controling UI of a class

  • Thread starter Thread starter Aung
  • Start date Start date
A

Aung

I have two classes under the same namespace. something like this:

class1
~~~~~

namespace myProject
{
class myUI
{
public System.Windows.Forms.Label lblStatus;
 
Hi Aung,

You may need to pass the a reference to the form instance or the
label instance in 'MyUI' to the 'LogicStuff' class.
Alternatively, you can expose events in the 'LogicStuff' class that
is fired when the label needs to be updated. 'MyUI' would then
have to subscribe to these events. When the event is fired,
'MyUI' updates its label.

In the example that you specified, let's assume we adopt the first approach:

class MyUI : Form
{
void PerformBusinessLogic()
{
LogicStuff stuff = new LogicStuff(this);
stuff.DoSomething();
}

void UpdateLabel(String text)
{
lblStatus.Text = text;
}

// ....
}


public class LogicStuff
{
private MyUI _form = null;

public LogicStuff(MyUI form)
{
this._form = form;
}

public void DoSomething()
{
// ....
_form.UpdateLabel("Completed tasks");
}
}


Regards,
Aravind C
 
Hi Aravind,

Thanks for the help.
I think i will have to follow your second method.

The reason is that "LogicStuff" will be called by 3rd class and i would like
"LogicStuff" to update the Status on "MyUI".
from your example, "MyUI" call "LogicStuff". In my case, this cannot be
done. :(

Is it possible for you to draft some code for your second suggestion?

-Aung
 
Back
Top