TEXTBOX control with small calculator (original)

xiaoxiao2021-03-05  24

/*hycapril@sohu.com

What you need added,

private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Button B_1; private System.Windows.Forms.Button B_N1; private System.Windows.Forms.Button B_N2; private System.Windows.Forms.Button B_N3; private System.Windows.Forms.Button B_N4; private System.Windows.Forms.Button B_N5; private System.Windows.Forms.Button B_N6; private System.Windows.Forms.Button B_N7; private System.Windows.Forms.Button B_N8; private System.Windows.Forms.Button B_N9; private System.Windows.Forms.Button B_N0; private System.Windows.Forms.Button B_ok; private System.Windows.Forms.Button B_Cancel; private System.Windows.Forms.Button B_J; private System.Windows.Forms.Button B_JJ; private System.Windows.Forms.Button B_C; private System.Windows.Forms.Button B_CC; private System.Windows.Forms.Button B_D; Private system.windows.Forms.Button B_B;

* /

Using system.collections; using system.drawing; using system.data; using system.windows.form;

Namespace TextBoxControl {///

/// textboxControl summary description. /// TEXTBOX control with a small calculator. /// HYCAPRIL 2005 04 06 is made. ///

public class TextBoxControl: System.Windows.Forms.UserControl {private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Button B_1; private System.Windows.Forms.Button B_N1; private System.Windows.Forms.Button B_N2; private System.Windows.Forms.Button B_N3; private System.Windows.Forms.Button B_N4; private System.Windows.Forms.Button B_N5; private System.Windows.Forms.Button B_N6; private System.Windows.Forms.Button B_N7; private System.Windows.Forms.Button B_N8; private System.Windows.Forms.Button B_N9; private System.Windows.Forms.Button B_N0; private System.Windows.Forms.Button B_ok; private System.Windows.Forms.Button B_Cancel; private System.Windows.Forms.Button B_J; private System.Windows.Forms.Button B_JJ; private System.Windows.Forms.Button B_C; private System.Windows.Forms.Button B_cc; private system.windows.Forms.Button B_D; private system.windows.Forms.Button B_B; ///

/// Required designer change the amount. /// private system.componentmodel.container components = null; public textboxControl () {// This call is required for the Windows.Forms Form Designer. InitializationComponent ();

// Todo: Add any initialization after INitComponent call

}

///

/// Clean all the resources being used. /// Protected Override Void Dispose (Bool Disposing) {if (disponents! = Null) Components.dispose ();} Base.Dispose (Disposing);

#REGION component designer generated code ///

/// designer supports the required method - Do not use the code editor // to modify the contents of this method.

/// private void InitializeComponent () {System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof (TextBoxControl)); this.textBox1 = new System.Windows.Forms.TextBox (); this. B_1 = new system.windows.Forms.Button (); this.panel1 = new system.windows.forms.Panel (); this.b_b = new system.windows.forms.button (); this.b_d = new system. Windows.Forms.Button (); this.b_cc = new system.windows.Forms.Button (); this.b_c = new system.windows.forms.button (); this.b_jj = new system.windows.Forms.Button (); This.b_j = new system.windows.Forms.Button (); this.b_cancel = new system.windows.Forms.Button (); this.b_n0 = new system.windows.Forms.Button (); this. B_N9 = new system.windows.forms.button (); this.b_n8 = new system.windows.Forms.Button (); this.b_n7 = new system.windows.Forms.Button (); this.b_n6 = new system. Windows.Forms.Button (); this.b_n5 = new system.windows.Forms.Button (); this.b_n4 = new system.windows.forms.button (); THISTEM.B_N2 = New System.Windows.Forms.Button (); this.b_n1 = new system.windows.Forms.Button (); this.b_ok = new System.windows.Forms.Button (); this.Panel1.suspendlayout (); this.suspendlayout (); /// textBox1 // this.textbox1.location = new system.drawing.point (0); this .TextBox1.name = "textBox1"; this.textbox1.size = new system.drawing.size (96, 21); this.textBox1.tabindex = 0; this.textBox1.text = ""; this.TextBox1.TextChanged = New System.EventHandler (this.TextBox1_textchanged);

// // B_1 // this.B_1.BackColor = System.Drawing.SystemColors.ControlLightLight; this.B_1.FlatStyle = System.Windows.Forms.FlatStyle.Popup; this.B_1.Image = ((System.Drawing.Image (Resources.getObject))); this.b_1.location = new system.drawing.point (96, 0); this.b_1.name = "b_1"; this.b_1.size = new System.drawing.size (18, 20); this.b_1.tabindex = 1; this.b_1.click = new system.eventhandler (this.button1_click; // // panel1 // this.Panel1.backcolor = system .Drawing.systemcolors.ActiveCaptionText; this.panel1.controls.add (this.b_b); this.panel1.controls.add (this.b_d); this.panel1.controls.add (this.b_cc); this.Panel1. Controls.add (this.b_c); this.Panel1.controls.add (this.b_jj); this.Panel1.controls.add (this.b_j); this.panel1.controls.add (this.b_cancel); this. Panel1.controls.add (this.b_n0); this.Panel1.controls.add (this.b_n9); this.panel1.controls.add (this.b_n8); this.panel1.controls.add (this.b_n7); this.Panel1.controls.a DD (this.b_n6); this.Panel1.controls.add (this.b_n5); this.panel1.controls.add (this.b_n4); this.panel1.controls.add (this.b_n3); this.Panel1. Controls.add (this.b_n2); this.panel1.controls.add (this.b_n1); this.pal1.controls.add (this.b_ok); this.pal1.location = new system.drawing.point (8, 24); this.Panel1.name = "panel1"; this.Panel1.size = new system.drawing.size (96, 120); this.Panel1.tabindex = 2; // // b_b // this.b_b. FLATSTYLE = system.windows.forms.flatstyle.flat; this.b_b.location = new system.drawing.point (48, 0); this.b_b.name = "b_b"; this.b_b.size = new system.drawing .Size (48, 20);

THIS.B_B.TabINDEX = 18; this.b_b.text = "<-"; this.b_b.click = new system.eventhandler (this.b_b_click); // // b_d // this.b_d.FlatStyle = System.windows.Forms.FlatStyle.Flat; this.b_d.location = new system.drawing.point (48, 80); this.b_d.name = "b_d"; this.b_d.size = new system.drawing.size (24, 20); this.b_d.tabindex = 17; this.b_d.text = "."; This.b_d.click = new system.eventhandler (this.b_d_click); // // b_cc // this. B_cc.flatstyle = system.windows.forms.flatstyle.flat; this.b_cc.location = new system.drawing.point (72, 80); this.b_cc.name = "b_cc"; this.b_cc.size = new system .Drawing.size (24, 20); this.b_cc.tabindex = 16; this.b_cc.text = "/"; this.b_cc.click = new system.eventhandler (this.b_cc_click); // // b_c // this.b_c.flatstyle = system.windows.forms.flatstyle.Flat; this.b_c.location = new system.drawing.point (72, 60); this.b_c.name = "b_c"; this.b_c. Size = new system.drawing.size (24, 20); this.b_c.tabindex = 15; this.b_c.text = "*"; this.b_c.click = new system.eventhandler (this.b_c_click); // // b_jj // this.b_jj.Flatstyle = System.Windows.Forms.FlatStyle. Flat; this.b_jj.location = new system.drawing.point (72, 40); this.b_jj.name = "b_jj"; this.b_jj.size = new system.drawing.size (24, 20); this. B_jj.tabindex = 14; this.b_jj.text = "-"; this.b_jj.click = new system.eventhandler (this.b_jj_click); // // b_j // this.b_j.flatstyle = System.Windows. Forms.flatstyle.flat;

This.b_j.location = new system.drawing.point (72, 20); this.b_j.name = "b_j"; this.b_j.size = new system.drawing.size (24, 20); this.b_j. TabINDEX = 13; this.b_j.text = " "; this.b_j.click = new system.eventhandler (this.b_j_click); // // b_cancel // this.b_cancel.Flatstyle = System.Windows.Forms. Flatstyle.flat; this.b_cancel.location = new system.drawing.point (0, 0); this.b_cancel.name = "b_cancel"; this.b_cancel.size = new system.drawing.size (48, 20); This.b_cancel.tabindex = 11; this.b_cancel.text = "clear"; this.b_cancel.click = new system.eventhandler (this.b_cancel_click); // // b_n0 // this.b_n0.flatstyle = system. Windows.Forms.FlatStyle.FLAT; this.b_n0.location = new system.drawing.point (0, 80); this.b_n0.name = "b_n0"; this.b_n0.size = new system.drawing.size (48 , 20); this.b_n0.tabindex = 10; this.b_n0.text = "0"; this.b_n0.click = new system.eventhandler (this.b_n0_click); // // b_n9 // this.b_n9. Flatstyle = system. Windows.Forms.FlatStyle.Flat; this.b_n9.location = new system.drawing.point (48, 60); this.b_n9.name = "b_n9"; this.b_n9.size = new system.drawing.size (24 , 20); this.b_n9.tabindex = 9; this.b_n9.text = "9"; this.b_n9.click = new system.eventhandler (this.b_n9_click); // // b_n8 // this.b_n8. Flatstyle = system.windows.Forms.Flatstyle.FLAT; this.b_n8.location = new system.drawing.point (24, 60); this.b_n8.name = "b_n8"; this.b_n8.size = new system.drawing .Size (24, 20); this.b_n8.tabindex = 8;

THISB_N8.TEXT = "8"; this.b_n8.click = new system.eventhandler (this.b_n8_click); // // b_n7 // this.b_n7.flatstyle = system.windows.Forms.Flatstyle.FLAT; This.b_n7.location = new system.drawing.point (0, 60); this.b_n7.name = "b_n7"; this.b_n7.size = new system.drawing.size (24, 20); THIS.B_N7. TabINDEX = 7; this.b_n7.text = "7"; this.b_n7.click = new system.eventhandler (this.b_n7_click); // // b_n6 // this.b_n6.flatstyle = System.Windows.Forms. FLATSTYLE.FLAT; this.b_n6.location = new system.drawing.point (48, 40); this.b_n6.name = "b_n6"; this.b_n6.size = new system.drawing.size (24, 20); THIS.B_N6.TABINDEX = 6; this.b_n6.text = "6"; this.b_n6.click = new system.eventhandler (this.b_n6_click); // // b_n5 // this.b_n5.flatstyle = system. Windows.Forms.FlatStyle.Flat; this.b_n5.location = new system.drawing.point (24, 40); this.b_n5.name = "b_n5"; this.b_n5.size = new system.drawing.size (24 , 20); this.b_n5.tabindex = 5; this. B_N5.Text = "5"; this.b_n5.click = new system.EventHandler (this.b_n5_click); // // b_n4 // this.b_n4.flatstyle = system.windows.forms.Flatstyle.FLAT; this. B_n4.location = new system.drawing.point (0, 40); this.b_n4.name = "b_n4"; this.b_n4.size = new system.drawing.size (24, 20); this.b_n4.tabindex = 4; this.b_n4.text = "4"; this.b_n4.click = new system.eventhandler (this.b_n4_click); // // b_n3 // this.b_n3.flatstyle = system.windows.forms.Flatstyle. Flat; this.b_n3.location =

New system.drawing.point (48, 20); this.b_n3.name = "b_n3"; this.b_n3.size = new system.drawing.size (24, 20); this.b_n3.tabindex = 3; this. B_N3.Text = "3"; this.b_n3.click = new system.eventhandler (this.b_n3_click); // // b_n2 // this.b_n2.flatstyle = system.windows.Forms.Flatstyle.FLAT; this. B_n2.location = new system.drawing.point (24, 20); this.b_n2.name = "b_n2"; this.b_n2.size = new system.drawing.size (24, 20); this.b_n2.tabindex = 2; this.b_n2.text = "2"; this.b_n2.click = new system.eventhandler (this.b_n2_click); // // b_n1 // this.b_n1.flatstyle = system.windows.Forms.Flatstyle. Flat; this.b_n1.location = new system.drawing.point (0, 20); this.b_n1.name = "b_n1"; this.b_n1.size = new system.drawing.size (24, 20); this. B_n1.tabindex = 1; this.b_n1.text = "1"; this.b_n1.click = new system.eventhandler (this.b_n1_click); // // b_ok // this.b_ok.flatstyle = System.Windows. Forms.flatstyle.flat; this.b_ok.location = new s YSTEM.DRAWING.POINT (0, 100); this.b_ok.name = "b_ok"; this.b_ok.size = new system.drawing.size (96, 20); this.b_ok.tabindex = 0; this.b_ok .Text = "(=) OK"; this.b_ok.click = new system.eventhandler (this.button2_click); /////////////trols.add (this.Panel1); this.controls.add (this.b_1); this.Controls.add (this.textBox1); this.name = "textboxControl"; this.size = new system.drawing.size (114, 144); this.KeyPress = new System.Windows . Form.keypressEventhandler (THIS.TEXTBOXCONTROL_KEYPRESS);

This.Load = New System.EventHandler (THISTEXTBOXCONTROL_LOAD); this.Panel1.ResumeLayout (false); this.ResumeLayout (false);} #ENDREGION

#Region control Custom Property HYC07APR 2005

private string _appVer = "1.2"; [CategoryAttribute ( "version information"), DefaultValueAttribute ( "1.2"), DescriptionAttribute ( "Version Information Version Information"), ReadOnlyAttribute (true), BrowsableAttribute (true)] public string ControlVer {get { Return this._appver;} set {this._Appver = value;}}

private string _appname = "Text Box Control"; [CategoryAttribute ( "version information"), DefaultValueAttribute ( "Text Box Control"), DescriptionAttribute ( "name of the control Control Name"), ReadOnlyAttribute (true), BrowsableAttribute (true)] public string ControlName {get {return this._Appname;} set {this._appname = value;}}

private string Str = ""; [CategoryAttribute ( "custom property"), DesignerSerializationVisibility (DesignerSerializationVisibility.Visible), DefaultValueAttribute ( ""), ReadOnlyAttribute (false), DescriptionAttribute ( "Text")] public new string Text {get {return THIS.STR;} set {this.str = value;}}

#ndregion

Private static int x; private static int y; public static int b_x {set {= value;} get {return x;}} public static int b_y {set {y = value;} get {return}

private void TextBoxControl_Load (object sender, System.EventArgs e) {panel1.Visible = false; textBox1.Left = 0; textBox1.Width = this.Width -B_1.Width; B_1.Left = textBox1.Left textBox1.Width; this .Height = 20;

Private void button1_click (Object sender, system.eventargs e) {

Str = ""; TextBox1.text = Str; YunSuanFu = "00"; x = b_1.location .x-panel1.width; y = b_1.location .y b_1.height; panel1.location = new point (x, Y); if (panel1.visible == true) {Panel1.visible = false; this.height = 20;} else {panel1.visible = true; this.height = 140;}}

#Region small calculator code

Private Void Cacul () // Calculation Function 2005 04 07 {SWITCH (YunSuanfu) {CASE "1": IF (Str == ") {str =" 0 ";} v2 = double.parse (str); result = V1 V2; str = Result.Tostring (); textBox1.text = str; break; case "2": if (str == ") {str =" 0 ";} v2 = double.parse (STR); Result = V1-V2; str = Result.Tostring (); textBox1.text = Str; Break; Case "3": if (str == ") {str =" 0 ";} v2 = double.parse (STR ); Result = v1 * v2; str = result.tostring (); textBox1.text = Str; break; case "4": if (str == ") {str =" 0 ";} v2 = double.parse (Str); result = v1 / v2; str = result.tostring (); textBox1.text = str; Break; default: Break;}}

Private void button2_click (object sender, system.eventargs e) // = ok {cacul (); this.height = 20; panel1.visible = false;}

Private void b_n8_click (object sender, system.eventargs e) {str = STR "8"; TextBox1.text = Str;}

Private Void B_N3_Click (Object sender, system.eventargs e) {str = STR "3"; TextBox1.text = Str;}

Private void b_cancel_click (object sender, system.eventargs e) // clear {str = ""; textBox1.text = Str;} private void b_b_click (object sender, system.eventargs e) // <- {ix (STR! = "") {Str.substring (0, str.length-1); TextBox1.text = str;}}

Private Void B_N1_Click (Object Sender, System.EventArgs E) {str = STR "1"; TextBox1.text = Str;}

Private Void B_N2_Click (Object Sender, System.EventArgs E) {str = STR "2"; TextBox1.text = Str;}

Private void b_n4_click (object sender, system.eventargs e) {str = STR "4"; TextBox1.text = Str;}

Private Void B_N5_Click (Object Sender, System.EventArgs E) {str = STR "5"; TextBox1.text = Str;}

Private void b_n6_click (object sender, system.eventargs e) {str = STR "6"; TextBox1.text = Str;}

Private Void B_N7_Click (Object sender, system.eventargs e) {str = STR "7"; TextBox1.text = Str;}

Private Void B_N9_Click (Object sender, system.eventargs e) {str = STR "9"; TextBox1.text = Str;}

Private void b_n0_click (object sender, system.eventargs e) {str = STR "0"; textBox1.text = Str;}

Private void b_d_click (object sender, system.eventargs e) ///. {string flag = "0"; if (str == ") {str = STR " 0. "; TextBox1.text = Str;} else {for (INT i = 0; i

Private void b_jj_click (object sender, system.eventargs e) // - {if (str == ") {str =" 0 ";} Cacul (); deletezero (); v1 = double.Parse (STR); str = ""; Yunsuanfu = "2";

Private Void B_C_Click (Object sender, system.eventargs e) // * {if (str == ") {str =" 0 ";} Cacul (); deletezero (); v1 = double.parse (STR); str = ""; Yunsuanfu = "3";

Private void B_CC_Click (Object Sender, System.EventArgs E) // "/" {if (Str == ") {str =" 0 ";} Cacul (); deletezero (); v1 = double.parse (STR) ; Str = ""; Yunsuanfu = "4";

Private void deletezero () {for (int i = 1; i

Private void textbox1_textchanged (object sender, system.eventargs e) {str = textbox1.text; deletezero ();}

Private void textboxControl_KeyPress (Object sender, system.windows.med) {}}}}}}}}}}}}}}}}}

转载请注明原文地址:https://www.9cbs.com/read-36841.html

New Post(0)