初识.net界面程序(13)--WPF综合练习(1)
来源:互联网 发布:linux压缩文件命令zip 编辑:程序博客网 时间:2024/05/16 07:00
界面分为左右两部分,根据单选情况点确定按钮后右侧显示不同页面。
注意:右侧部分都是根据不同功能加载的页面(Page),如果用Winform,可以使用弹出新窗口实现。
初始界面如图(相当于选择功能1:读写文件)
单击“写文件”,将文本框中的内容写入“TextFile1.txt”中。
单击“读文件”,将“TextFile1.txt”中的内容读入到文本框中显示出来。
几何图形:
选择“几何图形”并点击“确定”,右侧部分更新为几何图形页面,效果如下图:
其中图形的大小、颜色可自行确定,渐变效果也可自行设置。
需要完成的操作:当鼠标移动到矩形内部时,在下方的Label中显示鼠标相对于矩形的坐标。
查询:
选择“查询”并点击“确定”,右侧部分更新为查询页面,效果如下图:
项目中添加一个“Student”类,其中属性与“student.xml”文件中的学生属性对应,并提供下列方法:
A.默认及带参数的构造方法
B.静态方法 getAllStudent( )
该方法从文件“student.xml”读取全部学生信息,并将每一个学生实例化为“Student”类的对象,加入到泛型列表集合List 中,然后返回该 List。
C.其它你需要使用的方法。
界面中的下拉列表包含条目“查找年龄为20的学生”“按性别分组按学号排序”,选择其中一项并单击“查询”按钮,执行以下操作:
先调用getAllStudent( )方法获取全部学生信息列表List,然后根据选择进行查询,将查询结果显示到 TextBox 中。
选择为“查找年龄为20的学生”时,将符合条件的学生信息,按一个学生一行显示。
选择为“按性别分组按学号排序”时,将所有学生按性别分组,分别按学号排序(升序),并按一个学生一行显示。
//首页 读写文件 .xaml<Window x:Class="ww.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:ww" mc:Ignorable="d" Title="MainWindow" Height="350" Width="525"> <Grid> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="2*"/> </Grid.ColumnDefinitions> <Border Grid.Column="0" Grid.Row="0" Background="LightBlue" BorderBrush="White" BorderThickness="0" CornerRadius="2" Padding="10" Margin="10"> <!--背景颜色 边框颜色 边框宽度 角圆弧度 内容与边框的间隔--> <StackPanel > <RadioButton Name="file" Margin="20" FontSize="15" IsChecked="True">读写文件</RadioButton> <RadioButton Name="jihe" Margin="20" FontSize="15">几何图形</RadioButton> <RadioButton Name="chaxun" Margin="20" FontSize="15">查询</RadioButton> <Button Margin="10 0 " Height="41" FontSize="20" Click="Button_Click">确定</Button> </StackPanel> </Border > <Border Grid.Column="1" Grid.Row="0" Background="LightBlue" BorderBrush="White" BorderThickness="0" CornerRadius="2" Padding="10" Margin="10"> <Frame Name="framw1" NavigationUIVisibility="Hidden"/> </Border> </Grid> </Grid></Window>
//.xaml.csusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;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;namespace ww{ /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); framw1.Source = new Uri("Page1.xaml", UriKind.Relative); } private void Button_Click(object sender, RoutedEventArgs e) { if (file.IsChecked == true) framw1.Source = new Uri("Page1.xaml", UriKind.Relative); else if(jihe.IsChecked==true) framw1.Source = new Uri("Page2.xaml", UriKind.Relative); else if(chaxun.IsChecked == true) framw1.Source = new Uri("Page3.xaml", UriKind.Relative); } }}
//Page1.xaml.cs xaml代码在下面using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;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;namespace ww{ /// <summary> /// Page1.xaml 的交互逻辑 /// </summary> public partial class Page1 : Page { public Page1() { InitializeComponent(); textfile.Text = "你好,这里是Page1.xaml"; } private void Buttondu_Click(object sender, RoutedEventArgs e) { FileInfo myfile = new FileInfo("MyFile/TextFile1.txt"); StreamWriter FileWriter = myfile.CreateText(); StringBuilder FileText = new StringBuilder(textfile.Text.ToString()); FileWriter.Write(FileText);//将字符串写入 FileWriter.Close(); //关闭StreamWriter对象 textfile.Text = " ";//清空文本框 } private void Buttonxie_Click(object sender, RoutedEventArgs e) { StreamReader MyReader = new StreamReader("MyFile/TextFile1.txt", Encoding.UTF8); string nextline; StringBuilder textline = new StringBuilder(); while ((nextline = MyReader.ReadLine()) != null) { textline.AppendLine(nextline); } textfile.Text = textline.ToString(); MyReader.Close(); } }}
//Page1.xaml<Page x:Class="ww.Page1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:ww" mc:Ignorable="d" d:DesignWidth="300" Title="Page1" Height="256.772"> <StackPanel> <TextBox Name="textfile" Height="188" TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Visible"> </TextBox> <StackPanel Orientation="Horizontal"> <Button Padding="10" Margin="30 10 50 10" Click="Buttondu_Click">写文件</Button> <Button Padding="10" Margin="50 10 30 10" Click="Buttonxie_Click">读文件</Button> </StackPanel> </StackPanel></Page>
阅读全文
0 0
- 初识.net界面程序(13)--WPF综合练习(1)
- 初识.net界面程序(13)--WPF综合练习(2)几何图形
- 初识.net界面程序(14)--WPF综合练习(3)LINQ TO XML
- 初识.net界面程序(1)——密码输入和显示练习
- 初识.net界面程序(2)——简单计算器设计练习
- 初识.net界面程序(3)——字符提取和整数整除练习
- 初识.net界面程序(4)——数组排序和计算练习
- 初识.net界面程序(5)——定时器和随机数练习
- 初识.net界面程序(6)——类及其属性和方法的实现练习
- 初识.net界面程序(7)——泛型和LINQ练习
- 初识.net界面程序(8)——文本文件读写练习
- 初识.net界面程序(12)——按钮外观设计练习
- 初识.net界面程序(11)--实现界面登陆
- 初识.net界面程序(9)--LINQ To XML
- 初识.net界面程序(10)--连接MYSQL数据库
- 初识.net界面程序(15)--鼠标事件
- JQ综合练习(1)
- WPF学习笔记(1)——初识WPF
- lodash 之 Chain篇 显试调用与隐性调用
- TCP传输的三次握手四次挥手策略
- 使用scp在Linux主机之间进行定时备份
- Error : Incorrect datetime value: '0000-00-00 00:00:00'
- 代理服务器 和NAT技术
- 初识.net界面程序(13)--WPF综合练习(1)
- Qt使用connect函数时向slot传递参数:使用lambda表达式
- CAP理论十二年回顾:"规则"变了
- 微信小程序中设置全局变量
- vuejs过滤器
- 一个对象实例化的完整过程
- mysql删除重复记录语句的方法
- 数组去重2种最好的方法
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis+Maven)