DOTNET WINFORM Create FAQ (1)

xiaoxiao2021-03-06  99

1. How to set the boundary of a from

Form has a total of seven different border style to set you, you can run through generations at design time.

The code dynamics set it. These seven border styles are:

None (System.Windows.Forms.Formborderstyle.none)

Fixed 3D (System.Windows.Forms.FormBorderstyle.fixed3D)

Fixed Dialog (System.Windows.Forms.FormBorderstyle.fixedDialog)

Fixed Single (System.Windows.Forms.FormBorderstyle.fixedsingle)

Fixed Tool Window (System.Windows.Forms.FormBorderstyle.

FIXEDTOOLWINDOW)

Sizable (System.Windows.Forms.FormBorderstyle.sizable)

Sizable Tool window

(System.Windows.Forms.FormBorderstyle.sizableToolWindow)

Set the formborderstyle attribute in the Properties Window of the VS.NET ID in the design mode

Yes.

You can use the code under the mode of operation:

DLGBX1.FormBorderstyle = system.windows.forms.formolderstyle.

FixedDialog

There is no big change in this seven boundary type VB6, and you need a different enumeration in the mode of operation.

Variables are set.

2. How to build a transparent from FROM

You can do this at design time and running at both ways.

Design time, you can set the opacity property to reach this at the VS.NET IDE's Properties Window.

Effect. This value is completely transparent from 0.0 to 1.0. 0, 1.0 is completely opaque.

At runtime you can use the following encoding settings to set the Opactiy property of the form. Specific:

FRMTRANSPARENTFORM.OPACITY = 0.76; (C #)

It is very simple to see, you don't have to know what Alpha variables. Transparency is only a kind of effectiveness

Don't abuse it.

3. How to set the location of the form on the screen

You can set the StartPosition property of the form, and vs.net generally gives you a conservative option. "

WindowsDefaultLocation "This system will be set according to the user's current computer when the system is in the Load Form.

To determine a value, you can also change it to another "center" when designing.

If you must determine the form in the design mode, you can set it first.

StartPosition is Manual, then sets the value of the x and y of the Location.

Implementation of code in runtime seems to be more concise:

Form1.Location = New Point (100, 100) (VB.NET)

Of course, you can also modify the x and y values ​​of the Location, corresponding to the list of LEFTs and TOP properties, such as

:

Form1.Left = 200 (VB.NET)

Form1.top - = 100 (VB.NET)

Another property will also affect the form on the screen: DesktopLocation This property is mainly

You set the location of the form is very practical relative to the task bar (when you put the task bar on the top or on the left side of the screen.

In fact, the corresponding changes in Desktop Coordinates (0, 0)), you can set this not appearing in design

Properties in the property window,

Form1.Desktoplocation = new point (100,100)

The location of the form in the screen will mainly depend on the specific hardware and settings of their respective users, so conservative work

The method is to use the default "windowsdefaultlocation" or "center"; professional practice is the first

Get the system settings and then encodes the dynamic calculation and set, otherwise it is easy to find your form on the screen.

4. How to make minimization and maximize buttons are not available

Form.minimizeBox and form.maximizebox set in the formation Form.maximizeBox indicate display, False

It is not possible when it is not possible. See you by programming:

frmmaxmin.minnimizebox = false (vb.net)

frmmaxmin.maxmnimizebox = true (vb.net)

5. How to make a form don't see

I think the most direct way is that you call hide () methods to do this. But I want to provide another method.

You will get some other inspiration after you have seen it. (VB.NET)

Private const WS_EX_TOOLWINDOW AS INT32 = & H80

Private const WS_POPUP As Int32 = & H80000000

Private const ws_visible as int32 = & h10000000

Private const ws_sysmenu as INT32 = & h80000

Private const WS_maximizebox as int32 = & h10000

Protected Overrides Readonly Property CreateParams () AS System.

Windows.Forms.createParams

Get

DIM CP as System.Windows.Forms.createParams

Cp = mybase.createparams

cp.exStyle = WS_EX_TOOLWINDOW

Cp.Style = WS_POPUP or WS_VISible or WS_SYSMENU OR

WS_MAXIMIZEBOX

cp.height = 0

cp.width = 0

Return CP

END GET

End Property

It turned out to set Height and Width to 0, I think this way and hide () is called

It is different.

6. How to set the form into non-rectangle.

I think I am not the most professional approach, at least it can't reach the expectations, that is

Say it in some events will also change back to rectangles. But at least I can tell you: If you try to call the original

Win32's API setWindowrng is not good, I have tried this. Now you may need to know

Clock in the region property of the form

'// (vb.net)

Public SUB SETWINDOWREGON ()

DIM FORMPATH as system.drawing.drawing2d.graphicspath

Dim Reg As Drawing.Region

Dim Lret As Long

FormPath = new drawing2d.graphicspath ()

FormPath.Addellipse (New Rectangle (0, 0, 250, 120))

Me.Region = New Region (FormPath)

End Sub

Private sub button1_click (Byval Sender As System.Object, ByVal E

As system.eventargs) Handles Button1.click

Me.Region = Nothing

SetWindowRegion ()

End Sub

Protected Overrides Sub onResize (Byval E AS System.EventArgs)

Me.Region = Nothing

SetWindowRegion ()

End Sub7. How to make a form on the top of the screen.

This is a very practical feature, now you don't have to call other APIs, just set the TopMost property as

True is ok. For this property, it can be modified at design time and runtime. Code mode

:

Mytopform.topmost = true (vb.net)

8. How to display a form of Model and non-Model

The form of Model and Modeless will mainly depend on your application, the most is used in the display dialog. When you need

When you want to model, you call myform. Showdialog rather than Model's call myform.show,

ShowDialog has an optional parameter Ower to make you build a father and child relationship for a form. For example:

'Visual Basic

Private sub mnuabout_click (... args ...)

DIM F AS New Formption

F.ShowDialog ME

End Sub

One thing to note is that for ShowDialog, when executed, the form is displayed, but after this

The code will not execute, only after the window is closed, and it is instant, displayed for Show

The following code will be performed immediately after the body.

9. How to make a MDI form

1. Create a new Windows Application project

2. Add two forms of forms1, Form2 separately

3. Set the ISMDicontAiner property of Form1 to true. Make it a MDI main form.

4. Add a RichTextBox control in Form2 and set the Dock as: Fill

5. Drag a mainmenu to the form FORM1 in the Tools form, then create a menu

FILE | Windows | Help Three menu items, including new, exit menu items in the file; including Windows

Cascade, Horizontal, etc.

6. Set the mdilist property of the Windows menu item = true, so that each MDI sub-window will automatically

Add below the Windows menu item.

7. Double-click the New menu item, then add the following code:

Private void Menunew_click (Object Sender, System.Eventargs E)

{

Form2 newmdichild;

Newmdichild = new form2 ();

NEWMDICHILD.MDIPARENT = this;

Newmdichild.show ();

}

8. Add the following code in the menu items such as Windows Cascade:

Private void menuwindowcasca_click (Object Sender, System.

Eventargs E)

{

This.Layoutmdi (MDILAYOUT.CASCADE);

}

There is also the following common:

THIS.LAYOUTMDI (MDILAYOUT.TILEHORIZONTAL);

THIS.LAYOUTMDI (MDILAYOUT.TILEVERTICAL);

9. F5 runs.

The final version of VS.NET does not know if there will be a common template, but it creates a complete manual way.

MDI's window, which is a bit cumbersome, not as simple as the IDE mode of vs.net.

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

New Post(0)