C # learning document

zhaozj2021-02-08  210

I first learned VB, I always feel that there is no inheritance. Later, after learning C #, I feel very convenient (C and Delphi people don't laugh at me). When designing a program, the wizard is often used to establish an interface to help users complete a one, and the usual interface is basically the same, basic two types: Welcome screens and ordinary pictures.

System Analysis: The Ordinary Wizard page is divided into top information and bottom information, and the top includes: Title, this page Description (INFO) and title image. The bottom information includes: Cancel, the next step, next (next), and finSH, some wizards also include other buttons, such as Help (HELP), but in this example, for simple start Do not consider so many situations. In the welcome screen, the main difference is top, the welcome screen does not have the title section, but there is a big picture on the left.

Realize: I use the window as the base class, first draw basic controls in the interface, see the figure below:

First of all, I am sure that I use three attributes to control the top status, Title, INFO, and Image, maybe I found that I didn't put it directly on the title, because I didn't have it necessary, I defined three variables internally: private string strTITE = ""; Private string strinfo = ""; private image imgtitle = null; change the title by three attributes of the external attribute: [Description / Set the top of the top title ")] Public string title {get {return strtitle; } Set {stratitle = value; pantitle.invalidate ();}} [Description ("Back / Set Top Title Description Text")] Public String Info {Get {Return Strinfo;} set {strinfo = value; pantitle.invalidate );}} ["Returns / Set the image of the upper right corner image or welcome screen")] public image title {get {return @} set {imgtitle = value; pantitle.invalidate ();}} in the header panel ( In the red drawing event, the title information is re-drawn:

/ / Draw information in the title

Private void pantitle_paint (Object sender, system.windows.forms.Painteventargs e) {

Graphics GRP = E.Graphics;

Grp.clear (pantitle.backcolor);

if (mGuidPageMode == tayGuidePageEnum.tayGuidePage_None) {ControlPaint.DrawBorder3D (grp, panTitle.ClientRectangle, Border3DStyle.Etched, Border3DSide.Bottom); // draw a line at the bottom of the recess of the header block

FONT FNT = New font (this.font, this.font.style | fontstyle.bold); // Draw bold title text

Solidbrush Bsh = New Solidbrush (SystemColors.ControlText);

Grp.drawstring (Strtitle, FNT, BSH, 12, 8);

Pointf Locinfo = New Pointf (20, 10 fnt.getHeight (GRP)); / / Description Text's left corner coordinate

Sizef Szimg = New Sizef (48, 48); // Graphic Size

Pointf locimg = new pointf (PANTITLE.WIDTH - Szimg.width -6, 6); / / The upper left corner coordinate of the graph

Sizef Szinfo = New Sizef (Locimg.x - Locinfo.x -2, Pantitle.Height - Locinfo.Y -5); // Text size

Rectanglef Rect = New Rectanglef (Locinfo, Szinfo); // Scope of text

Grp.drawstring (Strinfo, this.font, bsh, rect); // Draw a text

Bsh.dispose ();

IF (imgtitle! = null) {

Grp.drawImage (Imgtitle, New Rectanglef (Locimg, Szimg);

}

}

Else if (mguidpagemode == tayguide_stayGuidepage_start) {

IF (imgtitle! = null) {

Grp.drawImage (Imgtitle, Pantitle.ClientRectangle);

}

}

Grp.dispose ();

}

Everyone may find that the plotted statement is drawn, in fact, the difference between the welcome screen and the ordinary picture, we pass the property to modify the style:

[Description ("Back / Set the type of the current page (Welcome page or normal page)")]]

Public tayguidepageenum pagemode {

Get {

Return mguidpagemode;

SET {

IF (MguidPageMode! = Value) {

MguidPageMode = Value; this.suspendlayout (); // Temporary hang space layout logic

Switch (mguidpagemode) {

Case TayGuidePagenum.TayGuidePage_none: {// Ordinary interface

Pantitle.Anchor = ((Anchorstyles.top | Anchorstyles.right) | Anchorstyles.right);

Pantitle.size = new size (width, 60);

Break;

Case TayGuidePagenum.TayGuidePage_Start: {// Welcome screen

Pantitle.Anchor = ((Anchorstyles.Bottom | Anchorstyles.Left) | Anchorstyles.top;

Pantitle.size = new size (160, height-panbottom.height);

Break;

}

This.ResumeLayout (false);

}

}

}

There is not much drawing work at the bottom, only to draw a line:

Private void panbottom_paint (Object sender, system.windows.Forms.PainteventArgs e) {

Graphics GRP = E.Graphics;

ControlPaint.drawBorder3D (GRP, Panbottom.ClientRectangle, Border3DStyle.tched, Border3Dside.top); // Draw a recessed line in the bottom of the title box

Grp.dispose ();

}

Status of Button We Control:

[Description ("Return / Set whether it is allowed")]]

Public bool cancancel {

Get {

Return cmdcancel.visible;}

SET {

cmdcancel.visible = value;

}

[Description ("Back / Setup is allowed to allow Previous")]]

Public bool canback {

Get {

Return cmdback.visible;}

SET {

CMDBACK.Visible = value;

}

[Description ("Return / Set whether the next step")]

Public bool cannext {

Get {

Return cmdnext.visible;}

SET {

cmdnext.visible = value;}

}

[Description ("Return / Set whether it is allowed")]]

Public bool canfinish {

Get {

Return cmdfinish.visible;}

SET {

CMDFINISH.Visible = value;

}

Ok, we are very big, the code is very simple, we inherit the new window from this basic class to see the effect:

First, I can't solve it, if I set the window to adjust the size, the picture can't scrub, please guideline.

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

New Post(0)