Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;
Namespace print
{
Public partial class print: Form
{
Public print ()
{
Initializecomponent ();
This. setmouseposition + = new resetmouseposhander (print_setmouseposition );
}
# Region attributes
Private int _ x;
Public int x
{
Get {return _ x ;}
Set {_ x = value ;}
}
Private int _ y;
Public int y
{
Get {return _ y ;}
Set {_ y = value ;}
}
Private bool _ iserr = false;
Public bool iserr
{
Get {return _ iserr ;}
Set {_ iserr = value ;}
}
# Endregion
Public Delegate void resetmouseposhander ();
Public event resetmouseposhander setmouseposition;
Public void onsetmouseposition ()
{
If (setmouseposition! = NULL)
{
Setmouseposition ();
}
Else
{
MessageBox. Show ("trying to reference an uninstantiated object! ");
}
}
Public void print_setmouseposition ()
{
If (iserr)
{
Cursor. Position = new point (x, y );
MessageBox. Show ("incorrect amount input! ");
}
Iserr = false;
}
Private void btnpreview_click (Object sender, eventargs E)
{
Printdocument1.documentname = "China Construction Bank International Remittance Application Form ";
Printpreviewdialog1.document = printdocument1;
Printpreviewdialog1.showdialog ();
}
Private void btnprint_click (Object sender, eventargs E)
{
Printdocument1.documentname = "China Construction Bank International Remittance Application Form ";
Printdialog1.document = printdocument1;
If (printdialog1.showdialog ()! = Dialogresult. Cancel)
{
Try
{
Printdocument1.print ();
}
Catch (exception ee)
{
MessageBox. Show ("Printing failed! "+ Ee. Message );
}
}
}
Private void printdocumentemediprintpage (Object sender, system. Drawing. Printing. printpageeventargs E)
{
Font titlefont = new font ("", 12, fontstyle. Underline );
E. Graphics. drawstring ("China Construction Bank International Remittance Application Form (this title is not printed)", titlefont, brushes. Black, 300, 50 );
E.graphics.drawstring(this.txt uint. Text, this.txt uint. Font, brushes. black, 200,125 );
E. graphics.drawstring(this.txt chactor. Text, this.txt chactor. Font, brushes. Black, 400,125 );
}
Private void print_load (Object sender, eventargs E)
{
This. formborderstyle = formborderstyle. None; // you can specify a window border.
This. windowstate = formwindowstate. maximized; // sets the maximum value of a program.
}
///////////////////////////////////////
/// // [This function is online Reference]
# Region converting the RMB size and amount
/// <Summary>
/// Convert the RMB size and amount
/// </Summary>
/// <Param name = "num"> amount </param>
/// <Returns> returns the capital format </returns>
Public static string numtocnum (decimal num)
{
String str1 = ""; // Chinese characters corresponding to 0-9
String str2 = "tens of thousands of Chinese characters, hundreds of millions of Chinese characters, and tens of thousands of Chinese characters"; // Chinese characters corresponding to digits
String str3 = ""; // value retrieved from the original num Value
String str4 = ""; // string format of a number
String str5 = ""; // the capital amount of RMB
Int I; // cyclic variable
Int J; // multiply the value of num by the string length of 100
String delimiter = ""; // Chinese reading of numbers
String CH2 = ""; // Chinese character reading of digits
Int nzero = 0; // number of consecutive zero values used for calculation
Int temp; // value retrieved from the original num Value
Num = math. Round (math. Abs (Num), 2); // returns the absolute value of num and rounding it to 2 decimal places.
Str4 = (long) (Num * 100). tostring (); // multiply num by 100 and convert it into a string
J = str4.length; // locate the highest bit
If (j> 15) {return "overflow ";}
Str2 = str2.substring (15-j); // retrieve the str2 value of the corresponding number of digits. For example: 200.55, J is 5, so str2 = hour
// Cyclically retrieve the value to be converted for each bit
For (I = 0; I <j; I ++)
{
Str3 = str4.substring (I, 1); // retrieves the value of a certain bit to be converted.
Temp = convert. toint32 (str3); // convert to a number
If (I! = (J-3) & I! = (J-7) & I! = (J-11) & I! = (J-15 ))
{
// When the number of retrieved digits is not RMB, or trillions of digits
If (str3 = "0 ")
{
Operator = "";
CH2 = "";
Nzero = nzero + 1;
}
Else
{
If (str3! = "0" & nzero! = 0)
{
Bytes = "zero" + str1.substring (temp * 1, 1 );
CH2 = str2.substring (I, 1 );
Nzero = 0;
}
Else
{
Dependencies = str1.substring (temp * 1, 1 );
CH2 = str2.substring (I, 1 );
Nzero = 0;
}
}
}
Else
{
// This digit is a key digit of trillions, hundreds of millions, tens of thousands, and Yuan.
If (str3! = "0" & nzero! = 0)
{
Bytes = "zero" + str1.substring (temp * 1, 1 );
CH2 = str2.substring (I, 1 );
Nzero = 0;
}
Else
{
If (str3! = "0" & nzero = 0)
{
Dependencies = str1.substring (temp * 1, 1 );
CH2 = str2.substring (I, 1 );
Nzero = 0;
}
Else
{
If (str3 = "0" & nzero> = 3)
{
Operator = "";
CH2 = "";
Nzero = nzero + 1;
}
Else
{
If (j> = 11)
{
Operator = "";
Nzero = nzero + 1;
}
Else
{
Operator = "";
CH2 = str2.substring (I, 1 );
Nzero = nzero + 1;
}
}
}
}
}
If (I = (J-11) | I = (J-3 ))
{
// If this digit is a hundred million or a metadigit, it must be written
CH2 = str2.substring (I, 1 );
}
Str5 = str5 + separator + CH2;
If (I = J-1 & str3 = "0 ")
{
// When the last digit (minute) is 0, add an integer"
Str5 = str5 + 'Integral ';
}
}
If (num = 0)
{
Str5 = "Zero RMB ";
}
Return str5;
}
# Endregion
Private void txtuint_textchanged (Object sender, eventargs E)
{
X = cursor. position. X;
Y = cursor. position. Y;
Try
{
Txtchactor. Text = numtocnum (convert. todecimal (txtuint. Text. Trim ()));
}
Catch
{
Txtuint. Focus ();
Iserr = true;
}
}
Private void picturebox#click (Object sender, eventargs E)
{
Onsetmouseposition ();
}
}
}