Use C # To develop the smartphone software: Push box (21)

Source: Internet
Author: User

This is "using C # To develop smartphone software: Push box"
SeriesArticle21st. This article introduces the window/mainform. Design. Cs SOURCEProgramFile. This source file is mainform
This class inherits from the system. Windows. Forms. Form class, which indicates the main form of the push box. This article describes the practical work of the "design" of the push box, as shown in:

Let's take a look at the sections related to the design work in the mainform. Designer. Cs source code file (which is automatically generated by Visual Studio 2005 IDE:

Namespace Skyiv. Ben. pushbox. Window
{
Partial Class Mainform
{
// Note: A lot is omitted.CodeOnly the midesign-related parts are retained.
Private   Void Initializecomponent ()
{
This . Midesign =   New System. Windows. Forms. menuitem ();
This . Midata. menuitems. Add ( This . Midesign );
This . Midesign. Text =   " Design " ;
This . Midesign. Click + =   New System. eventhandler ( This . Midesign_click );
}
Private System. Windows. Forms. menuitem midesign;
}
}

The code snippet above shows the events that occurred when you click "menu-> data-> Design" on the main form of the push box game:

This. Midesign. Click+ = NewSystem. eventhandler (This. Midesign_click );

That is to say, the pop-up "design" dialog box (introduced in the previous article "use C # To develop smartphone software: Push box (20 ), users are allowed to select the level for the game "new", "edit", and "delete. After the user selects and clicks "OK", the actual action is completed in the main form, which is implemented by the mainform. Design. Cs source code below:

1 Using System;
2 Using System. drawing;
3 Using System. Windows. forms;
4 Using Skyiv. Ben. pushbox. Common;
5
6 Namespace Skyiv. Ben. pushbox. Window
7 {
8 Partial Class Mainform
9 {
10 Void Midesign_click ( Object Sender, eventargs E)
11 {
12 Using (Designdlg DLG =   New Designdlg (topmost ))
13 {
14 DLG. maxlevelsize = Env. maxlevelsize;
15 DLG. levelsize = Env. levelsize;
16 DLG. Level = Env. level;
17 DLG. maxlelvel = Env. maxlevel;
18 If (DLG. showdialog () = Dialogresult. OK)
19 {
20 Env. Active = DLG. Active;
21 If (Env. Active = Action. delete) deletelastlevel ();
22 Else Createoreditlevel (DLG. iscopy, DLG. levelsize );
23 }
24 }
25 }
26
27 ///   <Summary>
28 /// Create a or edit the current
29 ///   </Summary>
30 ///   <Param name = "iscopy"> Whether to copy the current off when creating </Param>
31 ///   <Param name = "size"> New Dimension </Param>
32 Void Createoreditlevel ( Bool Iscopy, size)
33 {
34 If (Env. Active = Action. Create)
35 {
36 Env. newlevel (iscopy, size );
37 If (Environment. osversion. Platform ! = Platformid. wince)
38 Clientsize = Env. getclientsize (sbrmain. Visible ? Sbrmain. Height: 0 );
39 Clientsizechanged ();
40 }
41 Env. Pen = Block. Land;
42 Updatestatus ();
43 }
44
45 ///   <Summary>
46 /// Delete the last mark
47 ///   </Summary>
48 Void Deletelastlevel ()
49 {
50 Env. Active = Action. None;
51 If (Env. Level ! = Env. maxlevel -   1   | Env. maxlevel <=   1 ) Return ;
52 Env. deletelastlevel ();
53 Miprevlevel2orslot_click ( Null , Null );
54 }
55
56 ///   <Summary>
57 /// Action to be taken when you click the mouse in "design" Mode
58 ///   </Summary>
59 Void Design ()
60 {
61 Rectangle invalid;
62 If ( ! Env. Design ( Out Invalid )) Return ;
63 Invalidate (invalid );
64 Updatestatus ();
65 }
66 }
67 }
68

Notes:

    • The midesign_click method is used to process the action to be taken when you click "menu-> data-> Design" in the main form of the program, she first constructs a designdlg class (this class represents the "design" dialog box). By initializing some attributes of this class, she obtains necessary parameters (from the Env class that represents the "Work Environment, refer to "use C # To develop mobile software: Push box (11)"), and then call the showdialog method of the designdlg class to display the "design" dialog box. Finally, if the user clicks the "OK" button in the "design" dialog box, the corresponding action is performed based on the user's selection (call the deletelastlevel or createoreditlevel method ).
    • The deletelastlevel method is used to delete the last mark. This method actually calls the corresponding method of the Env class for work.
    • The createoreditlevel method is used to create a or edit the current. This method is actually used to call the corresponding methods of the Env class for work. At this time, the entire program enters the "design" mode, waiting for the user's action.
    • The design method handles the actions to be taken when you click the mouse in the "design" mode. This method actually calls the corresponding methods of the Env class for work.
Previous Article: Using C # To develop smartphone software: Push box (20)
Next article: use C # To develop the smartphone software: Push box (22nd)
Returned directory

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.