Display numbers (similar money) in the control, you can enter the output and convert the number into text

xiaoxiao2021-03-06  21

Using system; using system.componentmodel; using system.data; using system.windows.form; using system.text;

Namespace pzcontrol {///

/// MoneyControl's summary description. /// public class MoneyControl: System.Windows.Forms.UserControl {private System.Windows.Forms.Timer timer1; private System.ComponentModel.IContainer components; private const int W = 120; // total width private const INT H = 40; // Total private const Int segment = 8; // Each segment wide private bool show = true; // Control cursor flap private struct pens // Draw vertical pen {public pen redpen; public pen Bluepen; public pen yelowpen;} private struct Num // Each section {public int index; public char number; public point point;} private number [] NUMS = new num [15]; private pens = new Pens (), PRIVATE PENS PENS = New Pens () PRIVATE NUM CURRENTNUM; Private INT UPINDEX; Private Decalog Moneyp = 0m; // Money Private Decimal Moneyup = 0m; // The previous modification prior number private bool modified = false; // has been modified /// / // Selected background color ///////////////////// ////////////////////// private Color UnselectedColor = color.White; /// /// Whether painting Border /// private bool DrawFram = true; /// // Whether is a read-only /// private bool readonly = false; private bool zf = true;

///

/// Constructor /// public MoneyControl () {// This call is required for the Windows.Forms Form Designer. InitializationComponent ();

// Todo: Add any initialization pens.bluepen = new pen (color.blue, 1); pens.redpen = new pen (color.red, 1); pens.yellowpen = new pen (color.bisque, 1); this.money = 0m; this.Width = W; this.height = h; this.currentnum = this.nums [12]; this.upindex = 12;} ///

/// Provide initial Set /// /// Whether the border /// Select color /// Colorless color /// Number Public Void StartSet (Bool Drawfram, Color SlectedColor, Color UselectedColor, Decimal Money) {IF (selectedColor == UselectedColor) {MessageBox.Show ( "time when selecting the color is not selected and is not provided to the same!"); return;} this.selectedColor = selectedColor; this.unSelectedColor = UselectedColor; this.drawFram = DrawFram; THIS.MONEYZF = MONEYP; this.moneyup = MONEYP; this.modified = false;} /// /// Provide initial setting /// /// Number public void startset (Decimal Money) {this.mon eyZF = MoneyP; this.moneyUp = MoneyP; this.modified = false;} public void StartSet (bool DrawFram, decimal MoneyP) {this.drawFram = DrawFram; this.MoneyZF = MoneyP; this.moneyUp = MoneyP; this.modified = False;} /// /// Provide initial setup /// /// Color when selected /// Colors that are not selected /// Number

public void StartSet (Color SelectedColor, Color UselectedColor, decimal MoneyP) {if (SelectedColor == UselectedColor) {MessageBox.Show ( "time when selecting the color is not selected and is not provided to the same!"); return;} this.selectedColor = SELECTEDCOLOR; this.unselectedColor = uselectedColor; this.moneyzf = Moneyp; this.moneyup = MONEYP; this.Modified = false;} ///

/// If you give up modification, /// public void CancelModif () {this.moneyzf = this.moneyup; this.modified = false;} /// /// Set or take Money /// public decimal Moneyzf {Get {IF (this.zf ) Return this.moneyp; else return-heismoneyp;} set {this.money = math.abs (value); if (value> = 0) this.zf = true; else this.zf = false;}} / // /// setting, get /// public bool modified {get {return this.modified;} set {this.modified = value; if (! value) // If save Modify this.money = this.moneyz}} public bool readonly {get {return this. ReadOnly;} set {this.readonly = value;}} /// /// Fill in the character array - set Money No symbols /// /// private decimal money {get {returnimal monkey {get {} set {num Num; char [] charp; charp = this.moneytochars (value); for (int i = 0; i <15; i ) { Num = new Num (); Num.index = i; Num.Num = Charp [i]; Num.Point = New Point (i * segment, 16); NUMS [i] = Num;} this.moneyp = value; THIS.MODIFIED = true;}} /// /// Set or take Money Positive Negative ///

Public Bool Zf {Get {Return this.zf;} set {this.zf = value; this.drawMoney (); this.modified = true;}}

///

/// Analysis Money Makes the same one with the displayed characters /// /// /// private char [] MoneyToChars (Decimal Nump) {char [] pp = new char [15]; if (nump == 0) {for (int i = 0; i <15; i ) {pp [i] = '';} Return pp;} string str = Nump.toString (). Trim (); int S = str.indexof ("."); If (s == - 1) {str = str.padleft (13, '); Str = "00"; PP = str.tochararray (); return pp;} string zstr = str.substring (0, s); if (zstr == "0") zstr = ""; String Lstr = Str.SUBSTRING (S 1, str.length -s -1); lstr = lstr.padright (2, '0'); str = zstr lstr; str = str.padleft (15, '); PP = str.tochararray (); return pp;} /// /// Clean all the resources being used. /// Protected Override Void Dispose (Bool Disposing) {if (disponents! = null) {Components.dispose ();}}}}}}}}}}}}}} Painteventargs e) {base.onpaint (e); DrawLines (E); DrawMoney ();} /// /// Draw 15 vertical line and outer frame /// /// Private void Drawlines (PainTeventargs E) {INT i = 0; INT W = 0; graphics DC = E.Graphics; i ; w = i * segment; dc.drawline (Pens.bluepen) , New Point (w, 0)); i ; w = i * segment; dc.drawline (Pens.yellowpen, New Point (w, 0), New Point (W, H)) ; I ; w = i * segment; dc.drawline (Pens.Yellowpen, New Point (w, 0), New Point (W, H));

i ; w = i * segment; dc.drawline (Pens.bluepen, new point (w, 0), new point (w, h)); i ; w = i * segment; dc.drawline (Pens.yellowpen, New Point (w, 0), new point (w, h)); i ; w = i * segment; dc.drawline (Pens.yellowpen, new point (w, 0), new point (w, h)); i W = i * segment; dc.drawline (Pens.bluepen, New Point (w, 0), New Point (w, h)); i ; w = i * segment; dc.drawline (Pens.yellowpen, New Point (w, 0), New Point (w, h)); i ; w = i * segment; dc.drawline (Pens.yellowpen, New Point (w, 0), New Point (W, H));

i ; w = i * segment; dc.drawline (Pens.bluepen, new point (w, 0), new point (w, h)); i ; w = i * segment; dc.drawline (Pens.yellowpen, New Point (w, 0), new point (w, h)); i ; w = i * segment; dc.drawline (Pens.yellowpen, new point (w, 0), new point (w, h));

i ; w = i * segment; dc.drawline (pens.redpen, new point (w, 0), new point (w, h)); i ; w = i * segment; dc.drawline (Pens.Yellowpen, New Point (w, 0), new point (w, h)); i ; w = i * segment; dc.drawline (Pens.yellowpen, new point (w, 0), new point (w, h)); if (DrawRAM) DC.DrawRectangle (New Pen (Brushes.black, 2), 0, 0, W, H);} ///

/// Redraw Money with graphics /// /// private void drawmoney () {graphics dc = this.creategraphics (); brush brush; if (this.zf) brush = brushes.black; else brush = brushes .Red; if (this.backcolor == this.selectedcolor) for (int P = 0; P <15; p ) {dc.drawstring (NUMS [P] .num.toString (), New Font ("Arial Black" , 8), brush, new rectangle (NUMS [p] .point.x -1, nums [p] .point.y), new size (9, 12)), stringFormat.GenericDefault;} else for (int P = 0; P <15; p ) {dc.drawstring (NUMS [P] .num.toString (), New Font ("Arial", 8), Brush, New Rectangle (NUMS [p] .point, New size (8, 12)), stringformat.GenericDefault;}}

#REGION component designer generated code ///

/// designer supports the required method - Do not use the code editor // to modify the contents of this method. /// private () {this.components = new system.componentmodel.container (); this.timer1 = new system.windows.forms.timer (this.components); // // Timer1 / / this.timer1.Interval = 500; this.timer1.Tick = new System.EventHandler (this.timer1_Tick); // // MoneyControl // this.BackColor = System.Drawing.SystemColors.ActiveCaptionText; this.Name = " MoneyControl "; this.Size = new System.Drawing.Size (224, 150); this.Load = new System.EventHandler (this.MoneyControl_Load); this.Enter = new System.EventHandler (this.MoneyControl_Enter); this .KeyDown = new System.Windows.Forms.KeyEventHandler (this.MoneyControl_KeyDown); this.Leave = new System.EventHandler (this.MoneyControl_Leave); this.MouseDown = new System.Windows.Forms.MouseEventHandler (this.MoneyControl_MouseDown } #ENDREGION

Private void MoneyControl_load (Object sender, system.eventargs e) {this.width = W; this.height = h; this.upindex = 12;}

private void MoneyControl_BackColorChanged (object sender, System.EventArgs e) {if (this.BackColor == this.unSelectedColor) timer1.Enabled = false; else timer1.Enabled = true;} private void timer1_Tick (object sender, System.EventArgs e) {This.show =! (This.show); graphics dc = this.creategraphics (); if (this.show) Dc.drawline (New Pen (Brushes.black, 1), New Point (Currentnum.Point.x 2, currentnum.point.y 12), new point (Currentnum.Point.x 6, currentnum.point.y 12); else dc.drawline (New Pen (this.backcolor, 1), New Point Currentnum.Point.x 2, currentnum.point.y 12), new point (currentnum.point.x 6, currentnum.point.y 12);} private void MoneyControl_enter (Object Sender, System.EventArgs e ) {THIS.BACKCOLORCHANGED = New EventHandler (MoneyControl_backcolorchange; this.backcolor = this.selectedColor; if (this.moneyp == 0m) {NUMS [12] .num = '0'; NUMS [13] .num = ' 0 '; NUMS [14] .Num =' 0 ';} this.currentnum = this.nums [12];

private void MoneyControl_Leave (object sender, System.EventArgs e) {this.BackColorChanged = new EventHandler (MoneyControl_BackColorChanged); this.BackColor = this.unSelectedColor; if (this.moneyP == 0m) {numS [12] .num = ' '; NUMS [13] .num ='; NUMS [14] .Num = ';}}

private void MoneyControl_KeyDown (object sender, System.Windows.Forms.KeyEventArgs e) {Graphics dc = this.CreateGraphics (); int code = e.KeyValue; int index = 0; upIndex = this.CurrentNum.index; dc.DrawLine ( New Pen (Brushes.Black, 1), New Point (NUMS [UPINDEX] .Point.x 2, NUMS [UPINDEX] .Point.y 12), New Point (NUMS [UPINDEX] .point.x 6, Nums [upindex] .point.y 12)); Num Temnum = new num (); temnum = NUMS [UPINDEX]; switch (code) {case 33: // Mobile cursor case 36: index = this.currentnum .index -1; IF (index <0) {index = 0; this.Parent.selectnextControl (this, false, false, false, true);} this.currentnum = this.nums [index]; dc.drawline (New Pen (THIS.BACKCOLOR, 1), New Point (Temnum.Point.x 2, Temnum.Point.y 12), New Point (Temnum.Point.x 6, Temnum.Point.y 12); Dc.drawline (New Pen (Brushes.Black, 1), New Point (Currentnum.Point.x 2, Currentnum.Point.y 12), New Point (Currentnum.Point.x 6, Currentnum.Point.y 12)); Break; Case 34: // Move the cursor Case 35: index = this.c Urrentnum.index 1; if (index> 14) {index = 14; this.parent.selectnextControl (this, true, false, false, true);} this.currentnum = this.nums [index]; dc.drawline New Pen (this.backcolor, 1), New Point (Temnum.Point.x 2, Temnum.Point.y 12), New Point (Temnum.Point.x 6, Temnum.Point.y 12))) Dc.drawline (New Pen (Brushes.black, 1), New Point (currentnum.point.x 2, currentnum.point.y 12), New Point (Currentnum.Point.x 6, Currentnum.Point. Y 12)); Break; Case 13: // Press the Enter key Keyenter (); break; case 8: // 退格 // case 46: if (this.readonly) return; backbutton (false, -1 );

Break; Case 48: // 0-- Digital Key Case 49: Case 50: Case 51: Case 52: Case 53: Case 54: Case 55: Case 56: Case 57: Case 96: Case 97: Case 98: CASE 99: Case 100: Case 101: Case 102: Case 103: Case 104: Case 105: {IF (this.readonly) Return; if (this.currentnum.index == 0) Return; int Num = 0; if (Code > = 48 && code <= 57) NUM = CODE-48; IF (CODE> = 96 && code <= 105) Num = Code-96; this.BackButton (True, Num);} Break; Case 110: // Decuog Case 190: DC.Drawline (New Pen (this.backcolor, 1), New Point (this.currentnum.point.x 2, this.currentnum.point.y 12), New Point (this.currentnum.point .X 6, this.currentnum.point.y 12); this.currentnum = this.nums [13]; break; case 109: // Negase Case 189: if (this.readonly) return; if (this.Readonly) return; THIS.ZF) this.zf = false; Break; Case 107: // Positive Case 187: if (this.readOnly) Return; if (! this.zf) this.zf = true; Break;}} public Virtual Void KE yEnter () {this.Parent.SelectNextControl (this, true, false, false, true);} private void backButton (bool numORback, int num) {string temMoneyStr = this.moneyP.ToString (); StringBuilder Zstr = new StringBuilder ( ""); Stringbuilder lstr = new stringbuilder (""); int S = 0; s = TemmoneyStr.indexof ("."); If (s == - 1) {if (this.moneyp == 0M && Numorback = = false; else zstr.Append (TemmoneyStr);} else {zstr.Append (TemmoneyStr.Substring (0, s)); lstr.Append (TemmoneyStr.Substring (S 1, TemmoneyStr.Length-S-1) } IF (lstr.tostring () ==

"") Lstr.append ("00"); int b = 0; string numstr = Num.toString (); if (this.currentnum.index> 12) // Extra number {b = 14-this.currentnum.index 1; lstr.remove (lstr.length -b, 1); if (numorback) {if (this.currentnum.index == 13) {this.currentnum = this.nums [14]; this.upindex = 13; Lstr.insert (0, Num.Tostring ()); graphics dc = this.creategraphics (); dc.drawline (new Pen (this.backcolor, 1), new point (NUMS [13] .point.x 2, Nums [13] .point.y 12), New Point (NUMS [13] .point.x 6, NUMS [13] .point.y 12));} else {lstr.Append (Num.Tostring )));}} String m = lstr.tostring (); m = m.padright (2, '0'); lstr.replace (lstr.tostring (), m);} else // integer part {b = 12 -THIS.CURRENTNUM.INDEX 1; if (! Numorback) {if (b> zstr.length) {this.upindex = this.currentnum.index; this.currentnum = this.nums [13-zstr.length]; graphics DC = this.creategraphics (); dc.drawline (New Pen (this.backcolor, 1), new point (nums [this.upindex] .point.x 2 Nums [this.upindex] .point.y 12), new point (NUMS [this.upindex] .point.x 6, NUMS [this.upindex] .point.y 12)); Return;} zstr .Remove (zstr.length -b, 1);} else {if (zstr.length> = 12) {MessageBox.show ("The maximum or minimum of the input is only 999, 999, 999, 999.99!" "/ N" "The current number is:" this.moneyzf.tostring ()); return;}}} (b> zstr.length) {numstr = Numstr.padright (b-zstr.length, '0'); Numstr = Numstr ZSTR .Tostring (); zstr.replace (zstr.tostring (), numstr);} else {b = zstr.length-b 1;

ZStr.insert (b, num.tostring ());}}} f (zstr.tostring () == "") zstr.append ("0"); decimal money = this.moneyp; try {money = Decimal. Parse (ZSTR.TOString () "." Lstr.tostring ());} catch {messagebox.show ("The number of inputs is too large, no processing! Current number" this.moneyP.toString ()); } This.money = Money; if (this.moneyp == 0m) {NUMS [12] .num = '0'; NUMS [13] .Num = '0'; NUMS [14] .Num = '0'; } this.UnDisplayMoney (); this.drawMoney ();} private void MoneyControl_MouseDown (object sender, System.Windows.Forms.MouseEventArgs e) {if (e.Button == MouseButtons.Left) {this.upIndex = this.CurrentNum .index; int = (int) Math.floor (ex / 8); this.currentnum = this.nums [i]; graphics dc = this.creategraphics (); dc.drawline (new Pen (this.backcolor, 1 ), new point (NUMS [this.upindex] .point.x 2, NUMS [this.upindex] .point.y 12), new point (NUMS [this.upindex] .point.x 6, NUMS [ This.upindex] .point.y 12)); dc.drawline (new pen (brushes.black, 1), new point (currentnum.point.x 2, currentnum.point.y 12), new Point (CurrentNum.point.X 6, CurrentNum.point.Y 12));}} private void UnDisplayMoney () {Graphics dc = this.CreateGraphics (); Brush solidBrush = new SolidBrush (this.BackColor); for (INT i = 0; i <15; i ) {dc.FillRectangle (Solidbrush, NUMS [i] .point.x 1, NUMS [i] .point.y, 7, 12);}} /// < Summary> /// Show amount /// public void displaymoney () {this.undisplayMoney (); this.drawmoney ();} // ************************ ************************************************************* Public String Moneywz () {RETURN MONEYTOWZ this.moneyzf);

PUBLIC STATIC STRING MONEYTOWZ (DECIMAL MONEYT) {Decimal Tem = Math.Abs ​​(Moneyt); String FH = ""; IF (Moneyt <0) FH = "Negative"; String TemstR = Tem.toString (); int s = Temstr.indexof ("."); string zstr = ""; string lstr = ""; if (s == - 1) {zstr = temstr;} else {zstr = Temstr.SUBSTRING (0, s); lstr = Temstr.substring (S 1, Temstr.length-S-S-1);} String [] Quan = {"", "10,000", "100 million", "mega"}; string [] wzp = {"," Pick up "," "," "}; string [] MoneyNum = new string [zstr.length]; if (zstr.length> 12) {MessageBox.show (" Number is too big, unable to handle! "); Return "";} For (int i = 0; i 3) {MessageBox.show ("Overreprocessing range!"); Return "Over the processing range!";} OPERSTR OBJ = New OPERSTR (); String [] temyushou = new string [result]; string [] temwzp = new string [result]; array.copy (WZP, 4-Result, Temwzp, 0, Result); Array.copy (Moneynum, 0, TemyUShou, 0 , RESULT); for (int i = 0 i 0) {if (Obj.toString.substring (obj.tostring.Length-1, 1) == "zero") obj.tostring = obj.tostring.remove (obj.tostring.Length -1, 1); obj.tostring = quan [q];}

For (int J = 0; j 1 && obj.tostring.substring (obj.tostring.length -1, 1) == "zero") obj.tostring = obj.tostring.remove (obj.tostring.Length-1, 1); if (obj.tostring == ") Obj.toString =" zero ";

IF (lstr! = "&&lstr! =" 00 ") {obj.tostring =" point "; OPERSTR TEMV = New OPERSTR (); for (int i = 0; i

SOHU.com Address: East to County | East to Huayuan Textile Company Control Name: MoneyControl Name Space: PZControl Use: Digital (similar money) is displayed in the control, you can enter the output and convert the number into a text! "; Return Temstr;}}

}

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

New Post(0)