How to Drag and Drop controls in C#
By FoxLearn 7/19/2024 2:23:46 AM 7.15K
How to Drag and Drop controls in C#
Open your Visual Studio, then click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "DraggableDemo" and then click OK
You can install the Control.Draggable library using NuGet Package Manager. Search for "Control.Draggable" and install it into your project.
Drag and drop Buton, CheckBox, ComboBox, TextBox,..etc from the Visual Studio toolbox onto your form designer.
Adding a Form_Load event handler, then modify your c# code as shown below.
private void Form1_Load(object sender, EventArgs e) { ControlExtension.Draggable(button1, true); ControlExtension.Draggable(textBox1, true); ControlExtension.Draggable(comboBox1, true); ControlExtension.Draggable(checkBox1, true); ControlExtension.Draggable(dataGridView1, true); ControlExtension.Draggable(progressBar1, true); }
Once you've completed the above steps, run your application, and you should be able to drag and drop the specified control(s) within your form.
VIDEO TUTORIAL
- How to Open and Show a PDF file in C#
- How to Get all Forms and Open Form with Form Name in C#
- How to Create a custom Progress Bar with Percentage in C#
- How to update UI from another thread in C#
- How to Create a Wait Form Dialog in C#
- How to use Advanced Filter DataGridView in C#
- How to Print DataGridView with Header & Footer with Landscape in C#
- How to Add Combobox to DataGridView in C#