Setting form control proerties at runtime

H

Homer Simpson

I have a form named dataGatheringForm with a few controls on it (some
generic labels and a button).

How do I set the properties of the form (title, color, etc.) and it's
controls (a label for example) at runtime? I've included the code I have so
far and it does work.

Specifically, in this code, how do I change the label.text (control named
label1) on this form? Then, how do I retrieve the user input from a textbox
named textbox1 (textbox1.value) on the same form?

public void ShowForm()

{

Form dataForm = new dataGatheringForm();

dataForm.ShowDialog();

// dialog title = "Check Design Profile";

}



Thanks,

Scott
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

All the properties of the controls that are accesible at design time can be
adjusted at runtime.

for example:
Form dataForm = new dataGatheringForm();

dataForm..Text = "Check Design Profile";
dataForm.BackColor = Color.Black ;

dataForm.ShowDialog();

// dialog title = "Check Design Profile";

}


cheers,
 
H

Homer Simpson

That is what I thought but intellisense doesn't show any of the properties
of the form controls like the label or textbox. How do I access the
individual controls and their properties?

Thanks,
Scott

BTW, the problem with the form.title was caused by using the .showdialog and
then setting the title. I should set the title and then display it.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Haan, that's different.
Intellisense only shows you the properties of Form, as the controls you want
are declared in dataGatheringForm they are not shown.
This is what you have to do:
1- In dataGatheringForm declare public properties to make the controls
accesible.
2- If you want Intellisense to work put a /// above the property, it will
expand to the tags used by intellisense.
3- in your code below:
dataGatheringForm dataForm = new dataGatheringForm();

with that you shoulb be ok


cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top