T
Treefrog
Hi,
I'm developing a serious headache trying to get this to work. I want to
write to a label on frmMain from another class but I can't for the life of
me figure out how to do it. I'm pretty new to c# and the only other language
I've used properly is PHP so a lot of the concepts are difficult for me to
grasp. Why it's so difficult to do what I believed should be simple is
beyond me but as I said, some concepts are difficult to understand. Any help
would be very much appreciated.
This code is currently on the form:
------------------------------------------------------------------
public void updateStatus(string newText)
{
UpdateUIDelegate uid = new UpdateUIDelegate(UpdateUI);
this.Invoke(uid, new object[] { newText });
} // end updateStatus
delegate void UpdateUIDelegate(string str);
private void UpdateUI(string uiInfo)
{
if (StatusLineCount >= StatusLineLimit)
{
this.lblStatus.Text = "";
StatusLineCount = 0;
}
this.lblStatus.Text += uiInfo;
this.lblStatus.Refresh();
StatusLineCount++;
} // end UpdateUI
-------------------------------------------------------------------
When a button is pressed on the form I run
testClass hello = new testClass("example string");
and then in there I try
updateStatus("example string");
doesn't work so I tried frmMain. but it's doesn't display updateStatus in
the autofill.
I tried making updateStatus static but that didn;t work because it had no
reference to the instance of frmMain so couldn't use the label.
Can anybody tell me how to do this? I'm sure it must be easy but I can't
figure it out....
thanks in advance,
Treefrog
I'm developing a serious headache trying to get this to work. I want to
write to a label on frmMain from another class but I can't for the life of
me figure out how to do it. I'm pretty new to c# and the only other language
I've used properly is PHP so a lot of the concepts are difficult for me to
grasp. Why it's so difficult to do what I believed should be simple is
beyond me but as I said, some concepts are difficult to understand. Any help
would be very much appreciated.
This code is currently on the form:
------------------------------------------------------------------
public void updateStatus(string newText)
{
UpdateUIDelegate uid = new UpdateUIDelegate(UpdateUI);
this.Invoke(uid, new object[] { newText });
} // end updateStatus
delegate void UpdateUIDelegate(string str);
private void UpdateUI(string uiInfo)
{
if (StatusLineCount >= StatusLineLimit)
{
this.lblStatus.Text = "";
StatusLineCount = 0;
}
this.lblStatus.Text += uiInfo;
this.lblStatus.Refresh();
StatusLineCount++;
} // end UpdateUI
-------------------------------------------------------------------
When a button is pressed on the form I run
testClass hello = new testClass("example string");
and then in there I try
updateStatus("example string");
doesn't work so I tried frmMain. but it's doesn't display updateStatus in
the autofill.
I tried making updateStatus static but that didn;t work because it had no
reference to the instance of frmMain so couldn't use the label.
Can anybody tell me how to do this? I'm sure it must be easy but I can't
figure it out....
thanks in advance,
Treefrog