Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

Casting

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Analizer1 - 11 Mar 2008 18:39 GMT
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
   }
}
Jon Skeet [C# MVP] - 11 Mar 2008 18:52 GMT
> Hi, I have 3 or so windows
> they have   6 chkboxes ,
[quoted text clipped - 10 lines]
>     }
> }

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

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Analizer1 - 11 Mar 2008 19:04 GMT
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.

>> Hi, I have 3 or so windows
>> they have   6 chkboxes ,
[quoted text clipped - 13 lines]
> Well, in what way is your code going to differ based on which form
> you're looking at?
Jon Skeet [C# MVP] - 11 Mar 2008 19:24 GMT
> one Form is
> 1.  Dialer form
[quoted text clipped - 9 lines]
> 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.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Bjørn Brox - 11 Mar 2008 19:04 GMT
Analizer1 skrev:
> Hi, I have 3 or so windows
> they have   6 chkboxes ,
[quoted text clipped - 10 lines]
>     }
> }

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;
}

Signature

Bjørn Brox

Peter Duniho - 11 Mar 2008 19:06 GMT
> 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
Analizer1 - 11 Mar 2008 19:40 GMT
No Problem peter....
Sometimes Im not sure what to post....
Since im still somwhat new to c#

>> Hi, I have 3 or so windows
>> they have   6 chkboxes ,
[quoted text clipped - 13 lines]
>
> Pete
Peter Duniho - 11 Mar 2008 21:01 GMT
> 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
Analizer1 - 12 Mar 2008 21:15 GMT
Dont Talk to me like a kid son
I said no problem
I do understand
Leave it There plz

>> No Problem peter....
>> Sometimes Im not sure what to post....
[quoted text clipped - 39 lines]
>
> Pete
Peter Duniho - 13 Mar 2008 00:53 GMT
> Dont Talk to me like a kid son

I suggest you stop acting like a kid then, grandpa.

> I said no problem

Yes, you did.

> I do understand

It sure didn't seem so from your previous reply.

> Leave it There plz

Where?
Ben Voigt [C++ MVP] - 12 Mar 2008 16:46 GMT
> 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.
Analizer1 - 12 Mar 2008 21:16 GMT
thanks alot Ben
I should of thought about that....

>> Hi, I have 3 or so windows
>> they have   6 chkboxes ,
[quoted text clipped - 9 lines]
>
> Drop that UserControl onto each of your Forms.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.