Casting

A

Analizer1

Hi, I have 3 or so windows
they have 6 chkboxes ,
These Checkboxes Represent The Serial Port Signals, CD,CTS,DSR,DTR,RTC,RI
I dont want to write the same code , in 3 or 4 or more places ..
;

public static class SampleClass
{
public static void UpdateControls(Control oControl)
{
//how to cast to the Correct form so i Can
//update the controls on the Form
}
}
 
J

Jon Skeet [C# MVP]

Analizer1 said:
Hi, I have 3 or so windows
they have 6 chkboxes ,
These Checkboxes Represent The Serial Port Signals, CD,CTS,DSR,DTR,RTC,RI
I dont want to write the same code , in 3 or 4 or more places ..
;

public static class SampleClass
{
public static void UpdateControls(Control oControl)
{
//how to cast to the Correct form so i Can
//update the controls on the Form
}
}

Well, in what way is your code going to differ based on which form
you're looking at?
 
A

Analizer1

one Form is
1. Dialer form
2. Auto Answer Form
3. Automatic Processing form for (zero users data Driven)
4. Manual User Interface Terminal form with all the bells n whistle a user
needs (like hyperterminal or procomm)

each form is its own type derived from form
What i Want to do is have a Static function or member function in the NON UI
class for Serial communications
where each app can send the Approiate form to the Serial Class update the
The controls that represent the
Serial Port Signal lines.
 
B

Bjørn Brox

Analizer1 skrev:
Hi, I have 3 or so windows
they have 6 chkboxes ,
These Checkboxes Represent The Serial Port Signals, CD,CTS,DSR,DTR,RTC,RI
I dont want to write the same code , in 3 or 4 or more places ..
;

public static class SampleClass
{
public static void UpdateControls(Control oControl)
{
//how to cast to the Correct form so i Can
//update the controls on the Form
}
}
Very often I use the free-to-use Tag element to get a binding between a
userinterface element and the object it controls.

CheckBox cb;
....

cb.CheckStateChanged += new EventHandler(cb_CheckStateChanged);
cb.Tag = my_sampleclass_element;
....

static void cb_CheckStateChanged(object sender, EventArgs e)
{
CheckBox cb = (CheckBox)sender;
SampleClass s = (SampleClass)cb.Tag;
}
 
P

Peter Duniho

Hi, I have 3 or so windows
they have 6 chkboxes ,
These Checkboxes Represent The Serial Port Signals, CD,CTS,DSR,DTR,RTC,RI
I dont want to write the same code , in 3 or 4 or more places ..

And?

Honestly, none of us mind answering your questions. But you would really
help yourself and the rest of us if you would take a little more time and
thought in presenting your questions. You ask a lot of them, and they are
too often vague or (as in this case) simply missing a question altogether.

For someone posting under the pseudonym "Analizer1", you sure don't seem
to put much "analysis" into the messages you've posted. A little more
care taken on your part would go a long way.

Pete
 
J

Jon Skeet [C# MVP]

Analizer1 said:
one Form is
1. Dialer form
2. Auto Answer Form
3. Automatic Processing form for (zero users data Driven)
4. Manual User Interface Terminal form with all the bells n whistle a user
needs (like hyperterminal or procomm)

each form is its own type derived from form
What i Want to do is have a Static function or member function in the NON UI
class for Serial communications
where each app can send the Approiate form to the Serial Class update the
The controls that represent the
Serial Port Signal lines.

Why would a non-UI class know how to update a UI class? I'd expect each
of the UI classes to know how to update itself based on a particular
method call.

Consider making the forms implement an interface so that something
(whether the app or the Serial class) can make calls not caring which
of the implementations it's talking to.
 
A

Analizer1

No Problem peter....
Sometimes Im not sure what to post....
Since im still somwhat new to c#
 
P

Peter Duniho

No Problem peter....
Sometimes Im not sure what to post....
Since im still somwhat new to c#

This isn't about being "new to C#". It's about being clear when you
communicate. You write "no problem", but I'm not sure you mean that (or
even that you understand that by writing that, you are implying that you
agree to take more care with your posts in the future).

The post with which you started this thread and to which I replied did not
even have a question in it. It is possible to try to make an inference as
to the question, but frankly...if a person cannot even be bothered to ask
an actual question, I really don't see why I or anyone else should put any
effort into trying to answer the question they didn't even ask.

Those of us who answer questions (and this may one day include yourself)
do often try to make inferences and decode a person's post, to try to
offer an answer in spite of a vague, ambiguous message. But that doesn't
mean we enjoy that, and it doesn't mean we're going to do it every time.

This is especially the case when one person starts developing a reputation
of posting messages that require that extra work. That person will find
it harder and harder to get an answer as they continue to abuse the
willingness of people to try to figure out what they really mean.

To some extent, if you are not sure what to post, then maybe you shouldn't
post anything. Wait until you _are_ sure of what to post.

It's not a problem if you don't know the specific C# jargon or idioms.
But it is a problem if you cannot describe what you're trying to
accomplish clearly, or if you don't even include a question in your post.
Nothing that I'm talking about cannot be fixed by you simply taking some
more time when you compose your post, putting some thought into whether
and how the post actually expresses what you're trying to express.

Try to put yourself in the place of the person reading your post.
Understand that we aren't mind readers and the only information we have
available is that which you put as text in your post. Try reading some of
your recent posts and see if you really believe that they clearly express
whatever question it is you're trying to ask. If you perform that
analysis honestly, you'll find that they don't.

Pete
 
B

Ben Voigt [C++ MVP]

Analizer1 said:
Hi, I have 3 or so windows
they have 6 chkboxes ,
These Checkboxes Represent The Serial Port Signals,
CD,CTS,DSR,DTR,RTC,RI I dont want to write the same code , in 3 or 4
or more places .. ;


Make a UserControl.

Add the 6 checkboxes.

Add the code to go with them.

Drop that UserControl onto each of your Forms.
 

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