pcbway




c# controls, C# control, controls in c#, c#programming for controlsHello everyone, hope you all are fine and having fun with your lives. Today, I am going to show you How to add C# Controls in your project. In our previous tutorial, we have seen an Introduction to C# Windows Forms in which we have created our first project and then we have discussed all about its different features like How to use Properties etc. and if you haven’t read it yet then I would suggest you to read that one first as I am gonna continue from that tutorial onward.

So, I am assuming that you have read Introduction to C# Windows Forms and you have your first project created and ready to use. So, if you have dne exactly as I have shown in my previous tutorial then you have a for as shown in the below figure:

windows forms programming in c# , c# windows forms, windows forms in c#, c# windows form, c# windows form programmingSo, now we are gonna add some C# controls in this Windows form. So, let’s get started with How to add C# Controls in it.

How to add C# Controls ???

  • In our previous tutorial, we have discussed the Toolbox, which is available on the left side of your project.
  • All the components in the toolbox are shown in the below figure:

windows forms programming in c# , c# windows forms, windows forms in c#, c# windows form, c# windows form programming

  • These are a lot of controls and we will cover most of them in our coming tutorials but rite now we are just interested in knowing How to add these C# Controls in Windows Form we created in our previous tutorial.
  • So, the first C# Control I am gonna use is the Text Box, which is present in the Common Controls category.
  • So, what you need to do is to drag this Text Box from toolbox to your Windows Form and then it will be placed on your Windows Form as shown in below figure:

c# controls, C# control, controls in c#, c#programming for controls

  • Now you can see in the above figure that our Form has a new C# Control in it which is a Text Box.
  • Now when you select this Text Box then its Properties will open up in the Properties Section.
  • From its Properties you can change many of its attributes.
  • The two main attributes in Properties of any C# Controls are Name and Text.
  • Name is the name of that Control with which we call it when we writing the code for that control.
  • Text is the text which appears on that Control for user to view.
  • Let me add another C# control on this Windows Form i.e. Button and then show you the difference between this Text and Name Property.
  • So, drag a Button from the Toolbox and place it on this Windows Form as shown in below Figure:

c# controls, C# control, controls in c#, c#programming for controls

  • So, now we have two C# Controls on our Windows Form.
  • Now I will select the Button and then its Properties will open up in the Properties Section and I am gonna change its Text to Click Here as shown in below figure:

c# controls, C# control, controls in c#, c#programming for controls

  • Now, lets see in the Form, what’s written on the Button. πŸ˜›

c# controls, C# control, controls in c#, c#programming for controls

  • Wow the magic happened πŸ˜€ and what we have written in the Text Section of the Properties of this Button has appeared on it.
  • So, that’s How the Text Property works. Whatever you written in the Text Section is appeared on that C# Control.
  • The Name of Button Control is still button1 so whenever I am gonna call this button in the back end code I will use that Name.
  • We are gonna do this in the next tutorial.

So, that’s all for today. I hope you guys now have the idea How to add C# Controls in the Windows Form. In the coming tutorial, I am gonna add code behind each of these controls and will let you know How to use them. So, till then take care and have fun !!! πŸ™‚

Leave a Reply

Your email address will not be published. Required fields are marked *

Post comment