C # Learning II---Creating a simple graphics application-WPF

Source: Internet
Author: User

As simple as it is, it is now practiced-creating a simple graphical application-wpf;

1, first start Visual Studio 2012 Click File--New--project;

The window shown in the following figure, selected as "Console Application" in the installed-template--visual C # is called "Wpfhello", and finally click OK.



In the window will produce two open files, one is MainWindow.xaml.cs file, the other is Mainwindow.xam file, which is edited graphics, such as the same, inside the small window named MainWindow,

We can zoom in or out of the window by clicking on the outer border of the small window and dragging the window on the corner.



The XAML file at the bottom of the window is a graph of some of the parameters, we can change inside, can also be changed in the property, the two synchronized

I prefer to change in the properties, the mouse to hit you want to change the graphics, press the F4 key, you can pull out its corresponding Properties window, we can easily change the parameters in the property window, we put the name

Change to Hello. The following figure: (Note: We're clicking on the top border of the graphics window, which is near Hello, the title bar of the design window)



By adjusting the graphics window to fit, we start putting the build and controls into place.

Click on the Toolbox tab on the left side of Design view, which has a lot of builds, common and all of the two parts of WPF build, we in the common WPF build, double-click, or drag, or click on the control to use, and then click the Design window

Where you want to position, you can pull out the placement control, here we first pull out the label control, as shown in figure:



We can double-click the label to enter "please entere your name!", or enter it in the public Content in its properties, as on the right side of the image above;

We can also change the color of the control, select the required color in its properties-brush-background, and we can also change the font size in the property-text. Wait a minute...


Next, we put a TextBox control in the Toolbox tab on the left side of Design view, also set the parameter in its property, we renamed it "UserName", the public text empty, used to enter the name;

As shown in figure:



Immediately we pulled out the button control in the toolbox, put it on the right side of the text box, changed its property name to OK, and the public content changed to OK;

As:



We click Build solution in Build, and then "Start (without Debugging)" in debug; we can see that our graphics window is complete;

Picture below: The window on the left is what we made.



We can enter, but click OK no response, so we next perfect;


To write code for the OK button, we double-click the OK button to enter the MainWindow.xaml.cs file,

        private void Button_click_1 (object sender, RoutedEventArgs e)
        {
            MessageBox.Show ("Hello" + username.text);  Add this sentence;
        

We also click Build Solution in Build, and then start execution (without debugging) in Debug.

We enter the name, click the OK button, you can see the pop-up window

The following figure:



This is the end of our simple WPF application ...


Add a little to let our application open the title bar of the design window in the center of the screen, F4 the attribute, change the following figure:

This can be centered by opening it.


OVER!!!


********

public partial class App:application
{
protected override void Onstartup (StartupEventArgs e)
{
Base. Onstartup (e);
MainWindow = new MainWindow ();
Mainwindow.show ();
}
}

Delete the App.xmal in the

Startupuri= "MainWindow.xaml"

******




Related Article

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.