ユーザ用ツール

サイト用ツール

サイドバー

About

Contents

Materials Link

その他

PR


wiki:windowsphone:7.1:tips:013

013 テキストボックスの利用

概要

テキストボックスに入力した二つの文字列を合体させ、ダイアログに出力します。

MainPage.xaml

<phone:PhoneApplicationPage 
	x:Class="BaseApp.MainPage"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
	xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
	FontFamily="{StaticResource PhoneFontFamilyNormal}"
	FontSize="{StaticResource PhoneFontSizeNormal}"
	Foreground="{StaticResource PhoneForegroundBrush}"
	SupportedOrientations="Portrait" Orientation="Portrait"
	shell:SystemTray.IsVisible="True">
 
	<Canvas x:Name="LayoutRoot" Background="Black"></Canvas>
</phone:PhoneApplicationPage>

MainPage.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Diagnostics;
namespace BaseApp
{
	// エントリーポイント
	public partial class MainPage : PhoneApplicationPage
	{
		private TextBox textbox0 = null;
		private TextBox textbox1 = null;
 
		// コンストラクタ
		public MainPage()
		{
			// コンポーネントの初期化。
			InitializeComponent();
 
			// 初期化完了後に呼ばれるメソッドの登録。
			Loaded += OnLoaded;
		}
 
		// 初期化完了後に呼ばれるメソッド。
		void OnLoaded(object sender, RoutedEventArgs args)
		{
			// テキストボックスを表示する。
			{
				textbox0 = new TextBox();
				textbox0.Name = "textbox0";
				textbox0.Width = 250;
				textbox0.Height = 80;
				Canvas.SetLeft(textbox0, 20);
				Canvas.SetTop(textbox0, 40);
				LayoutRoot.Children.Add(textbox0);
 
				textbox1 = new TextBox();
				textbox1.Name = "textbox1";
				textbox1.Width = 250;
				textbox1.Height = 80;
				Canvas.SetLeft(textbox1, 20);
				Canvas.SetTop(textbox1, 120);
				LayoutRoot.Children.Add(textbox1);
			}
 
			// ボタンを表示する。
			{
				Button button0 = new Button();
				button0.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
				button0.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
				button0.Background = new SolidColorBrush(Color.FromArgb(255, 200, 200, 200));
				button0.Content = "合体!";
				button0.Tag = "ok";
				button0.Click += new RoutedEventHandler(OnButtonClick);
 
				Rect rect = new Rect(20, 250, 400, 80);
				Canvas.SetLeft(button0, rect.X);
				Canvas.SetTop(button0, rect.Y);
				button0.Width = rect.Width;
				button0.Height = rect.Height;
 
				LayoutRoot.Children.Add(button0);
			}
		}
 
		// ボタンクリック時に呼ばれるメソッド。
		private void OnButtonClick(object sender, RoutedEventArgs e)
		{
			String msg = "textbox0 + textbox1 =" + textbox0.Text + textbox1.Text;
			MessageBox.Show(msg, "caption", MessageBoxButton.OK);
		}
	}
}
Permalink wiki/windowsphone/7.1/tips/013.txt · 最終更新: 2014/11/09 11:02 (外部編集)

oeffentlich