Void
Drawform (Graphics G,
int
RESX,
int
RESY)
...
{g.fillRectangle (New Solidbrush (this.backcolor), 0, 0, this.width, this.Height); Float Scale = Resx / ScreenResolution; Foreach (Control C in Controls) ... {string string strand = C.gettype () .Tostring (). Substring (c.gettype (). TOSTRING (). LastIndexof (".") 1); switch (strtype) ... {copy "button": Button B = (Button) C; ControlPaint.drawButton ((button) c) .TOP ((Button) c) .width, (button) c). HEIGHT, ButtonState.Normal); g.drawstring (B.Text, B.Font, New Solidbrush (B.ForeColor), B.left B.Width / 2 - g.MeasureString (B.Text, B.Font) .width / 2, B.top B. Height / 2 - g.MeasureString ("a", b.font) .height / 2, new stringFormat ()); break; case "textbox": TextBox T = (TextBox) C; controlpaint.drawbutton (g, t. Left, t.top, t.width, t.height, buttonstate.pushed; g.FillRectangle (New SolidBrush (T.backColor), T.LEFT 1, T.TOP 1, T.Width 2, T .Height -2); g.drawstring (T.Text, T.Font, New Solidbrush (T.ForeColor), T.left 2, T.Top T.Height / 2 - g.MeasureString ("a", T.font) .height / 2, new stringFormat ()); Break; CASE "Checkbox": CheckBox CB = (Checkbox) C; if (cb.checked) Controlpaint.drawcheckbox (g, cb.left, cb.top, cb.height / 2, cb.height / 2, buttonstate.checked); ElseControlpaint.drawcheckbox (g, cb.left, cb.top, cb.height / 2, cb.height / 2, buttonstate.Normal); g.drawstring (Cb.Text, Cb.Font, New Solidbrush (Cb.ForeColor) , cb.right -cb.height - g.measureString (cb.text, cb.font) .width, cb.top, new stringFormat ()); break;}}}
Private
Void
PRINTDocument1_PrintPage
Object
Sender, system.drawing.printing.printpageeventargs e)
...
{PrinterResolution Pr = E.PageSettings.printerResolution; DrawForm (E.Graphics, Pr., Pr.} Float
ScreenResolution
=
96.0f
;
Private
Void
FORM1_PAINT (
Object
Sender, System.Windows.Forms.Painteventargs E)
...
{ScreenResolution = E.Graphics.dpix;}
Add several events. Add the following controls on the form:
Private
System.Windows.Forms.PrintPreviewDialog PrintPreviewDialog1;
Private
System.Drawing.Printing.PrintDocument printDocument1; wherein the upper window to add its Paint event which is above Form1_Paint, printDocument1 to add it PrintPage event, which is above printDocument1_PrintPage event and then use the menu or button calls printDocument1.Print (); You can print it. You can also call the printpreviewdialog1.showdialog () event directly to print previews.