dotnet WinForm FAQ 16 (first)

Source: Internet
Author: User
Tags dotnet modify
dotnet WinForm Create FAQ


Stingy God, 2001.08.31



How to build your first form and hope the following instructions can be a guideline for your quick start.



1. How to set a from boundary

2. How to create a transparent from

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

4. How to make minimized and maximize buttons unavailable

5. How to make a form disappear

6. How to set the form to be non rectangular.

7. How to make a form at the top of the screen.

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

9. How to make a form of MDI

10. How to make your form not appear on the task bar.

11. How to make a form with a splash screen.

12. How to make your form trayicon.

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

14. How to create a Windows Explorer-style form.

15. How to set the initial startup form

16. How to create a form with a background image




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




1. How to set a from boundary

There are seven different boundary styles for the form that you can set up for you to set at design time as well as through code dynamically. These seven boundary 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)

It is OK to set the FormBorderStyle property in the Properties window of the Vs.net IDE in the design mode.

In the running mode you can use the code to complete:

Dlgbx1.formborderstyle = System.Windows.Forms.FormBorderStyle.FixedDialog
These seven types of boundary type VB6, there is no big change in the running mode you need to control different enumeration variables to set.



2. How to create a transparent from

There are two ways you can do this at design time and run time.

At design time, you can set the Opacity property in the Vs.net IDE's Properties window to achieve this effect. This value is from 0.0 to 1.0. 0 means full transparency, and 1.0 means completely opaque.

Run time you can use the following code to set the form's opactiy properties to do. Specific:

frmtransparentform.opacity = 0.76; (C #)

It's easy to see now that you don't have to know any alpha variables anymore. Transparency is always an effect, don't abuse it.



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

You can set the StartPosition property of the form, VS. NET generally gives you a conservative option of "windowsdefaultlocation" so that the system will determine a value based on the user's current computer settings in the Load form, or you can change it to another value "Center" at design time.

If you have to make sure that the form appears on the screen in a design way you can set StartPosition to manual and then set the location x and Y values.

The runtime seems to be more concise with code implementations:

Form1.location = new Point (vb.net)
Of course you can also modify the x and Y values of the location separately, corresponding to the left and top properties of the form, such as:

Form1.left + (vb.net)

Form1.top = (vb.net)

Another property will also affect the position of the form on the screen: Desktoplocation This property is very useful when you set up the form position relative to the taskbar (when you put the taskbar on top or left of the screen, you actually change the desktop coordinates (0,0) So you can set this property that doesn't appear in the Design Properties window,

Form1.desktoplocation = new Point (100,100)

The position of the form on the screen will depend primarily on the specific hardware and settings of the individual user, so the conservative approach is to use the default "WindowsDefaultLocation" or "Center"; the professional approach is to get the system settings and then encode the dynamic calculation after the setting, Otherwise it's easy to find your form on the screen.



4. How to make minimized and maximize buttons unavailable

The Form.minimizebox and form.maximizebox of the form are displayed when True, and false is not. See below programmatically:

Frmmaxmin.minnimizebox = False (vb.net)

Frmmaxmin.maxmnimizebox = True (vb.net)



5. How to make a form disappear

I think the most direct way is for you to call the Hide () method to do this. But I want to provide another way, and then 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 turns out that the height and width are set to 0, and I think this approach may be different from the bottom of the hide () call.



6. How to set the form to be non rectangular.

The problem I think I'm not offering is the most professional, at least it's not what I expected, which means it's going to turn back into a rectangle in some events. But at least I can tell you this: if you try to call the original Win32 ' s API setwindowrng, I've tried so much. Now you may need to know about the region property of a form

'//(vb.net)

Public Sub setwindowregion ()



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 Sub



7. How to make a form at the top of the screen.

This is a very useful feature, and now you don't have to call other APIs, just set the topmost property to true. This property can be modified at design time and run-time. 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, most of which is used in the Display dialog box. You call MyForm when you need the model form. ShowDialog instead of the model call Myform.show, there is an optional parameter for ShowDialog ower lets you establish a parent-child relationship for a form. For example:

' Visual Basic
Private Sub mnuabout_click (... args ...)
Dim F as New formoption
F.showdialog Me
End Sub
One thing to note is that for ShowDialog, when executed to this sentence, the form is displayed, but the code that follows will not be executed until the window is closed, and is instantaneous for show, and the following code will be executed immediately after the display of the form.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.