DOTNET WINFORM Create FAQ (2)

xiaoxiao2021-03-06  121

10. ????? How to display your form on the task bar.

When the boundary style of the form is Tools? Window, it will not appear on the task bar. In addition, the topic 5

The method of introducing not only the form is invisible, and it will not appear on the task strip.

???? If you are now in the world of DOTNET, this matter also changes, any WinForm window is now

There is a showintaskbar property, so you can set this property as long as you set this property. Also you can choose

Select the showintaskbar by TRUE to False in the properties window. Or use the code:

???? mytaskbarfrm.showintaskbar? =? False?;? (? C #?)

11. ????? How to make a form with startup screen.

Need you to prepare two WinForm's forms, one called it: splashscreen, make it a beautiful

Form. Then you need a main point called it: Form1, then add the following code in this form.

????? //? (? C #?)

????? protected? Override? void? onload? (? System.EventArgs? E?)

????? {

?????????? // make? load? Take? a? long? time

????????? thread.sleep (2000);

????????? base.onload (e);

?????}

Then add such a code in main:

????? [statne

????? static? void? main ()

????? {

????????? splashscreen? Splashform? =? New? Splashscreen ();

????????? splashform.show ();

????????? form1? Mainform? =? New? Form1 () ?;

????????? mainform.load? =? new? EventHandler (splashform.mainscreen_load);

????????? Application.run (Mainform);

?????}

Don't forget to add reference to threading:? Us? System.threading;

12. ????? How to make your form trayicon.

Implement this feature You can use the Notifyicon control to achieve, from Tools? Windows

Notifyicon is dragged to your form and then adds the following code, f5.

??? '? //? Vb.net

???? private? Microna? As? Icon? =? New? Icon ("icon1.ico")

???? private? Miconb? As? Icon? =? New? Icon ("icon2.ico")

???? private? MicroDisplayed? As? Boolean

???? public? SUB? New ()

???????? mybase.new

???????? form1? =? Me

???????? 'this? Call? Is? Required? By? The? Win? Form? Designer.

???????? InitializeComponent

???????? 'Todo:? Add? Any? Initialization? After? The? InitializeComponent ()

Call

???????? 'this? form? isn't? used? Directly? So? hide? it? immediately

???????? me.hide ()

???????? 'setup? THE? TRAY? icon

???????? INITIALIZENOTICON ()

???? end? SUB

???? private? Sub? Initializenotifyicon ()

???????? 'setup? The? default? icon

???????? notifyicon? =? new? system.windows.Forms.notifyicon ()

???????? notifyicon.icon? =? Micona

???????? notifyicon.text? =? "" Right? Click? For? The? Menu "

???????? notifyicon.visible? =? TRUE

???????? MICONDISPLAYED? =? TRUE

???????? 'INSERT? ALL? Menuitem? Objects? INTO? AN? Array? And? Add? Them? TO

???????? 'the? context? Menu? Simultaneously

???????? DIM? MNUITMS (3)? AS? MenuItem

???????? mnuitms (0)? =? new? menuitem ("show? form ...",? New

EVENTHANDLER (Addressof? ME.SHOWFORMSELECT))

???????? mnuitms (0) .defaultItem? =? TRUE

???????? mnuitms (1)? =? new? Menuitem ("Toggle? Image",? New

EVENTHANDLER (Addressof? Me.toggleimageselect))

???????? mnuitms (2)? =? new? menuitem ("-")

???????? mnuitms (3)? =? new? menuitem ("exit",? new? EventHandler (Addressof)

Me.exitsLect))))

???????? Dim? Notifyiconmnu? As? Contextmenu? =? New? Contextmenu (MNUITMS)

???????? notifyicon.contextMenu? =? Notifyiconmnu

???? end? SUB

???? public? Sub? ShowFormSelect (byval? Sender? As? Object ,? Byval? E? AS

System.EventArgs)

???????? 'Display? The? Settings? Dialog

???????? DIM? Settingsform? As? New? Settingsform ()

???????? settingsform.showdialog ()

???? end? SUB

???? public? Sub? ToggleImageselect (byval? Sender? As? Object ,? Byval? E? AS

System.EventArgs)

???????? 'Called? When? the? usr? selects? the?' Toggle? Image '? Context? Menu

???????? 'determine? which? icon? is? currently? Visible? and? switch? IT

???????? i? MicroDisplayed? Then

???????????? 'Called? When? the? user? selects? the?' show? form '? context? Menu

???????????? notifyicon.icon? =? Miconb

???????????? notifyicon.text? =? "SAD"

???????????? microPlayed? =? false

?????????????? notifyicon.icon? =? Micona

???????????? NOTIFYICON.TEXT? =? "Happy"

???????????? microDisplayed? =? TRUE

???????? end? IF

???? end? SUB

???? public? Sub? EXIXITSELECT (ByVal? Sender? As? Object,? BYVAL? E? As? System.

Eventargs)

???????? 'Called? When? the? user? selects? The?' exit '? context? Menu

???????? 'hide? THE? TRAY? icon

???????? notifyicon.visible? =? False

???????? 'close? UP

???????? me.close ()

???? end? SUB

???? 'form? OVERRIDES? DISPOSE? TO? CLEAN? UP? THE? Component? List.

???? public? OVERLOADS? OVERRIDES? SUB? DISPOSE ()

???????? mybase.dispose ()

???????? components.dispose ()

???? end? SUB

???? Icon file you prepare yourself, if you can see the various features about NOTIFYICOND

.

13. ???? How to modify the size and length width of the control form.

Mainly modify the winform's size,? Width? And height properties. They are all available in design and transportation

Modifications and settings during the time.

Form1.size? =? New? System.drawing.size (100,? 100)? (? VB.NET?)

Form1.Width? =? 100 ?? (VB.NET?)

Form1.height? - =? 20 ?? (VB.NET?)

14. How do I create a Windows® Explorer style form.

1. Create a new Windows? Application

2. Drag a TreeView control from the Toolbox window, a splitterk control, a listView control

, Set the TreeView's Dock property in the properties window, to: left; set the listView control

The DOCK property is: Fill

3:? F5? Run

15. ????? How to set the initial startup form

Whether it is C # or Visual? Basic's WinForm project you can in the Solution? Explorer window

Right click on your Project, then select Properties, select the form you start from your Project's properties page or

MAIN () method.

Some different is that the C # items in the current vs.net?beta2 will automatically generate main ()? Method, Visual

Basic.Net? You must add main () code, c # you can change Form1 to any you

You can start the form name:

????? //? (? C #?)

???????? static? void? main ()

???????? {

???????????? application.run (new? Form1 ());

????????}

16. How do I create a form with a background image

All forms in WinForm have a BackgroundImage property, which can be assigned to it.

. Ordinary forms can be done this setting in operation mode. For example

InitializeComponent () or form of constructor is added to the system:

THIS.BACKGROUNDIMAGE? =? new? Bitmap ("c: //dotnetApp//winform/tile.bmp"?);

???? For MDI's main form, you have to trouble, in the IDE form of VS.NET, when you set up

After the ismdicontainer property is True, you need to check if there is inTIALIZECOMPONENT ()

Such a code? (? C #?):

???????????? this.mdiclient1.dock? =? system.windows.Forms.dockStyle.Fill;

???????????? this.mdiclient1.name?=?"mdiclient1 ";

Or see MDICLIENT1? System.Windows.Forms in the Properties window combo box of the window.

This is the main MDI window, but I didn't find anything in the DOTNET document.

Description of System.Windows.Forms.mdiClient. Then you can in InitializeComponent ()

Or add such code in the constructor of the form (? C #?):

THIS.MDICLIENT1.BACKGROUNDIMAGE ?? =? new? bitmap ("C:

//DotnetApp//winform/tile.bmp "?)?

???? Online an ImageView example, demonstrated to join a line on the background of the MDI main form

Logo text method, so that your MDI form looks very commercial, specific you can do this:

1. ??? First in the infitIZeComponent in the vs.net? Automatically generate code, see if there is such a statement

(? C #?):

This.Controls.addRange (new? system.windows.forms.control []? {THIS.

Mdiclient1});

???? Is this MDICLIENT? (Haha)

2. ??? Establish the following two functions to display this LOGO character:

/ /? (? C #?)

???????? protected ?? void? MDI_ONPAINT? (?? Object? s, ?? System.windows.forms.

PaintevenTargs? E?)

???????? {

???????????? control? C? =? (Control) s;

???????????? Rectangle? R1? =? C.clientRectangle;

???????????? r1.width? - =? 4;

???????????? r1.height? - =? 4;

???????????? Rectangle? R2? =? R1;

???????????? r2.width? - =? 1;

???????????? r2.height? - =? 1;

???????????? font? F? =? New? Font ("tahoma",? 8);

???????????? String? Str? =? "Mywinform.net??2001?mywinform.Application?v1.

0 ";

???????????? StringFormat? Sf? =? New? StringFormat ();

???????????? sf.alignment.far;

???????????? sf.LineAlignment? =? stringAlignment.far;

???????????? e.graphics.drawstring (str,? f,? new? Solidbrush (SystemColors.controlDark,? r1,? sf);

???????????? e.graphics.drawstring (Str,? f,? new? Solidbrush (SystemColors.

ControlLight,? R2,? Sf);

????????}

???????? protected ?? void? MDI_ONRESIZE? (? Object? s?, ?? SYSTEM.EVENTARGS? E

)

???????? {

???????????? control? C? =? (Control) s;

???????????? c.INVALIDATE ();

????????}

3. ??? Add such code in the constructor of InitializationComponent () or form:

(? C #?)

???? this.controls [0] .paint? =? new? painteventhandler (? MDI_ONPAINT?)?

???? this.controls [0] .resize? =? new? Eventhandler (? MDI_ONRESIZE?)?

???????? Note that it will be added behind the InitializationComponent () or in the InitializationComponent letter

The triscontrols.addrange function is after.

-------------------------------------------------- ----------------------

------------

In general, the entire WinForm part has always been in Hejlsberg design VJ WFC library at the WFC library, now still

No clues can prove that DOTNET is moving the WFC library, but I still believe that Delphi and VJ users will be more

It is easy to feel the design style of Hejlsberg, such as the incident being considered a few years ago.

Let the developer in the principle of "pure Java", now we can? NBSP; naturally enjoy this feature,

But on the other hand, DOTNET and JAVA or Delphi seem to be more close, you can hardly go like the MFC era.

Look from the source code to find secrets and inside.

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

New Post(0)