Liam的C# 学习历程(七):WPF(Windows Presentation Foundation)、Windows Form Applications

  在今天的课堂中,老师向我们讲述了关于一些WPF(Windows Presentation Foundation)和Windows Form Applications的内容,接下来就让我们一起来复习一下:

(一)、WPF(Windows Presentation Foundation):

  WPF是一个重要运用于desktop手机开发方面。它使用到了一种XML的变形语言——XAML的语言(eXtensible Application Markup Language)。

  使用XAML开发人员可以对WPF程序的 所有用户界面元素(例如文本、按钮、图像和列表框等)进行详细的定置,同时还可以对整个界面进行合理化的布局,这与使用HTML非常相似。但是由于 XAML是基于XML的,所以它本身就是一个组织良好的XML文档,而且相对于HTML,它的语法更严谨、更明确。预计以后大部分的XAML都可由相应的软件自动生成,就如同我们现在制作一个静态页面时,几乎不用编写任何HTML代码就可以直接通过Dreamweaver软件生成一个美观的页面。

  在课外,我又通过Bob Tabor的C#教学视频,更深入的学习了一些关于XAML的程序,通过这些视频的讲解,我们可以更加深刻的体会理解,下面就是一个简单的实例以及其输出结果:

 1  x:Class="GridsRowsAndColumns.MainPage"
 2     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4     xmlns:local="using:GridsRowsAndColumns"
 5     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 6     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 7     mc:Ignorable="d"
 8     Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
 9 
10     <Page.Resources>
11         <Style TargetType="TextBlock">
12             <Setter Property="FontSize" Value="42" />
13         </Style>
14     </Page.Resources>
15 
16     <Grid>
17         <Grid.RowDefinitions>
18             <RowDefinition Height="*" />
19             <RowDefinition Height="*" />
20             <RowDefinition Height="*" />
21         </Grid.RowDefinitions>
22         <Grid.ColumnDefinitions>
23             <ColumnDefinition Width="*" />
24             <ColumnDefinition Width="*" />
25             <ColumnDefinition Width="*" />
26         </Grid.ColumnDefinitions>
27 
28         <TextBlock>1</TextBlock>
29         <TextBlock Grid.Column="1">2</TextBlock>
30         <TextBlock Grid.Column="2">3</TextBlock>
31 
32         <TextBlock Grid.Row="1">4</TextBlock>
33         <TextBlock Grid.Row="1" Grid.Column="1">5</TextBlock>
34         <TextBlock Grid.Row="1" Grid.Column="2">6</TextBlock>
35 
36         <TextBlock Grid.Row="2">7</TextBlock>
37         <TextBlock Grid.Row="2" Grid.Column="1">8</TextBlock>
38         <TextBlock Grid.Row="2" Grid.Column="2">9</TextBlock>
39 
40     </Grid>
41 </Page>

输出结果:

  

 

(二)、Windows Form Applications:

  其实在老师进行这一章的讲解之前,我们就在编写CRC_Generation时使用到了这一方面的内容,下面让我通过这个程序来回顾一下相关内容:

  我编写的代码如下:

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 CRC_Generation_Form
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            RegisterBox.ReadOnly = true;
        }

        private void OKButton_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            string debugAddress = Environment.CurrentDirectory;
            p.StartInfo.FileName = debugAddress + "\\CRC_Generation.exe";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.Arguments = PathBox.Text;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.RedirectStandardInput = true;
            p.Start();
            OutputBox.Items.Add(p.StandardOutput.ReadToEnd());
            //PathBox.value = "";
         }
    }
}

  这其中主要是对OK_Button的Click事件进行了内容的编写,通过process语句与外部提前编写好的控制台程序相连接,并将输出重定向到Form中的OutputBox中,其输出结果如下:

(错误输入)

(正确输入)

posted @ 2015-05-04 00:14  Liam_LC  阅读(364)  评论(0编辑  收藏  举报