Can I use a label from one form to read from data entered into a textbox on another form? An example is entering a number in a text box and having that information displayed with the label on the other form
Asked
Active
Viewed 40 times
-4
-
When you have a question like this ask yourself the opposite - "is there a chance it's impossible to pass data from one form to the next?". If it's impossible - wouldn't you have made a major break-through in computing :D. A better question would be "how do I..." and google it first – Sten Petrov Apr 26 '15 at 03:16
1 Answers
0
Sure, it's not too rough. The general concept is that the source form (where the textbox resides) supplies the necessary value to the destination form (where the label resides). Here is a small example:
SourceForm:
namespace DataTransferBetweenForms
{
public partial class SourceForm : Form
{
public SourceForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var destinationForm = new DestinationForm();
destinationForm.LabelText = textBox1.Text;
destinationForm.Show();
}
}
}
DestinationForm:
namespace DataTransferBetweenForms
{
public partial class DestinationForm : Form
{
public string LabelText
{
get { return label1.Text; }
set { label1.Text = value; }
}
public DestinationForm()
{
InitializeComponent();
}
}
}
Now when the SourceForm's button1_Click event is triggered, an instance of DestinationForm is created, the label's Text property is set, and the DestinationForm instance is shown.

Peeticus
- 63
- 7