{"id":8360,"date":"2006-07-13T18:20:00","date_gmt":"2006-07-13T10:20:00","guid":{"rendered":"http:\/\/enet.yo2.cn\/articles\/8360,%e7%ae%80%e5%8d%95%e7%9a%84%e5%8a%a0%e5%87%8f%e4%b9%98%e9%99%a4%e5%ae%9e%e4%be%8b-2.html"},"modified":"2006-07-13T18:20:00","modified_gmt":"2006-07-13T10:20:00","slug":"%e7%ae%80%e5%8d%95%e7%9a%84%e5%8a%a0%e5%87%8f%e4%b9%98%e9%99%a4%e5%ae%9e%e4%be%8b-2","status":"publish","type":"post","link":"https:\/\/www.bohu.net\/blog\/8360\/","title":{"rendered":"\u7b80\u5355\u7684\u52a0\u51cf\u4e58\u9664\u5b9e\u4f8b C#"},"content":{"rendered":"<pre class=\"brush:csharp\">using System;\nusing System.Drawing;\nusing System.Collections;\nusing System.ComponentModel;\nusing System.Windows.Forms;\n\nnamespace WinForm_p169_2\n{\n        \/\/\/ &lt;summary&gt;\n        \/\/\/ Form2 \u7684\u6458\u8981\u8bf4\u660e\u3002\n        \/\/\/ &lt;\/summary&gt;\n        public class Form2 : System.Windows.Forms.Form\n        {\n                private System.Windows.Forms.ToolBar toolBar1;\n                private System.Windows.Forms.ToolBarButton toolBarButton1;\n                private System.Windows.Forms.ToolBarButton toolBarButton2;\n                private System.Windows.Forms.ToolBarButton toolBarButton3;\n                private System.Windows.Forms.ToolBarButton toolBarButton4;\n                private System.Windows.Forms.Label label1;\n                private System.Windows.Forms.Label label2;\n                private System.Windows.Forms.TextBox textBox1;\n                private System.Windows.Forms.TextBox textBox2;\n                private System.Windows.Forms.StatusBar statusBar1;\n                private System.Windows.Forms.StatusBarPanel statusBarPanel1;\n                private System.Windows.Forms.StatusBarPanel statusBarPanel2;\n                int a,b,x; \/\/ \u8fd0\u7b97\u6240\u9700\u76843\u4e2a\u53d8\u91cf\n                \/\/\/ &lt;summary&gt;\n                \/\/\/ \u5fc5\u9700\u7684\u8bbe\u8ba1\u5668\u53d8\u91cf\u3002\n                \/\/\/ &lt;\/summary&gt;\n                private System.ComponentModel.Container components = null;\n\n                public Form2()\n                {\n                        \/\/\n                        \/\/ Windows \u7a97\u4f53\u8bbe\u8ba1\u5668\u652f\u6301\u6240\u5fc5\u9700\u7684\n                        \/\/\n                        InitializeComponent();\n\n                        \/\/\n                        \/\/ TODO: \u5728 InitializeComponent \u8c03\u7528\u540e\u6dfb\u52a0\u4efb\u4f55\u6784\u9020\u51fd\u6570\u4ee3\u7801\n                        \/\/\n                }\n\n                \/\/\/ &lt;summary&gt;\n                \/\/\/ \u6e05\u7406\u6240\u6709\u6b63\u5728\u4f7f\u7528\u7684\u8d44\u6e90\u3002\n                \/\/\/ &lt;\/summary&gt;\n                protected override void Dispose( bool disposing )\n                {\n                        if( disposing )\n                        {\n                                if(components != null)\n                                {\n                                        components.Dispose();\n                                }\n                        }\n                        base.Dispose( disposing );\n                }\n\n                #region Windows \u7a97\u4f53\u8bbe\u8ba1\u5668\u751f\u6210\u7684\u4ee3\u7801\n                \/\/\/ &lt;summary&gt;\n                \/\/\/ \u8bbe\u8ba1\u5668\u652f\u6301\u6240\u9700\u7684\u65b9\u6cd5 - \u4e0d\u8981\u4f7f\u7528\u4ee3\u7801\u7f16\u8f91\u5668\u4fee\u6539\n                \/\/\/ \u6b64\u65b9\u6cd5\u7684\u5185\u5bb9\u3002\n                \/\/\/ &lt;\/summary&gt;\n                private void InitializeComponent()\n                {\n                        this.toolBar1 = new System.Windows.Forms.ToolBar();\n                        this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();\n                        this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();\n                        this.toolBarButton3 = new System.Windows.Forms.ToolBarButton();\n                        this.toolBarButton4 = new System.Windows.Forms.ToolBarButton();\n                        this.label1 = new System.Windows.Forms.Label();\n                        this.label2 = new System.Windows.Forms.Label();\n                        this.textBox1 = new System.Windows.Forms.TextBox();\n                        this.textBox2 = new System.Windows.Forms.TextBox();\n                        this.statusBar1 = new System.Windows.Forms.StatusBar();\n                        this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();\n                        this.statusBarPanel2 = new System.Windows.Forms.StatusBarPanel();\n                        ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();\n                        ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).BeginInit();\n                        this.SuspendLayout();\n                        \/\/\n                        \/\/ toolBar1\n                        \/\/\n                        this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {\n                                                                                                                                                                                this.toolBarButton1,\n                                                                                                                                                                                this.toolBarButton2,\n                                                                                                                                                                                this.toolBarButton3,\n                                                                                                                                                                                this.toolBarButton4});\n                        this.toolBar1.DropDownArrows = true;\n                        this.toolBar1.Location = new System.Drawing.Point(0, 0);\n                        this.toolBar1.Name = \"toolBar1\";\n                        this.toolBar1.ShowToolTips = true;\n                        this.toolBar1.Size = new System.Drawing.Size(292, 41);\n                        this.toolBar1.TabIndex = 0;\n                        this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);\n                        \/\/\n                        \/\/ toolBarButton1\n                        \/\/\n                        this.toolBarButton1.Tag = \"+\";\n                        this.toolBarButton1.Text = \"\u52a0\";\n                        \/\/\n                        \/\/ toolBarButton2\n                        \/\/\n                        this.toolBarButton2.Tag = \"-\";\n                        this.toolBarButton2.Text = \"\u51cf\";\n                        \/\/\n                        \/\/ toolBarButton3\n                        \/\/\n                        this.toolBarButton3.Tag = \"*\";\n                        this.toolBarButton3.Text = \"\u4e58\";\n                        \/\/\n                        \/\/ toolBarButton4\n                        \/\/\n                        this.toolBarButton4.Tag = \"\/\";\n                        this.toolBarButton4.Text = \"\u9664\";\n                        \/\/\n                        \/\/ label1\n                        \/\/\n                        this.label1.Location = new System.Drawing.Point(27, 79);\n                        this.label1.Name = \"label1\";\n                        this.label1.Size = new System.Drawing.Size(63, 27);\n                        this.label1.TabIndex = 1;\n                        this.label1.Text = \"\u7b2c\u4e00\u4e2a\u6570\";\n                        \/\/\n                        \/\/ label2\n                        \/\/\n                        this.label2.Location = new System.Drawing.Point(25, 133);\n                        this.label2.Name = \"label2\";\n                        this.label2.Size = new System.Drawing.Size(63, 27);\n                        this.label2.TabIndex = 2;\n                        this.label2.Text = \"\u7b2c\u4e8c\u4e2a\u6570\";\n                        \/\/\n                        \/\/ textBox1\n                        \/\/\n                        this.textBox1.Location = new System.Drawing.Point(94, 77);\n                        this.textBox1.Name = \"textBox1\";\n                        this.textBox1.Size = new System.Drawing.Size(129, 21);\n                        this.textBox1.TabIndex = 3;\n                        this.textBox1.Text = \"0\";\n                        \/\/\n                        \/\/ textBox2\n                        \/\/\n                        this.textBox2.Location = new System.Drawing.Point(92, 130);\n                        this.textBox2.Name = \"textBox2\";\n                        this.textBox2.Size = new System.Drawing.Size(129, 21);\n                        this.textBox2.TabIndex = 4;\n                        this.textBox2.Text = \"0\";\n                        \/\/\n                        \/\/ statusBar1\n                        \/\/\n                        this.statusBar1.Location = new System.Drawing.Point(0, 251);\n                        this.statusBar1.Name = \"statusBar1\";\n                        this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {\n                                                                                                                                                                                  this.statusBarPanel1,\n                                                                                                                                                                                  this.statusBarPanel2});\n                        this.statusBar1.ShowPanels = true;\n                        this.statusBar1.Size = new System.Drawing.Size(292, 22);\n                        this.statusBar1.TabIndex = 5;\n                        this.statusBar1.Text = \"statusBar1\";\n                        \/\/\n                        \/\/ statusBarPanel1\n                        \/\/\n                        this.statusBarPanel1.Text = \"\u7ed3\u679c\";\n                        \/\/\n                        \/\/ Form2\n                        \/\/\n                        this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);\n                        this.ClientSize = new System.Drawing.Size(292, 273);\n                        this.Controls.Add(this.statusBar1);\n                        this.Controls.Add(this.textBox2);\n                        this.Controls.Add(this.textBox1);\n                        this.Controls.Add(this.label2);\n                        this.Controls.Add(this.label1);\n                        this.Controls.Add(this.toolBar1);\n                        this.Name = \"Form2\";\n                        this.Text = \"Form2\";\n                        ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();\n                        ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).EndInit();\n                        this.ResumeLayout(false);\n\n                }\n                #endregion\n                \/\/ \u51fd\u6570\u9a8c\u8bc1\u662f\u5426\u4e3a\u6570\u5b57\n                public bool IsNumeric(string str)\n                {\n                        try\n                        {\n                                \/\/ \u5148\u5224\u65ad\u662f\u5426\u4e3a\u6574\u5f62\n                                Int32.Parse(str);\n                        }\n                        catch\n                        {\n                                \/\/ \u5728\u5224\u65ad\u662f\u5426\u4e3a\u6d6e\u70b9\u578b\n                                try\n                                {\n                                        Double.Parse(str);\n                                }\n                                catch\n                                {\n                                        return false;\n                                }\n                        }\n                        return true;\n                }\n\n                \/\/ \u8fd0\u7b97\u51fd\u6570\n                public void NumOperation(string o)\n                {\n                        \/\/ \u5224\u65ad\u8f93\u5165\u662f\u5426\u4e3a\u7a7a\n                        if((textBox1.Text!=null)||(textBox2.Text!=null))\n                        {\n                                \/\/ \u5224\u65ad\u662f\u5426\u4e3a\u6570\u5b57\n                                if(!IsNumeric(textBox1.Text)||!IsNumeric(textBox2.Text))\n                                {\n                                        this.textBox1.Text=\"0\";\n                                        this.textBox2.Text=\"0\";\n                                }\n                                else\n                                {\n                                        \/\/ \u8f6c\u6362\u8f93\u5165\u76842\u4e2a\u5b57\u7b26\u4e32\u4e3a\u6570\u5b57\n                                        a=System.Convert.ToInt32(this.textBox1.Text);\n                                        b=System.Convert.ToInt32(this.textBox2.Text);\n                                        if(o==\"+\")\n                                                x=a+b;\n                                        if(o==\"-\")\n                                                x=a-b;\n                                        if(o==\"*\")\n                                                x=a*b;\n                                        if(o==\"\/\")\n                                                if(b==0)\n                                                {\n                                                        MessageBox.Show(\"\u9664\u6570\u4e0d\u80fd\u4e3a0!\");\n                                                        this.textBox2.SelectAll();\n                                                }\n                                                else\n                                                        x=a\/b;\n                                        \/\/ \u663e\u793a\u7ed3\u679c\n                                        statusBarPanel2.Text=x.ToString();\n                                }\n                        }\n                }\n\n                private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)\n                {\n                        \/\/ \u8c03\u7528\u6309\u94ae\n                        this.NumOperation(e.Button.Tag.ToString());\n                }\n        }\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>using System; using System.Drawing; using System.Collec &hellip; <a href=\"https:\/\/www.bohu.net\/blog\/8360\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u7b80\u5355\u7684\u52a0\u51cf\u4e58\u9664\u5b9e\u4f8b C#\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,4],"tags":[50,98,159,260,374,382],"class_list":["post-8360","post","type-post","status-publish","format-standard","hentry","category-net","category-c-net","tag-net","tag-c","tag-form2-system","tag-name-form2","tag-text-form2","tag-todo"],"_links":{"self":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts\/8360","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/comments?post=8360"}],"version-history":[{"count":0,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts\/8360\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/media?parent=8360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/categories?post=8360"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/tags?post=8360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}