Creating Simple GUI Designer in C#

May 7 2012 5:41 PM

Hi,

I am trying to create a very simple GUI designer application in C# WinForm (This is just a UI designer and not a complicated IDE).Like below image but I have problem with adding items to the form as:

1- I tried to use Drag and Drop function in C# and drag and drop selected controls(When user Mouse Down on each control panels) but this function just replace (preposition) the existing control in the form.What I meant to do is generating new control by draging to correct position in the Main Form panel.

2- Then I used a method to create control and add them to panel whenever we call the method by Mouse Down event like:

private void CreateButton()         {             Button button1 = new Button();             button1.Text = "Click Me";             button1.Location = new Point(150, 110);             MainForm.Controls.Add(button1);          }         private void btnPanel_MouseDown(object sender, MouseEventArgs e)         {             CreateButton();         }

This works but as you see it just add a hard coded button to the Main Form and it does not let user to drag the control to appropriate X,Y location.

3- The other issue is I have to create a method to check if there is any button added to the list already and if so give a different name the new button.like

Button button2 = new Button();
Button button3 = new Button();

and so on : btncustom_1, btncustom_2, btncustom_3


I really appreciate your time if you can help me to figure this out:

1- how I can drag and create(not Move) a new control and add it to the Main form

2- how to generate a controls like adding auto number naming convention  like btncustom_1, btncustom_2, btncustom_3

Thanks for you help and comments


Answers (2)