DOTNET WINFORM Create FAQ
The god of the small gas 2001.08.31
How to build your first form, I hope the following instructions can be a guidelines you start quickly.
1. How to set the boundary of a from
2. How to build a transparent from FROM
3. How to set the location of the form on the screen
4. How to make minimization and maximize buttons are not available
5. How to make a form don't see
6. How to set the form into non-rectangle.
7. How to make a form on the top of the screen.
8. How to display a form of Model and non-Model
9. How to make a MDI form
10. How to put your form is not displayed on the task bar.
11. How to make a form with startup screen.
12. How to make your form trayicon.
13. How to modify the size and length width of the control form.
14. How to create a Windows Explorer style form.
15. How to set the initial startup form
16. How to build a form with a background image
1. How to set the boundary of a from
Form has a total of seven different border styles to set up, you can set it through code dynamics at design time. 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)
Setting the formborderstyle attribute in the Properties Window of the VS.NET IDE in the design method.
You can use the code under the mode of operation:
DLGBX1.FORMBORDERSTYLE = system.windows.Forms.FormBorderstyle.FixedDialog
This seven boundary type VB6 has, there is no big change, and you need to set up different enumeration variables under the operation mode.
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 in the VS.NET IDE's Properties Window. 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 just a effect, 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" such that the system will determine a value according to the user's current computer settings, you can also change it when designing. Another value "center".
If you have to determine the form where the form appears in the design method You can set the startPosition to Manual, then set the value of the x and y of 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 form's LEFT and TOP properties, such as:
Form1.Left = 200 (VB.NET)
Form1.top - = 100 (VB.NET)
Another property will also affect the location of the form: DesktopLocation This property is mainly very practical when you set the form of the form. (When you put the task bar on the top or left of the screen, it is actually Change Desktop Coordinates (0,0)), you can set this attribute that does not appear in the design properties window,
Form1.Desktoplocation = new point (100,100)
The location of the form will depend primarily on the specific hardware and settings of their respective users, so conservative processes are with the default "WindowsDefaultLocation" or "center"; professional method is to get the system's settings and then encode dynamic computing After setting, 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 up the form indicate that it is not possible when True is displayed. False is not possible. See the 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 way, after reading it, you will get some other inspiration. (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 the bottom layer of hide () call may be different.
6. How to set the form into non-rectangle.
I think I don't have the most professional approach, at least it can't reach my expectations, that is, it will change back to rectangles in some events. 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 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 (byvale 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 Sub
7. How to make a form on the top of the screen.
This is a practical function, now you don't have to call other APIs, just set the topmost property to true. For this property, you can modify the design time and runtime. Code:
Mytopform.topmost = true (vb.net)
8. How to display a form of Model and non-Model
Model and Modeless forms will mainly depend on your app, which is used in the display dialog. When you need model's form, you call myform. Showdialog rather than Model's call Myform.Show, there is a use of showdialog The selected parameter Ower allows you to build a parent 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 the form is executed, the form is displayed, but the code will not perform, only after the window is closed, and for Show is immediate, display The following code will be executed immediately after the form.