using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Threading; namespace SuperCalculate ... { /**//// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form ...{ private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.Button button1; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.TextBox textBox3; private System.Windows.Forms.Button button2; private System.Windows.Forms.Button button3; private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label3; private System.Windows.Forms.ImageList imageList1; private System.Windows.Forms.ProgressBar progressBar1; private System.Windows.Forms.ProgressBar progressBar2; private System.ComponentModel.IContainer components; public Form1() ...{ // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /**//// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) ...{ thread.Abort(); if( disposing ) ...{ if (components != null) ...{ components.Dispose(); } } base.Dispose( disposing ); } Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码 /**//// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() ...{ this.components = new System.ComponentModel.Container(); System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1)); this.textBox1 = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.textBox2 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.textBox3 = new System.Windows.Forms.TextBox(); this.button2 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.label4 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.imageList1 = new System.Windows.Forms.ImageList(this.components); this.progressBar1 = new System.Windows.Forms.ProgressBar(); this.progressBar2 = new System.Windows.Forms.ProgressBar(); this.groupBox1.SuspendLayout(); this.SuspendLayout(); // // textBox1 // this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.textBox1.Font = new System.Drawing.Font("宋体", 12F); this.textBox1.Location = new System.Drawing.Point(104, 4); this.textBox1.Name = "textBox1"; this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal; this.textBox1.Size = new System.Drawing.Size(320, 26); this.textBox1.TabIndex = 0; this.textBox1.Text = ""; // // label1 // this.label1.AutoSize = true; this.label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.label1.Font = new System.Drawing.Font("宋体", 9F); this.label1.Location = new System.Drawing.Point(8, 8); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(93, 20); this.label1.TabIndex = 1; this.label1.Text = "请输入被乘数:"; // // label2 // this.label2.AutoSize = true; this.label2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.label2.Font = new System.Drawing.Font("宋体", 9F); this.label2.Location = new System.Drawing.Point(8, 40); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(81, 20); this.label2.TabIndex = 3; this.label2.Text = "请输入乘数:"; // // textBox2 // this.textBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.textBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.textBox2.Font = new System.Drawing.Font("宋体", 12F); this.textBox2.Location = new System.Drawing.Point(104, 36); this.textBox2.Name = "textBox2"; this.textBox2.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal; this.textBox2.Size = new System.Drawing.Size(320, 26); this.textBox2.TabIndex = 2; this.textBox2.Text = ""; // // button1 // this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.button1.BackColor = System.Drawing.Color.Linen; this.button1.DialogResult = System.Windows.Forms.DialogResult.OK; this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup; this.button1.Font = new System.Drawing.Font("宋体", 15F); this.button1.ForeColor = System.Drawing.Color.Red; this.button1.Location = new System.Drawing.Point(8, 172); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(108, 52); this.button1.TabIndex = 5; this.button1.Text = "开始计算"; this.button1.Click += new System.EventHandler(this.button1_Click); this.button1.MouseEnter += new System.EventHandler(this.button1_MouseEnter); this.button1.MouseLeave += new System.EventHandler(this.button1_MouseLeave); // // groupBox1 // this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.groupBox1.Controls.Add(this.textBox3); this.groupBox1.Location = new System.Drawing.Point(4, 68); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(424, 100); this.groupBox1.TabIndex = 7; this.groupBox1.TabStop = false; this.groupBox1.Text = "计算结果:"; // // textBox3 // this.textBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.textBox3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.textBox3.Font = new System.Drawing.Font("宋体", 12F); this.textBox3.ForeColor = System.Drawing.Color.Magenta; this.textBox3.Location = new System.Drawing.Point(8, 20); this.textBox3.Multiline = true; this.textBox3.Name = "textBox3"; this.textBox3.ScrollBars = System.Windows.Forms.ScrollBars.Both; this.textBox3.Size = new System.Drawing.Size(408, 72); this.textBox3.TabIndex = 3; this.textBox3.Text = ""; // // button2 // this.button2.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.button2.BackColor = System.Drawing.Color.Linen; this.button2.DialogResult = System.Windows.Forms.DialogResult.OK; this.button2.Enabled = false; this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Popup; this.button2.Font = new System.Drawing.Font("宋体", 15F); this.button2.ForeColor = System.Drawing.Color.Red; this.button2.Location = new System.Drawing.Point(164, 172); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(108, 52); this.button2.TabIndex = 11; this.button2.Text = "暂停计算"; this.button2.Click += new System.EventHandler(this.button2_Click); this.button2.MouseEnter += new System.EventHandler(this.button2_MouseEnter); this.button2.MouseLeave += new System.EventHandler(this.button2_MouseLeave); // // button3 // this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.button3.BackColor = System.Drawing.Color.Linen; this.button3.DialogResult = System.Windows.Forms.DialogResult.OK; this.button3.Enabled = false; this.button3.FlatStyle = System.Windows.Forms.FlatStyle.Popup; this.button3.Font = new System.Drawing.Font("宋体", 15F); this.button3.ForeColor = System.Drawing.Color.Red; this.button3.Location = new System.Drawing.Point(316, 172); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(108, 52); this.button3.TabIndex = 12; this.button3.Text = "停止计算"; this.button3.Click += new System.EventHandler(this.button3_Click); this.button3.MouseEnter += new System.EventHandler(this.button3_MouseEnter); this.button3.MouseLeave += new System.EventHandler(this.button3_MouseLeave); // // label4 // this.label4.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.label4.AutoSize = true; this.label4.FlatStyle = System.Windows.Forms.FlatStyle.System; this.label4.ForeColor = System.Drawing.Color.Blue; this.label4.Location = new System.Drawing.Point(124, 292); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(196, 17); this.label4.TabIndex = 10; this.label4.Text = "正在装入数据...总进度已完成:0%"; // // label3 // this.label3.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.label3.AutoSize = true; this.label3.FlatStyle = System.Windows.Forms.FlatStyle.System; this.label3.ForeColor = System.Drawing.Color.Blue; this.label3.Location = new System.Drawing.Point(124, 232); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(196, 17); this.label3.TabIndex = 8; this.label3.Text = "正在装入数据...子进度已完成:0%"; // // imageList1 // this.imageList1.ImageSize = new System.Drawing.Size(21, 21); this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream"))); this.imageList1.TransparentColor = System.Drawing.Color.Transparent; // // progressBar1 // this.progressBar1.Dock = System.Windows.Forms.DockStyle.Bottom; this.progressBar1.Location = new System.Drawing.Point(0, 315); this.progressBar1.Name = "progressBar1"; this.progressBar1.Size = new System.Drawing.Size(432, 23); this.progressBar1.TabIndex = 16; // // progressBar2 // this.progressBar2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.progressBar2.Location = new System.Drawing.Point(0, 260); this.progressBar2.Name = "progressBar2"; this.progressBar2.Size = new System.Drawing.Size(430, 23); this.progressBar2.TabIndex = 17; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(432, 338); this.Controls.Add(this.progressBar2); this.Controls.Add(this.progressBar1); this.Controls.Add(this.label4); this.Controls.Add(this.label3); this.Controls.Add(this.button3); this.Controls.Add(this.button2); this.Controls.Add(this.groupBox1); this.Controls.Add(this.button1); this.Controls.Add(this.label2); this.Controls.Add(this.textBox2); this.Controls.Add(this.label1); this.Controls.Add(this.textBox1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "Form1"; this.Text = "超级乘法计算器-蓝天软件工作室 朱狄敏版权所有"; this.Load += new System.EventHandler(this.Form1_Load); this.groupBox1.ResumeLayout(false); this.ResumeLayout(false); } #endregion /**//// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() ...{ Application.Run(new Form1()); } Thread thread; private void button1_Click(object sender, System.EventArgs e) ...{ thread.Start(); button1.Enabled=false; button2.Enabled=true; button3.Enabled=true; } private void calc()//计算过程 ...{ Console.WriteLine(" 超大型乘法计算系统-蓝天^_^软件工作室"); if(textBox1.Text=="" || textBox2.Text=="") ...{ textBox3.Text="请先输入要计算的数字!"; button1.Enabled=true; button2.Enabled=false; button3.Enabled=false; thread=new Thread(new ThreadStart(calc)); return; } textBox3.Text=null; string n1=textBox1.Text;//被乘数 string n2=textBox2.Text;//乘数 string mulJieguo=null;//乘法结果 int[,] addNum=new int[n2.Length,n1.Length+1];//各位加数 int jinwei=0;//进位 //每一层的值相乘 for(int i=n2.Length-1;i>=0;i--) ...{ progressBar1.Value=(int)((n2.Length-double.Parse(i.ToString()))/(n2.Length)*100); label4.Text="正在装入数据...总进度已完成:"+(int)((n2.Length-double.Parse(i.ToString()))/(n2.Length)*100)+"%"; for(int j=n1.Length;j>0;j--) ...{ progressBar2.Value=(int)((n1.Length-double.Parse(j.ToString()))/(n1.Length)*100); label3.Text="正在装入数据...子进度已完成:"+(int)((n1.Length-double.Parse(j.ToString()))/(n1.Length)*100)+"%"; try ...{ addNum[i,j]=int.Parse(n2[i].ToString())*int.Parse(n1[j-1].ToString()); } catch ...{ textBox3.Text="您输入的不是有效的数字!"; button1.Enabled=true; button2.Enabled=false; button3.Enabled=false; thread=new Thread(new ThreadStart(calc)); return; } if(addNum[i,j].ToString().Length==1) ...{ addNum[i,j]=addNum[i,j]+jinwei; jinwei=0; } else ...{ addNum[i,j]=addNum[i,j]+jinwei; jinwei=int.Parse(addNum[i,j].ToString().Substring(0,1));//获取进位值; addNum[i,j]=int.Parse(addNum[i,j].ToString().Substring(1));//获取个位值 } } addNum[i,0]=int.Parse(jinwei.ToString()); jinwei=0;//进位清空 } Console.WriteLine (" ***************"); int[][] mulNum=new int[n2.Length][]; for(int i=0;i<mulNum.GetLength(0);i++) mulNum[mulNum.GetLength(0)-i-1]=new int[n1.Length+i+1]; for(int i=0;i<mulNum.GetLength(0);i++) for(int j=0;j<mulNum[i].Length;j++) if(j>=addNum.GetLength(1)) mulNum[i][j]=0; else mulNum[i][j]=addNum[i,j]; for(int i=0;i<mulNum.Length;i++) ...{ for(int j=0;j<mulNum[i].Length;j++) Console.Write(mulNum[i][j]); Console.WriteLine(); } Console.WriteLine("**************************"); Console.Write(n1+"乘以"+n2+"的计算结果是(请稍等...):"); //所有层的值相加 int[] jieguo=new int[mulNum[0].Length]; for(int i=0;i<jieguo.Length;i++) ...{ progressBar1.Value=(int)(double.Parse(i.ToString())/(jieguo.Length-1)*100); label4.Text="正在进行计算...总进度已完成:"+(int)(double.Parse(i.ToString())/(jieguo.Length-1)*100)+"%"; for(int k=0;k<mulNum.Length;k++) ...{ if(mulNum.Length>1) ...{ progressBar2.Value=(int)(double.Parse(k.ToString())/(mulNum.Length-1)*100); label3.Text="正在进行计算...子进度已完成:"+(int)(double.Parse(k.ToString())/(mulNum.Length-1)*100)+"%"; } else ...{ progressBar2.Value=100; label3.Text="正在进行计算...子进度已完成:100%"; } try ...{ jieguo[i]+=mulNum[k][mulNum[k].Length-(i+1)]; } catch...{} } if(jieguo[i].ToString().Length==1) ...{ jieguo[i]=jieguo[i]+jinwei; jinwei=0; } else ...{ jieguo[i]=jieguo[i]+jinwei; jinwei=int.Parse(jieguo[i].ToString().Substring(0,1));//获取进位值; jieguo[i]=int.Parse(jieguo[i].ToString().Substring(1));//获取个位值 } mulJieguo=jieguo[i]+mulJieguo; } textBox3.Text=checkData(jinwei.ToString()+mulJieguo);//打印计算结果 Console.Write(textBox3.Text); button1.Enabled=true; button2.Enabled=false; button3.Enabled=false; MessageBox.Show("任务执行完毕","蓝天^_^软件工作室",MessageBoxButtons.OK,MessageBoxIcon.Information); thread=new Thread(new ThreadStart(calc)); } static private string checkData(string s) ...{ try ...{ while(s.Substring(0,1)=="0") s=s.Substring(1); } catch...{s="0";} return s; } private void button1_MouseEnter(object sender, System.EventArgs e) ...{ button1.BackColor=Color.Yellow; } private void button1_MouseLeave(object sender, System.EventArgs e) ...{ button1.BackColor=Color.Linen; } private void button2_MouseEnter(object sender, System.EventArgs e) ...{ button2.BackColor=Color.Yellow; } private void button2_MouseLeave(object sender, System.EventArgs e) ...{ button2.BackColor=Color.Linen; } private void button3_MouseEnter(object sender, System.EventArgs e) ...{ button3.BackColor=Color.Yellow; } private void button3_MouseLeave(object sender, System.EventArgs e) ...{ button3.BackColor=Color.Linen; } private void Form1_Load(object sender, System.EventArgs e) ...{ thread=new Thread(new ThreadStart(calc)); } private void button2_Click(object sender, System.EventArgs e) ...{ if(button2.Text=="暂停计算") ...{ thread.Suspend(); button2.Text="恢复计算"; } else ...{ thread.Resume(); button2.Text="暂停计算"; } } private void button3_Click(object sender, System.EventArgs e) ...{ if(MessageBox.Show("您真的要停止正在执行的任务吗?","请选择",MessageBoxButtons.YesNo,MessageBoxIcon.Warning,MessageBoxDefaultButton.Button2)==DialogResult.Yes) try ...{ thread.Abort(); } catch...{} finally ...{ button1.Enabled=true; button2.Enabled=false; button3.Enabled=false; button2.Text="暂停计算"; thread=new Thread(new ThreadStart(calc)); } } }}