Create (Design) a dialog box at run time.

  • Thread starter Thread starter Jean Lemaire
  • Start date Start date
J

Jean Lemaire

Hello,

I want to design a dialog box based on parameters I read from a file.
For example in the file I find "Name/char/25" and then I create a Label Text
(Name) and an Edit control that receive the value. Then I can save the
result to an XML file or other.

Thanks in advance for your help.

Jean Lemaire
 
Hi,

You can create windows controls at tun time(the type of the control you can
decide based on the data stored in your disk file) and add the same to your
windows form.

Sample code is shown below:

private System.Windows.Forms.TextBox textBox1;
this.textBox1 = new System.Windows.Forms.TextBox();

this.textBox1.Location = new System.Drawing.Point(248, 104);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(112, 20);
this.textBox1.TabIndex = 0;
this.textBox1.Text = " ";

this.Controls.Add(this.textBox1); //add text box to form


NOTE: the display position of text box is controlled using Position
property. You have to setup the position according to your layout requirement.

Thanks and Regards,
GirishKumar
 
GirishKumar said:
private System.Windows.Forms.TextBox textBox1;
this.textBox1 = new System.Windows.Forms.TextBox();

Creating a single member varaible of a specific type is probably not the
best method of handing this. It would probably be better to use a generic
local variable.

System.Windows.Forms.Control control = null;
if ( /* whatever criterion to determine type wanted */)
{
control = new System.Windows.Forms.TextBox();
}
else { /* etc */ }

this.Controls.Add(control);
 
Back
Top