8基于WinForm的界面设计全解PPT课件

相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
2)滑块(TrackBar)的Scroll事件代码如下:
private void numberTrackBar_Scroll(object sender, EventArgs e) { numberTextBox1.Text = numberTextBox2.Text = numberTextBox3.Text = numberTextBox4.Text = numberTrackBar.Value.ToString(); }
<Window x:Class="WpfApplication3.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentati
on"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6
WinForm和WPF开发UI对比
(2)WPF数据驱动UI 1)在WPF项目中创建一个Student类,作为UI的数据源:
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace WpfApplication3
int value = 0;
int.TryParse(t.Text,out value);
if (value < 0)
{
value = 0;
}
if (value > 100)
{
value = 100;
}
numberTrackBar.Value = value;
}
5
WinForm和WPF开发UI对比
2、常见属性:Text、FlatStyle 3、常见事件:Click
12
练习1:加法计算器
练习1:加法计算器。
int.TryPase(string,out int)
//“求和”命令按钮的单击事件处理函数 private void btnAdd_Click(object sender, EventArgs e) {
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<!--定义了三行-->
<Grid.RowDefinitions>
8
WinForm和WPF开发UI对比
3)WPF项目的后台代码文件:
4
WinForm和WPF开发UI对比
(1)WinForm事件驱动UI 1)四个文本框(TextBox)的TextChanged事件代码如下:
private void numberTextBox_TextChanged(object sender,
EventArgs e)
{
TextBox t = (TextBox)sender;
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data;
WFP开发UI
✓ 专门的UI设计语言: XMAL
✓ 数据驱动UI:数据是 核心,主动;UI从属于 数据,并表达数据,是 被动的。
3
WinForm和WPF开发UI对比
【例1】实现如图所示的四个文本框和滑块之间的同 步。当用户往文本框中输入数字后,滑块将显示到 相应的位置;当滑块的位置被移动后,文本框中将 显示相应的数字。
10
文本框
1、文本框TextBox的作用:接收用户输入的 文本
2、常见属性:MultiLine、ReadOnly、 UseSystemPasswordChar
3、常见方法:SetFocus 4、常见事件:TextChanged、Leave
11
命令按钮
1、命令按钮Button的作用:响应用户的 click事件
Title="滑块与文本框的同步" Height="200" Width="300"
Loaded="Window_Loaded">
<Grid>
<!--定义了一个网格-->
<Grid Width="200" Height="100" >
<!--定义了三列-->
<Grid.ColumnDefinitions>
第八讲 基于WinForm的界面设计
▪ 主要内容
WinForm和WPF开发UI对比 标签
命令按钮 复选框
图形框
1
第八讲 基于WinForm的界面设计
▪ 主要内容
列表框 组合框 树视图 对话框 菜单与工具栏 其他控件 布局
2
WinForm和WPF开发UI对比
WinForm开发UI ✓ 消息被封装成事件 ✓ 事件驱动UI
int intAdd1 = 0; int intAdd2 = 0; string strAdd1 = txtAdd1.Text; string strAdd2 = txtAdd2.Text; if (int.TryParse(strAdd1, out intAdd1) == false) {
namespace WpfApplication3
{
/// <summary>
/// Window1.xaml 的交互逻辑
9
标签
1、标签Label的作用:显示文本信息 2、常见属性:
1)Text:标签显示的文本信息 2)Font:设置标签的文本字体 3)TextAlign:设置标签文本与控件的对齐 方式
using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes;
{
/// <summary>
/// 学生类
/// </summary>
class Student
{
/// <summary>
ຫໍສະໝຸດ Baidu
/// 获取或设置学生的年龄
/// </summary>
public int Age { get;set;}
7
WinForm和WPF开发UI对比
2)WPF项目的界面代码XAML如下:
相关文档
最新文档