How to get the txtxbox.text from another windows form?  
Author Message
vincent90152900





PostPosted: Visual C# General, How to get the txtxbox.text from another windows form? Top

thank you

Visual C#9  
 
 
Andrej Tozon





PostPosted: Visual C# General, How to get the txtxbox.text from another windows form? Top

Hi,

you could set that txtxbox's Modifiers property to Public, which will make it accessible from other forms, or better yet [a common practice], write a public property, which will be used to access that textbox's Text property:

public string TextBoxText
{
   
get { return textBox.Text; }
   
set { textBox.Text = value; }
}

Andrej



 
 
PJ. van de Sande





PostPosted: Visual C# General, How to get the txtxbox.text from another windows form? Top

You can make the Textbox on the other form public, but a better way is to add an propertie to the Form that contains the Textbox and call this from other forms:


public class MyForm
{
public string TextOnTextBox
{
get
{
return textBox1.Text;
}
set
{
textBox1.Text = value;
}
}
}

Now you can get the by reading the TextOnTextBox property. If you want to make this readonly, just remove the set modifier.