Oct 8, 2015

C# basic] Button




Java need a 'SWING' for making GUI application.

But C# is comfortable.

Make GUI using toolbox then coding in property.

There are simple counter example.


First new project -> Windows Forms application program



You can see Form design.

You can make gui as drag left item.

Then setting property as left design item.

I added Text and button.


Change name.


Double click to button for button listener.


Automatically making button listener code.

Add below code.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
namespace answerofgod_button{
    public partial class Form1 : Form
    {
        int buttonCount = 0;
        public Form1()
        {
             InitializeComponent();
        }
         private void countBtn_Click(object sender, EventArgs e)
        {
            buttonCount++;
            countText.Text = buttonCount.ToString();
        }
    }
}

Line 4 : button click counter variable.

Line 11 : When button click, increase counter variable.

Line 12 : Display counter variable.

Run~

Click button~

No comments:

Post a Comment