setting form control property from class

T

tirrell payton

Hello,

I am trying to manipulate the properties of a form's controls from a class.
I dont want to make the form's control public.

Attached is a code snippet of what I am trying to accomplish:

Public Form1()

public void SetLabel4Text(string theText)
{
label4.Text = theText;
}

---
class clsDataLayer
Form1.SetLabel4Text("Hello World");

When I try to do this, I get invalid token '(' in class, struct, or
interface member declaration

Is what I am attempting to do invalid?
 
T

tirrellp

I agree with you. However, the presentation layer needs to know the
status of a function in process (attempting to connect to a database
server). Prior to the connection, the presentation layer displays "Not
yet connected" (by default).

The presentation layer calls a function in the data access layer to
attempt to connect to the database. I need a way to tell the user (by
updating the label) that the application is "Attempting to connect to
the database." The presentation layer cant query the function in
progess, only before or after. So as of now, the GUI can get a
response from the data layer when we are "Not yet connected" and when
we have "Connection Established" and when we have "Connection Error",
but I have not yet figured out how to tell the GUI "Attempting to
connect" while the data layer is actually attempting the connection.
Any ideas?
 
G

Guest

you could pass your label control 'by reference' to your function and then
use the parameter object to update its text?
 
R

RobinS

Seems like you could use event handlers somehow. Like
add a change event handler to a property in a class, say in your
business layer. Have the DAL change the property, and
have the form change the label when the property changes.
Something like that. If you want to be truly disconnected,
I mean.

I'm sure others will chime in if this is an incredibly
stupid idea. I will claim the lateness of the hour as
my excuse.

Robin S.
------------------------------
 
T

tirrell payton

So,

The UI layer will subscribe to specific events in the data access layer and
process changes to the label based on event notifications?

-Tirrell
 
R

RobinS

Right. That's my theory. Then if you changed the UI, you
could ignore the raised event by not subscribing to it,
and wouldn't have to change your DAL, which is the point
of separating them, after all.

Robin S.
--------------------------------
 
T

tirrell payton

I understand the theory behind it perfectly, but I have no idea how to
implement it.
Can you show me an example of the following:

Datalayer class raises event 1
Datalayer class raises event 2

UI class catches event and changes a label to "event 1"
UI class catches event and changes a label to "event 2"
 
R

RobinS

Well, I can implement it in VB, but I don't do C# very well.
Would that help anyway?

Robin S.
-------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top