How to set the situation of the ComboBox in C#?


How to set the situation of the ComboBox in C#?

In Windows Forms, How to set the Location of the ComboBox in C#?

ComboBox provides 2 totally different options in exceedingly single management, it suggests that ComboBox works as each TextBox and ListBox. In ComboBox, only 1 item is displayed at a time and also the remainder of the things square measure gift within the menu How to set the situation of the Combo Box in C# window form.

you’re allowed to line the situation of your ComboBox within the windows from by victimization Location Property. Or in alternative words, Location property is employed to line the coordinates of the upper-left corner of the ComboBox management relative to the upper-left corner of its kind. you’ll set this property victimization 2 totally different methods How to set the situation of the Combo Box in C# window form:

1. Design-Time:

it’s the best technique to line the situation of the ComboBox management victimization the subsequent steps:

Step 1:

produce windows kind as shown within the below image:
Visual Studio -> File -> New -> Project -> WindowsFormApp
Step 2:

Drag the ComboBox management from the tool cabinet and drop it on the windows kind. you’re allowed to put a ComboBox management anyplace on the windows kind consistent with your want.
Step 3:

when drag and drop you’ll visit the properties of the ComboBox management to line the situation of the ComboBox.

How to set the location of the ComboBox in C#?

2. Run-Time:

it’s a touch bit trickier than the higher than technique. during this technique, you’ll set the situation of the ComboBox programmatically with the assistance of given syntax:

public System.Drawing.Point Location
Here, the purpose indicates the upper-left corner of the ComboBox management relative to the upper-left corner of its kind. Following steps square measure wont to set the situation of the ComboBox:

Step 1:

produce a jazz group box victimization the ComboBox() builder is provided by the ComboBox category.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System. Data;
using System. Drawing;
using System. Linq;
using System. Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp11 {

public partial class Form1: Form {

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
// Creating and setting the properties of label
Label l = new Label();
l.Location = new Point(222, 80);
l.Size = new Size(99, 18);
l.Text = “Select Your id”;

// Adding this label to the form
this.Controls.Add(l);

// Creating and setting the properties of ComboBox

ComboBox mybox = new ComboBox();
mybox.Location = new Point(327, 77);
mybox.Size = new Size(216, 26);
mybox.Name = “My_Cobo_Box”;
mybox.Items.Add(230);
mybox.Items.Add(231);
mybox.Items.Add(232);
mybox.Items.Add(233);
mybox.Items.Add(234);

// Adding this ComboBox to the form
this.Controls.Add(mybox);
}
}
}

Have any Question or Comment?

Leave a Reply

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

Categories

%d bloggers like this: