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 Form1 in the Tools form, then create a menu file | Windows | Help three menu items, including new, exit menu items in the file; Windows include Cascade, Horizontal, and so on.
6. Set the MDilist property of the Windows menu item = true, so that each MDI sub-window will be automatically added 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 universal template, but a MDI window is generated in a complete manual manner, which is not as simple as the IDE mode of VS.NET.
10. How to put your form is not displayed on the task bar.
When the boundary style of the form is Tools Window, it does not appear on the task bar. In addition, the method described in the topic 5 is not only the form of the form, not on the task bar.
If you are now in the world of DotNet, this matter also changes, any Winform window is now there is a showintaskbar attribute, so you can use this property as long as you set this property. Also you can choose to change the showintaskbar from true 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, a name: 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 loading take a long time
Thread.sleep (2000);
Base.onLoad (e);
}
Then add such a code in main:
[Stathread]
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: use system.threading;
12. How to make your form trayicon.
Implement this feature You can use the Notifyicon control to achieve, drag the Notifyicon to your form from Tools Windows and then add 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 anyinitization after the initializationcomponent () CALL
'this form isn't Used Directly SO Hide IT IMMEDIATELY
Me.hide ()
'setup the TRY icon
Initializenotifyicon ()
End Sub
Private subinitizenotifyicon ()
'setup the default icon
Notifyicon = new system.windows.Forms.notifyicon ()
Notifyicon.icon = Micona
Notifyicon.text = "Right Click for the Menu"
Notifyicon.visible = True
MicroDisplayed = 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 e as system.eventargs) 'Display the settings dialog
DIM Settingsform as new settingsform ()
Settingsform.showdialog ()
End Sub
Public Sub ToggleImageselect (Byval E AS ISTEM.EventArgs)
'Called when User Selects the' Toggle Image 'Context Menu
'DETERMINE WHICH ICON IS CURRENTLY Visible and Switch IT
IF MicroPlayed Then
'Called When the User Selects The' Show Form 'Context Menu
Notifyicon.icon = Miconb
Notifyicon.text = "sad"
MicroDisplayed = FALSE
Else
Notifyicon.icon = Micona
Notifyicon.text = "happy"
MicroDisplayed = TRUE
END IF
End Sub
Public Sub EXITSELECT (Byval E AS ISTEM.EventArgs)
'Called when 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 files are ready, if you can see you have all functions about Notifyicond.
13. How to modify the size and length width of the control form.
Mainly modify the Size, Width, and Height properties of WinForm. Also they are modified and setup in design and runtime.
Form1.size = new system.drawing.size (100, 100) (VB.NET)
Form1.width = 100 (VB.NET)
Form1.height - = 20 (VB.NET)
14. How to 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, is :: left; set the Dock property of the ListView control: Fill
3: F5 operation
15. How to set the initial startup form
Whether it is C # or Visual Basic's WinForm project, you can right-click your Project in the Solution Explorer window, then select Properties, select the form you start from your Project's property page or the main () method. Some differences are the current VS.NET beta2 C # project automatically generate main () methods, Visual Basic.Net project you must add main () code, c # you can change Form1 to any you can start Form name:
// (C #)
Static void
Main
()
{
Application.run (New Form1 ());
}
16. How to build a form with a background image
All forms in WinForm have a BackgroundImage property, which is only used to assign it. Ordinary forms can be done this setting in operation mode. For example, add such code to the constructor of InitializationComponent () or form:
THIS.BACKGROUNDIMAGE = New bitmap ("c: //dotnetApp//winform/tile.bmp");
For MDI's main form, you have to trouble some, in the IDE form of VS.NET, when you set the ismdicontainer property is true, you need to check if there is such code (C #) in itializeComponent ():
This.mdiclient1.dock = system.windows.Forms.dockStyle.Fill;
THIS.MDICLIENT1.NAME = "mdiclient1";
Or see mdiclient1 system.windows.forms.mdiclient in the properties window combo box of the window. This is the main MDI window, but I didn't find any instructions on System.Windows.Forms.mdiClient in the DOTNET document. Then you can add such code (C #) in the constructor of InitializationComponent () or form:
This.mdiclient1.backgroundimage = new bitmap ("c: //dotnetApp//winform/tile.bmp");
There is an ImageView example on the Internet, which demonstrates the way to join the logo text on the background of the MDI main form, which makes your MDI form look very commercial, specific you can do this:
1. See if there is such a statement in the initializeComponent that automatically generates code in VS.NET (C #):
This.Controls.addRange (new system.windows.forms.control [] {this.mdiclient1});
This 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 = stringalignment.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 this code in the constructor of the initializeComponent () or form:
(C #)
This.Controls [0] .paint = new painteventhandler (MDI_ONPAINT);
This.Controls [0] .resize = New EventHandler (MDI_ONRESize);
Note After INITIALIZECOMPONENT () or after this.controls.addrange function in the initializeComponent function.
In general, the entire WinForm section always has a breath of the WFC library in Hejlsberg, and now there is no clue to prove that DOTNET is moving the WFC library, but I still believe that Delphi and VJ users will easily feel the design of Hejlsberg. Style, such as the event is deemed to be a few years ago, which is considered to be awarded against the principle of "pure Java", which has caused the developers into embarrassment. Now we can enjoy this feature naturally, but on the other hand DOTNET and JAVA or Delphi seems to be More close, you can hardly find secrets and inside those from the source code like the MFC era.