📄 mainform.cs
字号:
using System;using System.Collections;using System.ComponentModel;using System.Drawing;using System.Windows.Forms;namespace BookMulti{ public class MainForm : BookMulti.BaseForm {
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.MainMenu mainMenu2;
private System.Windows.Forms.MenuItem fileMenu;
private System.Windows.Forms.MenuItem fileCaculateMenuItem;
private System.Windows.Forms.MenuItem fileSummaryMenuItem;
private System.Windows.Forms.MenuItem fileClearMenuItem;
private System.Windows.Forms.MenuItem fileExitMenuItem;
private System.Windows.Forms.MenuItem helpMenu;
private System.Windows.Forms.MenuItem helpAboutMenuItem;
private System.Windows.Forms.MenuItem menuItem9;
private System.Windows.Forms.TextBox titleTextBox;
private System.Windows.Forms.TextBox quantityTextBox;
private System.Windows.Forms.TextBox priceTextBox;
private System.Windows.Forms.TextBox extendedpriceTextBox;
private System.Windows.Forms.Label titleLabel;
private System.Windows.Forms.Label quantityLabel;
private System.Windows.Forms.Label priceLabel;
private System.Windows.Forms.Label extendedpriceLabel;
private System.ComponentModel.IContainer components = null; private BookSale bookSalesObject;
private System.Windows.Forms.CheckBox studentCheckBox;
private System.Windows.Forms.TextBox tiltelTextBox; private StudentBookSale studentBookSalesObject; public MainForm() { // 该调用是 Windows 窗体设计器所必需的。 InitializeComponent(); // TODO: 在 InitializeComponent 调用后添加任何初始化 } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } static void Main()
{
Application.Run(new MainForm());
}
private void MainForm_Load(object sender, System.EventArgs e)
{
}
private void menuItem5_Click(object sender, System.EventArgs e)
{
}
protected override void okButton_Click(object sender, System.EventArgs e)
{
//this.Close();
}
private void InitializeComponent()
{
this.mainMenu2 = new System.Windows.Forms.MainMenu();
this.fileMenu = new System.Windows.Forms.MenuItem();
this.fileCaculateMenuItem = new System.Windows.Forms.MenuItem();
this.fileSummaryMenuItem = new System.Windows.Forms.MenuItem();
this.fileClearMenuItem = new System.Windows.Forms.MenuItem();
this.fileExitMenuItem = new System.Windows.Forms.MenuItem();
this.helpMenu = new System.Windows.Forms.MenuItem();
this.helpAboutMenuItem = new System.Windows.Forms.MenuItem();
this.menuItem9 = new System.Windows.Forms.MenuItem();
this.titleLabel = new System.Windows.Forms.Label();
this.quantityLabel = new System.Windows.Forms.Label();
this.priceLabel = new System.Windows.Forms.Label();
this.extendedpriceLabel = new System.Windows.Forms.Label();
this.studentCheckBox = new System.Windows.Forms.CheckBox();
this.tiltelTextBox = new System.Windows.Forms.TextBox();
this.quantityTextBox = new System.Windows.Forms.TextBox();
this.priceTextBox = new System.Windows.Forms.TextBox();
this.extendedpriceTextBox = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// okButton
//
this.okButton.Location = new System.Drawing.Point(354, 230);
this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(108, 38);
this.okButton.Click += new System.EventHandler(this.okButton_Click_1);
//
// label1
//
this.label1.Location = new System.Drawing.Point(54, 50);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(270, 18);
//
// mainMenu2
//
this.mainMenu2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.fileMenu,
this.helpMenu});
//
// fileMenu
//
this.fileMenu.Index = 0;
this.fileMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.fileCaculateMenuItem,
this.fileSummaryMenuItem,
this.fileClearMenuItem,
this.fileExitMenuItem});
this.fileMenu.Text = "&File";
//
// fileCaculateMenuItem
//
this.fileCaculateMenuItem.Index = 0;
this.fileCaculateMenuItem.Text = "&Caculate";
this.fileCaculateMenuItem.Click += new System.EventHandler(this.fileCaculateMenuItem_Click);
//
// fileSummaryMenuItem
//
this.fileSummaryMenuItem.Index = 1;
this.fileSummaryMenuItem.Text = "&Summary";
this.fileSummaryMenuItem.Click += new System.EventHandler(this.fileSummaryMenuItem_Click);
//
// fileClearMenuItem
//
this.fileClearMenuItem.Index = 2;
this.fileClearMenuItem.Text = "C&lear";
this.fileClearMenuItem.Click += new System.EventHandler(this.fileClearMenuItem_Click);
//
// fileExitMenuItem
//
this.fileExitMenuItem.Checked = true;
this.fileExitMenuItem.Index = 3;
this.fileExitMenuItem.Text = "&Exit";
this.fileExitMenuItem.Click += new System.EventHandler(this.fileExitMenuItem_Click);
//
// helpMenu
//
this.helpMenu.Index = 1;
this.helpMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.helpAboutMenuItem,
this.menuItem9});
this.helpMenu.Text = "&Help";
//
// helpAboutMenuItem
//
this.helpAboutMenuItem.Index = 0;
this.helpAboutMenuItem.Text = "&About";
this.helpAboutMenuItem.Click += new System.EventHandler(this.helpAboutMenuItem_Click);
//
// menuItem9
//
this.menuItem9.Index = 1;
this.menuItem9.Text = "";
this.menuItem9.Click += new System.EventHandler(this.menuItem9_Click);
//
// titleLabel
//
this.titleLabel.Location = new System.Drawing.Point(18, 81);
this.titleLabel.Name = "titleLabel";
this.titleLabel.Size = new System.Drawing.Size(75, 18);
this.titleLabel.TabIndex = 2;
this.titleLabel.Text = "&Title";
//
// quantityLabel
//
this.quantityLabel.Location = new System.Drawing.Point(18, 131);
this.quantityLabel.Name = "quantityLabel";
this.quantityLabel.Size = new System.Drawing.Size(75, 18);
this.quantityLabel.TabIndex = 2;
this.quantityLabel.Text = "&Quantity";
//
// priceLabel
//
this.priceLabel.Location = new System.Drawing.Point(18, 187);
this.priceLabel.Name = "priceLabel";
this.priceLabel.Size = new System.Drawing.Size(75, 18);
this.priceLabel.TabIndex = 2;
this.priceLabel.Text = "&Price";
//
// extendedpriceLabel
//
this.extendedpriceLabel.Location = new System.Drawing.Point(18, 286);
this.extendedpriceLabel.Name = "extendedpriceLabel";
this.extendedpriceLabel.Size = new System.Drawing.Size(126, 18);
this.extendedpriceLabel.TabIndex = 2;
this.extendedpriceLabel.Text = "&Extended price";
//
// studentCheckBox
//
this.studentCheckBox.Checked = true;
this.studentCheckBox.CheckState = System.Windows.Forms.CheckState.Checked;
this.studentCheckBox.Location = new System.Drawing.Point(24, 230);
this.studentCheckBox.Name = "studentCheckBox";
this.studentCheckBox.Size = new System.Drawing.Size(78, 19);
this.studentCheckBox.TabIndex = 3;
this.studentCheckBox.Text = "student";
//
// tiltelTextBox
//
this.tiltelTextBox.Location = new System.Drawing.Point(156, 81);
this.tiltelTextBox.Name = "tiltelTextBox";
this.tiltelTextBox.Size = new System.Drawing.Size(75, 21);
this.tiltelTextBox.TabIndex = 2;
this.tiltelTextBox.Text = "";
//
// quantityTextBox
//
this.quantityTextBox.Location = new System.Drawing.Point(156, 131);
this.quantityTextBox.Name = "quantityTextBox";
this.quantityTextBox.Size = new System.Drawing.Size(108, 21);
this.quantityTextBox.TabIndex = 4;
this.quantityTextBox.Text = "";
//
// priceTextBox
//
this.priceTextBox.Location = new System.Drawing.Point(156, 187);
this.priceTextBox.Name = "priceTextBox";
this.priceTextBox.Size = new System.Drawing.Size(108, 21);
this.priceTextBox.TabIndex = 4;
this.priceTextBox.Text = "";
//
// extendedpriceTextBox
//
this.extendedpriceTextBox.Location = new System.Drawing.Point(156, 286);
this.extendedpriceTextBox.Name = "extendedpriceTextBox";
this.extendedpriceTextBox.Size = new System.Drawing.Size(108, 21);
this.extendedpriceTextBox.TabIndex = 4;
this.extendedpriceTextBox.Text = "";
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
this.ClientSize = new System.Drawing.Size(486, 455);
this.Controls.Add(this.tiltelTextBox);
this.Controls.Add(this.studentCheckBox);
this.Controls.Add(this.titleLabel);
this.Controls.Add(this.quantityLabel);
this.Controls.Add(this.priceLabel);
this.Controls.Add(this.extendedpriceLabel);
this.Controls.Add(this.quantityTextBox);
this.Controls.Add(this.priceTextBox);
this.Controls.Add(this.extendedpriceTextBox);
this.Menu = this.mainMenu2;
this.Name = "MainForm";
this.Text = "MainForm";
this.Load += new System.EventHandler(this.MainForm_Load_2);
this.Controls.SetChildIndex(this.extendedpriceTextBox, 0);
this.Controls.SetChildIndex(this.priceTextBox, 0);
this.Controls.SetChildIndex(this.quantityTextBox, 0);
this.Controls.SetChildIndex(this.extendedpriceLabel, 0);
this.Controls.SetChildIndex(this.priceLabel, 0);
this.Controls.SetChildIndex(this.quantityLabel, 0);
this.Controls.SetChildIndex(this.titleLabel, 0);
this.Controls.SetChildIndex(this.studentCheckBox, 0);
this.Controls.SetChildIndex(this.tiltelTextBox, 0);
this.Controls.SetChildIndex(this.okButton, 0);
this.Controls.SetChildIndex(this.label1, 0);
this.ResumeLayout(false);
}
private void MainForm_Load_1(object sender, System.EventArgs e)
{
}
private void menuItem5_Click_1(object sender, System.EventArgs e)
{
}
private void MainForm_Load_2(object sender, System.EventArgs e)
{
okButton.Visible=false;
}
private void okButton_Click_1(object sender, System.EventArgs e)
{
}
private void fileCaculateMenuItem_Click(object sender, System.EventArgs e)
{
try
{
if(studentCheckBox.Checked)
{
studentBookSalesObject=new StudentBookSale(titleTextBox.Text,int.Parse(quantityTextBox.Text ),decimal.Parse(priceTextBox.Text));
extendedpriceTextBox.Text=studentBookSalesObject.ExtendedPrice.ToString();
}
else
{
bookSalesObject=new BookSale(titleTextBox.Text,int.Parse(quantityTextBox.Text),decimal.Parse(priceTextBox.Text));
extendedpriceTextBox.Text=bookSalesObject.ExtendedPrice.ToString("n");
}
}
catch
{
MessageBox.Show("invalid data:error","the tip of error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
private void fileClearMenuItem_Click(object sender, System.EventArgs e)
{
titleTextBox.Clear();
quantityTextBox.Clear();
priceTextBox.Clear();
extendedpriceTextBox.Clear();
titleTextBox.Focus();
}
private void fileExitMenuItem_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void helpAboutMenuItem_Click(object sender, System.EventArgs e)
{
AboutForm aboutFormObject=new AboutForm ();
aboutFormObject.Show();
}
private void menuItem9_Click(object sender, System.EventArgs e)
{
}
private void fileSummaryMenuItem_Click(object sender, System.EventArgs e)
{
SummaryForm summaryFormObject=new SummaryForm ();
summaryFormObject.salesCountTextBox.Text=BookSale.SalesCount.ToString();
summaryFormObject.salesTotalTextBox.Text=BookSale.SalesTotal.ToString("c");
summaryFormObject.totalStudentDiscountTextBox.Text=StudentBookSale.DiscountTotal.ToString("c");
summaryFormObject.Show();
} }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -