一、WPF Application
WPF使用XAML(extensible application markup language)可擴展應用程序標記語言,來進行頁面的操縱,非常簡便易懂。
下面一段代碼,就是使用xaml語言對頁面進行布局
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid Width="300" Height="190">
<Grid.RowDefinitions>
<RowDefinition Height="70" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel >
<TextBlock Text="Top stack panel" VerticalAlignment="Center" />
</StackPanel>
<StackPanel >
<TextBlock Text="Bottom stack panel" VerticalAlignment="Center" />
</StackPanel>
</Grid>
</Window>
界面如下:
二、Windows Form Applications
其實,WPF和Windows Form Application 的開發和windows phone的開發大同小異,都是進行控件的拖拽,編輯以及對控件發生動作時的反應。
下面就舉出一個Windows Form Applications的例子
ui設計:
Form1里面的代碼如下:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string a = textBox1.Text; string b = textBox2.Text; if(a == "qwer" && b == "123456") { MessageBox.Show("登陸成功"); } else { MessageBox.Show("登陸失敗"); textBox2.Text = " "; } } private void button2_Click(object sender, EventArgs e) { textBox2.Text = " "; textBox1.Text = " "; } } }
結果如下:登陸失敗:
登陸成功:
個人認為,對於這種應用的開發,就是要從實例中去學習各種控件的使用,所以,我舉出了兩個例子,控件的使用大同小異,還有許多控件的使用都需要從實際中去學習。