资源描述
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
展开阅读全文