Button Control
18K views
Nov 21, 2023
Button Control
View Video Transcript
0:00
In my previous video I discussed how to create a Windows Forms application using Visual Studio 2010
0:10
Now in this application in all following applications I'm going to discuss Windows Forms controls one by one in how to use them in your Windows Forms applications
0:21
So let's start by creating a new project. So what I do is file, select new project
0:29
When you select new project, I'm going to call this application button control sample
0:40
What I'm going to do in this project, I'm going to show you how to use the button control
0:47
in your Windows Forms applications. So if you look at this, by default the form is actually centralized
0:57
So to create a button control in a Windows Forms application, you simply select the button
1:06
control in your toolbox and drag and drop to the form. When you drag and drop to the form, you will see the button control is added with default
1:18
properties where text says button one. Now if you do want to change the properties of this button control, there's a problem
1:27
properties window right here what you can do is now if you have worked with
1:42
Windows forms applications prior to this Visual Studio 2010 in dot net framework
1:47
4.0 there are several new features added new properties added new methods added
1:54
to these Windows forms control and all all these changes are really pretty cool. So in this purpose of this project is to show you how
2:03
to use a button control in some of the major properties. So first thing I do like to do
2:11
in my projects that I usually change the name of the button control. So I call it Click Me
2:18
button What you can do is there are different ways to view these properties you can sort them alphabetically or you can categorize them so if I
2:31
categorize them you will see they can be minimized and maximize based on their
2:39
category so as you can see from here accessibility appearance behavior data
2:44
design focus and layout so let's let's start with the layout In layout you can see anchor auto size docking
2:55
Say if you want to change docking to centralize this will fill the whole form
3:02
If you want to say, okay dock to top, it will only fill the top area
3:08
Same thing with bottom, same thing with left and right side. I would change to none
3:16
Right now I really do not want talking location tells you where the location of this button is on the form and then we have you can also restrict the
3:25
size of a button control by setting maximum size and minimum size of the button
3:29
control so that's layout now let's go to appearance in appearance you can see
3:36
there's a background to back color and background back color is basically
3:40
background color of the button so I change background color to say chocolate or
3:46
I like say this color orange now you can also change background color as a background image image if
3:58
you go to image what it will do is it will actually ask you to import images in
4:03
local resources so what I can really do is import any image from my image gallery
4:09
and let's say let's call some of these India pictures they look they look
4:17
pretty cool how about the Taz Mahal. That's pretty cool. All right so I did import Taj Mahal. This picture is
4:28
pretty big so you can't really see but as you can see as you know increase the
4:33
size of the control button control you will see the picture in there now you
4:40
can change the let change this to say center They have all other background image properties you can stretch them Let pick a actually different image
4:54
This is just too big. This is just too big. Let's pick this one. Okay
5:04
You can see this is my button control right here. And you can change text
5:13
Let's go one by one. So flat appearance is for... Then you have flat style, standard button style, it can pop up button, flat style
5:28
I do like flat style. And foreground color basically for the text
5:35
So you can say, give me maroon. And then I'm going to change the font
5:39
Font, you can either click on this. It will bring the font dialog box
5:43
you where you can select any font say Georgia bold size say 14 or you can also
5:53
expand this from here and where you can select anything you want to type by hand
5:57
as well italics say make it true so I'm going to actually I'm going to remove the
6:06
background image because you can't really see the effects right now so I go
6:13
there and okay now you can see the property changes to the button control you
6:20
can also align images align text you feel like okay you want to start your
6:26
text with top bottom you can do all that this at this feature is actually pretty
6:31
cool because I remember I was having hard time in previous version of Windows
6:36
forms setting the button at the top like this one and when the size actually
6:41
the height of the button was bigger than the actual text. So there are so many pretty cool properties have been added to these controls
6:50
And again, these properties are not just added to the button control
6:55
They have been added to all of the control in Windows forms
6:59
So, and then, you know, there are more properties here. These are general properties and data binding is there
7:06
Design is here But these were basically the major properties so let go back to our toolbox What I going to do actually here is I actually going to add a few more controls to the button control this form
7:28
So we can test our click event functionality. So button control, you usually use button control when you need something like, say you want to click something
7:38
and you want to take some action on that click. So let's quick add a text box control to this form
7:54
And on button click event, you can, okay, go back to your properties
7:59
You can right click and say properties. If you look at this lightning events, you will see all the events related to the
8:08
to this one control specifically you know so our goal basically the mouse click or
8:16
click on this if you double click on that what happens is default click event
8:24
handler is added to your code what I'm going to do here is on this click
8:28
a handler handler is I'm going to read from I'm going to display a message box
8:38
In message box I'm going to display the data whatever is from text box one
8:47
So whatever you enter that Xbox one when you click the button I'm going to display as a message box so F5 if you hit F5
8:54
It will build and run your project So this is how my form look like so I'm going to type something here
9:04
Hello button if you click the button you will see a message box saying hello button appears on the screen
9:12
So to summarize this, there has been a lot of new properties have been added to Windows
9:20
Forms Control and this was our simple demo for button control. Now I'm going to keep continuing this series and next I'm going to discuss the text box
9:34
and then other Windows Forms Control. Till then see you
#Computers & Electronics
#Programming
#Windows & .NET