原創|使用教程|編輯:郝浩|2015-07-29 14:19:02.000|閱讀 279 次
概述:本篇文章你將學習到如何編寫一個應用程序以及訪問Windows Phone中文本框的值。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
在這一部分里,我將講解如何編寫一個應用程序以及訪問Windows Phone中文本框的值。
首先從編寫應用程序說起。
從File菜單選擇New project,并選擇Windows Phone applicaton。將三個文本框添加到網格面板,前兩個文本框用于輸入數值,第三個文本框顯示結果。
<!--LayoutRoot is the root grid where all page content is placed--> <Grid x:Name="LayoutRoot" Background="Transparent"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <!--TitlePanel contains the name of the application and page title--> <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/> <TextBlock x:Name="PageTitle" Text="1st Application" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/> </StackPanel> <!--ContentPanel - place additional content here--> <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <TextBlock x:Name="lblfirst" Text="Enter 1st Number" Margin="25,38,241,527"></TextBlock> <TextBlock x:Name="lblsecond" Text="Enter 2nd Number" Margin="25,98,241,467"></TextBlock> <TextBlock x:Name="lblresult" Text="Result" Margin="25,161,241,404"></TextBlock> <TextBox x:Name="txtfirst" Margin="225,24,6,508"></TextBox> <TextBox x:Name="txtsecond" Margin="225,84,6,450"></TextBox> <TextBox x:Name="txtresult" Margin="225,147,6,381"></TextBox> <Button x:Name="btnadd" Height="95" Content="Addition" Margin="0,232,0,280" Click="btnadd_Click"></Button> </Grid> </Grid>
現在為按鈕的點擊事件編寫代碼,第一個和第二個文本框接收用戶輸入的數據,第三個文本框顯示兩個數字相加的結果。
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.Shapes; using Microsoft.Phone.Controls; namespace WriteFirstApplication { public partial class MainPage : PhoneApplicationPage { // Constructor public MainPage() { InitializeComponent(); } private void btnadd_Click(object sender, RoutedEventArgs e) { int result = Convert.ToInt32(txtfirst.Text)+Convert.ToInt32(txtsecond.Text); txtresult.Text = result.ToString(); } } }
所有完成之后運行應用程序。
現在編寫顯示運行消息的信息提示框。你只需要添加一行代碼就可以完成信息提示框的設計。
MessageBox.Show(“YourContent”)
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.Shapes; using Microsoft.Phone.Controls; namespace WriteFirstApplication { public partial class MainPage : PhoneApplicationPage { // Constructor public MainPage() { InitializeComponent(); } private void btnadd_Click(object sender, RoutedEventArgs e) { int result = Convert.ToInt32(txtfirst.Text)+Convert.ToInt32(txtsecond.Text); MessageBox.Show("Addition of "+ txtfirst.Text +"&"+ txtsecond.Text +"=" +result.ToString()); } } }
本文翻譯自
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn