winforms control question

  • Thread starter Thread starter Mike P
  • Start date Start date
M

Mike P

In a Windows app, how do you make reference to a control on another
form? I am entering the name of the form, but none of the controls
appear in Intellisense.
 
By default, controls have protected accessibility (VB has Friend). One
option is to change this to public, or create a public property that let's
you access the control or individual properties.
 
You might find that the constituent controls are private by default. Try
changing the modifier to Internal.

Hope that helps.
 
I've made both the declaration of the control public, and the click
event public, but it still doesn't appear in Intellisense on the other
form..?
 
Are you creating an instance of the other form? If you add a TextBox to the
second form and call it txtTest, then set the modifier to Internal, you
should be able to access it as follows:

Form2 f = new Form2();
f.txtTest.Text = "Hello";
f.ShowDialog();
MessageBox.Show(f.txtTest.Text);

This lets you both set and get the value in the TextBox on the second form.
 

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

Back
Top