C# Windows Form

Simple Examples in C# Windows Form Application

Example 1: Here is a first very, very simple example:

When the user clicks the button, the text “click button” is placed in the textbox.
Here is the code to perform this operation:

btn1 is the name of the button, txt1 is the name of the textBox.

If we look at the part of code concerning the creation of the window, code generated by the environment, here is what we find:

 

Example 2: Another example always very simple:

When the user clicks on the button, the text “click button” is placed in the textBox:

Moreover, when the content of the textBox is “end” the button becomes invisible, otherwise it is visible:

This type of writing should preferably be replaced by the equivalent instruction:

 

Example 3: Change background color by skipping over the textBox with the mouse (and writing the color):

The code takes the two previous examples and adds the background color change:

 

Example 4: Transfer of information between a textBox and a listBox; select an element in a listBox:

 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.