原創(chuàng)|使用教程|編輯:郝浩|2015-07-29 14:19:02.000|閱讀 279 次
概述:本篇文章你將學(xué)習(xí)到如何編寫一個(gè)應(yīng)用程序以及訪問Windows Phone中文本框的值。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
在這一部分里,我將講解如何編寫一個(gè)應(yīng)用程序以及訪問Windows Phone中文本框的值。
首先從編寫應(yīng)用程序說起。
從File菜單選擇New project,并選擇Windows Phone applicaton。將三個(gè)文本框添加到網(wǎng)格面板,前兩個(gè)文本框用于輸入數(shù)值,第三個(gè)文本框顯示結(jié)果。
<!--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>
現(xiàn)在為按鈕的點(diǎn)擊事件編寫代碼,第一個(gè)和第二個(gè)文本框接收用戶輸入的數(shù)據(jù),第三個(gè)文本框顯示兩個(gè)數(shù)字相加的結(jié)果。
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(); } } }
所有完成之后運(yùn)行應(yīng)用程序。
現(xiàn)在編寫顯示運(yùn)行消息的信息提示框。你只需要添加一行代碼就可以完成信息提示框的設(shè)計(jì)。
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()); } } }
本文翻譯自
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn