2. Create an MDI form app
MDI is a multi-document interface, because an Excel spreadsheet user sometimes needs to manipulate multiple tables at the same time, and MDI just provides a great convenience for this kind of operation.
To add a subform to the main form, set the current form as a container for an MDI form (that is, set the form's IsMdiContainer property to True)
Add a subform to the MDI parent form implementation
Code: From childfrom = new from ();
Childfrom.mdiparent = this;
Childfrom.text = "window" + childfromnumber++;
Childfrom.show ();
8.
You may also want to consider putting these things into events such as paint or erasebkground in specific applications.
3. Get Application path information
Desktop Windows program development, sometimes need to read the current directory of files, sometimes need to create a document in the current directory, and even sometimes self-upgrade also need to know the current directory of the application.
Here's the code for several ways to get file path information:
4. Enter Jump control focus
Customer service daily needs to enter the information quickly, and how to save them with more time, so that they have the fastest speed, minimum operating time to complete the entry of information becomes a key factor, try to avoid using the mouse operation is one of its key processes.
The following is a code example:
This will automatically jump to the next line when we press the ENTER key.
5. Transferring complex data between forms
In programming, data is passed not only in the same form, but also between forms. Sometimes it is necessary to pass more complex data between mutually callable forms, or even to modify the contents of the parent form by a subform.
Here are a few ways to pass data between forms:
(1) Construction transfer
(2) Public field delivery
1) Define the public field in Form1
TextBox1 private System.Windows.Forms.TextBox to public System.Windows.Forms.TextBox textBox1;
Or define a public field, which is more consistent with object-oriented encapsulation
2) From2 adds a public property and constructor to receive the pass value.
3) Create and Invoke From2 in From1.
(3) Delegate and event delivery
Function: Implements changing the contents of a parent form in a subform, passing a value to the parent form through delegates and events.
(1) Defines a result object that is used to store the results returned by the subform. Also define an event that allows a subform to modify the state of the parent form. The code is as follows:
This avoids the direct invocation of the parent form object in the subform, effectively reducing the dependency-level coupling between the two. The subform does not need to be recompiled after the parent form has changed. The two forms all depend on the result object at the same time, which better satisfies the principle of the encapsulation of the object and the "dependency inversion". Operation Result:
6. Implementing a personalized form interface
The creation of irregular personalization forms is implemented in C # with a small amount of code.
(1) Prepare a photo to use a white background (preferably a BMP bitmap for effect) where you intend to make it transparent
7. Two ways to drag without a title form
When you implement a personalized irregular form, the entire form is a graphic that cannot be dragged or moved without the title bar and the Close button. There are two ways to drag a form like this:
(1) Through mouse event implementation
(2) Invoking API implementations
. NET chapter fourth Windows Forms programming