Reputation: 129
I am very new to C# programming, I have start button in one class, Transfer Start and Transfer Stop labels with TextBox in another class. As well as both are in different tabs in the design also. I am able to display start and stop time in the same tab and class but i am not able to display in another class.I have attached simple design as below.![Sample][1]
When i click"start" button in Project tab then it has to display the start time in the textbox with label "transfer start". same with stop button also. I want to display start and stop times. in the project tab i have some other functionality to add but i haven't displayed here.
Upvotes: 0
Views: 169
Reputation: 14618
You could use a delegate to pass through the value to the second tab/class to avoid cross threading problems etc... something like:
MyClass.NotifyParentUI += new EventHandler<MyArgs>(UpdateMyLabel);
public void UpdateMyLabel(object sender, MyArgs ea)
{
this.Invoke(new MethodInvoker(
delegate()
{
myLabel.Text = ea.Message;
}));
}
public class MyArgs : EventArgs
{
public string Message { get; set; }
}
And then in the class that you want to pass data from use:
public MyClass
{
public static event EventHandler<MyArgs> NotifyParentUI;
protected virtual void OnMyEvent(MyArgs ea)
{
if (NotifyParentUI != null)
{
NotifyParentUI(this, ea);
}
}
}
Using:
OnMyEvent(new MyArgs() { Message = "Transfer start/stop values go here" });
To pass the value
Upvotes: 1
Reputation: 15881
you can pass data between forms using various methods pass data between forms
if form is same for both tab, then you can use the control itself. what's the problem with that ?
public Class form2 {
public form2(string somevalues)
{
//use this values. in form2
}
}
public class form1 {
form2 objfrm = new form2("your value");
}
Upvotes: 0