收藏 分销(赏)

C#第七章实验打印.docx

上传人:xrp****65 文档编号:7983053 上传时间:2025-01-29 格式:DOCX 页数:8 大小:866.50KB 下载积分:10 金币
下载 相关 举报
C#第七章实验打印.docx_第1页
第1页 / 共8页
C#第七章实验打印.docx_第2页
第2页 / 共8页


点击查看更多>>
资源描述
MainForm代码: using 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; using ch070.Examples; using ch070.PageExample; namespace ch070 { public partial class MainWindow : Window { public MainWindow() {InitializeComponent(); this.WindowStartupLocation =System.Windows.WindowStartupLocation.CenterScreen; this.SourceInitialized += MainWindow_SourceInitialized;} void MainWindow_SourceInitialized(object sender, EventArgs e) { LoginWindow login = new LoginWindow(); login.ShowDialog(); this.Title = "欢迎您," + login.UserName; } RadioButton rb = null; private void RadioButton_Checked(object sender, RoutedEventArgs e) { rb = e.Source as RadioButton; } private void Button_Click(object sender, RoutedEventArgs e) { if (rb == null) { MessageBox.Show("请选择一个例子", "提示",MessageBoxButton.OK, MessageBoxImage.Information); return; } string content = rb.Content.ToString(); Window w = null; switch (content) { case "HelloWorld": w = new HelloWorldWindow(); break; case "MessageBox": w = new MessageBoxWindow(); break; case"DialogBox": DialogBoxWindow dw = new DialogBoxWindow(); dw.Owner = this; bool? result = dw.ShowDialog(); if (result == true) { MessageBox.Show("来自自定义对话框:"+dw.TextString); } break; case"PageExample1": w = new Window(); w.Content = new PageExample.Page1();break; case "PageExample2": w = new System.Windows.Navigation.NavigationWindow(); w.Content = new PageExample.Page2(); break; case "PageExample3": w = new PageExample.FrameExample(); break; } if (w != null) { w.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner; w.Owner = this; w.ShowDialog(); } } } } 例子代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; 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.Shapes; namespace ch070.Examples { public partial class MessageBoxWindow : Window { public MessageBoxWindow() { nitializeComponent(); this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; } RadioButton rb1 = null; RadioButton rb2 = null; private void RadioButton1_Check(object sender, RoutedEventArgs e) { rb1 = e.Source as RadioButton; } private void RadioButton2_Check(object sender, RoutedEventArgs e) { rb2 = e.Source as RadioButton; } private void Button_Click(object sender, RoutedEventArgs e) { MessageBoxButton button = MessageBoxButton.YesNo; MessageBoxImage image = MessageBoxImage.Error; if(rb1!=null) switch (rb1.Content.ToString()) { case"OK": button = MessageBoxButton.OK; break; case"YesNo": button = MessageBoxButton.YesNo; break; case"YesNoCancel": button = MessageBoxButton.YesNoCancel; break; case"OKCancel": button = MessageBoxButton.OKCancel; break; } if(rb2!=null) switch (rb2.Content.ToString()) { case"Error": image=MessageBoxImage.Error; break; case "Information": image=MessageBoxImage.Information; break; case"Question": image = MessageBoxImage.Question; break; case"Warning": image = MessageBoxImage.Warning; break; } MessageBox.Show(ttBox1.Text, ttBox2.Text,button,image); } } } A.5.1代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; 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 UserLogin { public partial class MainForm : Window { public static string[] information = new string[3]; public MainForm() { InitializeComponent(); this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; this.SourceInitialized += MainWindow_SourceInitialized; } void MainWindow_SourceInitialized(object sender, EventArgs e) { LoginForm login = new LoginForm(); login.ShowDialog(); } private void autoFill_Click(object sender, RoutedEventArgs e) { studentName.Text = "ljh"; baseInformation.Text = "8932042"; otherInformation.Text = "8493204238"; } private void popToMessageBox_Click(object sender, RoutedEventArgs e) { MessageBox.Show(studentName.Text + "\n" + baseInformation.Text + "\n" + otherInformation.Text); } private void popToWindow_Click(object sender, RoutedEventArgs e) { information[0] = studentName.Text; information[1] = baseInformation.Text; information[2] = otherInformation.Text; NewWindow w = new NewWindow(); w.ShowDialog(); } } } 8
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 百科休闲 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服