亚洲成年网在线观看黄,日本免码va在线看免费,在线看黄aⅴ网站免费观看,三级在线观看视频a毛,超碰caoporen国产,午夜在线无码免费福利院,永久免费无码专区在线观看

C#WPF計算器!一個剛剛?cè)腴T一個星期Csharp的應(yīng)屆生!

先入正題吧!1:創(chuàng)建wpf應(yīng)用。我用的VS是2013!2:創(chuàng)建wpf文件并且起名字!3:起一條虛線3:打開我們電腦基本的計算器,然后我們模仿他來做計算器吧!4:在工具箱找到lable,把他拖進來。并且起一個名字!設(shè)置他的屬性。4:再

C#WPF計算器!一個剛剛?cè)腴T一個星期Csharp的應(yīng)屆生!

落戶上海咨詢二維碼  

  

先入正題吧!

  

1:創(chuàng)建wpf應(yīng)用。我用的VS是2013!

  

2:創(chuàng)建wpf文件并且起名字!

  

3:起一條虛線

  

3:打開我們電腦基本的計算器,然后我們模仿他來做計算器吧!

  

4:在工具箱找到lable,把他拖進來。并且起一個名字!設(shè)置他的屬性。

  

4:再然后在工具箱找到button按鈕把他拖進來。并且?guī)退鹈?,還有設(shè)置他的屬性!

  

5:寫完整的界面,按鈕直接復(fù)制粘貼就可以的!下一步進行后臺代碼!

  

6:定義三個變量存放數(shù)據(jù)!

  

7:設(shè)置按鈕0的點擊事件!然后數(shù)字鍵復(fù)制粘貼就可以了!

  

8:設(shè)置符號鍵,給他賦值!

  

9:設(shè)置C按鍵清除所有!這個問了很多人才找到的C按鍵清除lable!

  

10:設(shè)置等于號按鍵促發(fā)加減乘除!

  

11:然后一個計算器完成了!下面是全部代碼!

  

namespaceLVcalculation

  

{

  

??///

  

??///MainWindow.xaml的交互邏輯

  

??///

  

??publicpartialclassMainWindow:Window

  

??{

  

????stringnumber1=null,number2=null,flag=null;//第一個變量存放按下的第一個字符,第二個變量存放按下符號鍵的字符。第三個存放符號的字符!

  

????publicMainWindow左邊()右邊

  

????{

  

??????InitializeComponent左邊()右邊;

  

????}

  

????privatevoidbutton0_Click(objectsender,RoutedEventArgse)

  

????{

  

??????if(flag==null)

  

??????{

  

????????number1=number1+"0";

  

????????lable1.Content=number1;

  

??????}

  

??????else{

  

????????number2=number2+"0";

  

????????lable1.Content=number2;

  

???????

  

??????}

  

????}

  

????privatevoidbutton1_Click(objectsender,RoutedEventArgse)

  

????{

  

??????if(flag==null)

  

??????{

  

????????number1=number1+"1";

  

????????lable1.Content=number1;

  

??????}

  

??????else

  

??????{

  

????????number2=number2+"1";

  

????????lable1.Content=number2;

  

??????}

  

????}

  

????privatevoidbutton2_Click(objectsender,RoutedEventArgse)

  

????{

  

??????if(flag==null)

  

??????{

  

????????number1=number1+"2";

  

????????lable1.Content=number1;

  

??????}

  

??????else

  

??????{

  

????????number2=number2+"2";

  

????????lable1.Content=number2;

  

??????}

  

????}

  

????privatevoidbutton3_Click(objectsender,RoutedEventArgse)

  

????{

  

??????if(flag==null)

  

??????{

  

????????number1=number1+"3";

  

????????lable1.Content=number1;

  

??????}

  

??????else

  

??????{

  

????????number2=number2+"3";

  

????????lable1.Content=number2;

  

??????}

  

????}

  

????privatevoidbutton4_Click(objectsender,RoutedEventArgse)

  

????{

  

??????if(flag==null)

  

??????{

  

????????number1=number1+"4";

  

????????lable1.Content=number1;

  

??????}

  

??????else

  

??????{

  

????????number2=number2+"4";

  

????????lable1.Content=number2;

  

??????}

  

????}

  

????privatevoidbutton5_Click(objectsender,RoutedEventArgse)

  

????{

  

??????if(flag==null)

  

??????{

  

????????number1=number1+"5";

  

????????lable1.Content=number1;

  

??????}

  

??????else

  

??????{

  

????????number2=number2+"5";

  

????????lable1.Content=number2;

  

??????}

  

????}

  

????privatevoidbutton6_Click(objectsender,RoutedEventArgse)

  

????{

  

??????if(flag==null)

  

??????{

  

????????number1=number1+"6";

  

????????lable1.Content=number1;

  

??????}

  

??????else

  

??????{

  

????????number2=number2+"6";

  

????????lable1.Content=number2;

  

??????}

  

????}

  

????privatevoidbutton7_Click(objectsender,RoutedEventArgse)

  

????{

  

??????if(flag==null)

  

??????{

  

????????number1=number1+"7";

  

????????lable1.Content=number1;

  

??????}

  

??????else

  

??????{

  

????????number2=number2+"7";

  

????????lable1.Content=number2;

  

??????}

  

????}

  

????privatevoidbutton8_Click(objectsender,RoutedEventArgse)

  

????{

  

??????if(flag==null)

  

??????{

  

????????number1=number1+"8";

  

????????lable1.Content=number1;

  

??????}

  

??????else

  

??????{

  

????????number2=number2+"8";

  

????????lable1.Content=number2;

  

??????}

  

????}

  

????privatevoidbutton9_Click(objectsender,RoutedEventArgse)

  

????{

  

??????if(flag==null)

  

??????{

  

????????number1=number1+"9";

  

????????lable1.Content=number1;

  

??????}

  

??????else

  

??????{

  

????????number2=number2+"9";

  

????????lable1.Content=number2;

  

??????}

  

????}

  

????privatevoidbuttonb_Click(objectsender,RoutedEventArgse)

  

????{

  

??????flag="-";

  

????}

  

????privatevoidbuttona_Click(objectsender,RoutedEventArgse)

  

????{

  

??????flag="+";

  

????}

  

????privatevoidbuttone_Click(objectsender,RoutedEventArgse)

  

????{

  

??????flag="%";

  

????}

  

????privatevoidbuttond_Click(objectsender,RoutedEventArgse)

  

????{

  

??????flag="/";

  

????}

  

????privatevoidbuttonc_Click(objectsender,RoutedEventArgse)

  

????{

  

??????flag="*";

  

????}

  

????privatevoidbuttoncc_Click(objectsender,RoutedEventArgse)

  

????{

  

??????this.lable1.Content="";

  

????}

  

????privatevoidbuttongg_Click(objectsender,RoutedEventArgse)

  

????{

  

??????if(flag==null)

  

??????{

  

????????number1=number1+".";

  

????????lable1.Content=number1;

  

??????}

  

??????else{

  

????????number2=number2+".";

  

????????lable1.Content=number2;

  

???????

  

??????}

  

????}

  

????privatevoidbuttonf_Click(objectsender,RoutedEventArgse)

  

????{

  

??????switch(flag){

  

????????case"+":lable1.Content=Convert.ToString(Convert.ToDouble(number1)+Convert.ToDouble(number2));

  

??????????break;

  

????????case"-":lable1.Content=Convert.ToString(Convert.ToDouble(number1)-Convert.ToDouble(number2));

  

??????????break;

  

????????case"*":lable1.Content=Convert.ToString(Convert.ToDouble(number1)*Convert.ToDouble(number2));

  

??????????break;

  

????????case"/":lable1.Content=Convert.ToString(Convert.ToDouble(number1)/Convert.ToDouble(number2));

  

??????????break;

  

????????case"%":lable1.Content=Convert.ToString(Convert.ToDouble(number1)%Convert.ToDouble(number2));

  

??????????break;

  

??????}

  

??????number1=null;

  

??????number2=null;

  

??????flag=null;

  

????}

  

??}

  

}

  

12:還有一種方法寫!注意這個方法的是用textbox,不是用lable。

  

13:下面是這個的全部代碼!

  

  

????xmlns=""

  

????xmlns:x=""

  

????Title="為什么我寫的計算器這么多bug"Height="350"MaxHeight="350"MinHeight="350"Width="525"MaxWidth="525"MinWidth="525"

  

????>

  

??

  

?????

  

????

  

??????

  

??????

  

??????

  

??????

  

??????

  

??????

  

????

  

????

  

??????

  

??????

  

??????

  

??????

  

????

  

????

  

????

免責(zé)聲明:本站部分內(nèi)容和圖片來源于互聯(lián)網(wǎng),經(jīng)本站整理和編輯,版權(quán)歸原作者所有,本站轉(zhuǎn)載出于傳遞更多信息、交流和學(xué)習(xí)之目的,不做商用不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。若有來源標(biāo)注存在錯誤或侵犯到您的權(quán)益,煩請告知網(wǎng)站管理員,將于第一時間整改處理。管理員郵箱:y569#qq.com(#轉(zhuǎn)@)

相關(guān)推薦

推薦內(nèi)容

落戶咨詢2
最新資訊
落戶咨詢3