WinForm Project Development Fool Tutorial

Source: Internet
Author: User

Development environment: Win7 64Bit Simplified Chinese version, VS2012 Simplified Chinese version.

Main content:

    • Login page and Main Page
    • Use of background resources
    • Control assembly
    • Making the installation package

Open VS2012, select File | new | Project , Pop New Project dialog box:

Note: The project is an entity, can be an executable file, an assembly, the solution is a collection of several projects, if you just want to do a simple tool, only one project, you can create a directory for the solution to remove, you can omit a set of directories; The solution in this example has an execution program , two assemblies, so the project name can be different from the solution name to choose from.

When you click OK , the project is generated.

Once the project is built, it is a very important habit to build and execute it immediately, and it can be done by compiling the key nodes to avoid many compilation problems.

Observe the new project, the program entry file is: Program.cs, the only form class is Form1, corresponding to two files: Form1.cs,form1.designer.cs, change Form1 to logon.

In Solution Explorer , select Form1.cs, select Rename in the right-click menu, name becomes editable, enter logon, pop-up dialog box, select Yes, build and execute , The title of the Discovery window is still Form1.

Double-click Logon.cs in Solution Explorer , open the Logon.cs design interface, right-click | properties, open the Properties page, find the text entry, change the "Form1" here to "login", and then compile and execute.

After you modify the name, you can see that there is a logon.resx file under the project, which is the resource for the logon form, and the resources and forms of the form can be easily migrated later. (This ResX file is an XML file)

Add background : In the Logon design interface, select the form, right-click the | property, find backgroundimage in the appearance, click on the following ... button, a Resource Context dialog box pops up, and the local resource corresponds to Logon.resx, and the project resource file corresponds to properties/ Resources.resx, here you choose to put in the local resources, after importing the file, you can see the logon.resx significantly bigger, open to see, you can see the entire picture is inserted into the file base64 way. After compiling, the picture is compiled into a straight line program and can be detached from the image file.

Build and execute, adjust the size of the login window, you can see the background is displayed in a tiled way, it is necessary to fix the size of the login window, in the window properties found "formborderstyle", changed to FixedSingle (other values are also OK).

Double-click Logon.resx in Solution Explorer to open the resource file, and you can see that there is an object "$this. BackgroundImage ".

From the Toolbox, drag a button into the dialog box, set the text in the Properties window, the name that appears on the button, and set (name) to BTN_OK, which is the name of the object in the source code.

Add Click event Response : In the Properties page, click the button, switch to the event page, find click, double click, automatically generated a response named Btn_ok_click, in Form.cs can see the newly generated Btn_ok_ The click Method.

Add main window : Right click Project | add | New Item | Windows Forms, enter mainframe, click Add.

Switch from the Log window to the main window:

        Private void Btn_ok_click (object  sender, EventArgs e)        {            this. DialogResult = DialogResult.OK;              This . Close ();        }
    Static classProgram {/// <summary>        ///The main entry point for the application. /// </summary>[STAThread]Static voidMain () {application.enablevisualstyles (); Application.setcompatibletextrenderingdefault (false); Logon logon=NewLogon (); if(Logon. ShowDialog ()! =DialogResult.OK) {return; } Application.Run (NewMainFrame ()); }    }

This allows you to close the login window and open the main window by clicking the button in the login window. It is not good to open the main window in the login window and then hide your own method.

Add control assembly : Right-click Solution | add | New Project | Windows Forms Control Library. A Form control library can be seen as part of a form and can be placed in other forms after it is done.

To add a control to the main form : Right-click in the Toolbox | Add Tab , create a tab named my controls, right-click | Select item , see the newly built control, click Browse, find the control's DLL. You can then add the control to the main form.

make the installation package : If you only see the one that is enabled, click on it and go to the Web page where you are registering for the download, just fill it up and download it, and it's not much trouble.

This is a limited edition, many features can not be used, open the Project Assistant page (new project will open automatically)

Application Files: Choose Add Project Outputs, select the main output of two items, i.e. EXE and DLL.

Click Build on the Setup project, under directory "Setup\express\singleimage\diskimages\disk1" There is a setup file, after installation, you can C:\Program files (x86) \ Zycguide "See the installed files below.

You can also see the program you just made from the Start menu.

Feel this kind of rubbish, I hope we all develop the green version of the software.

WinForm Project Development Fool Tutorial

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.