Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's Calculator Programming subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. General Coding and Design => Calculator Programming
Author Message
Newbie


Bandwidth Hog


Joined: 23 Jan 2004
Posts: 2247

Posted: 20 Apr 2009 07:53:08 pm    Post subject:

How would I replicate this in C#?


Code:
Private Sub Toppings_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles chkRelish.Click, chkKraut.Click, chkCheese.Click

Dim chkSelectedTopping As CheckBox = sender

If chkSelectedTopping.Checked Then
     
        Select Case chkSelectedTopping.Tag
         
             Case "Relish"
       
             Case "Kraut"
         
             Case "Cheese"
     
        End Select

Else

End If
Back to top
benryves


Active Member


Joined: 23 Feb 2006
Posts: 564

Posted: 21 Apr 2009 08:41:35 am    Post subject:


Code:
private void Toppings_Click(object sender, EventArgs e) {
   CheckBox chkSelectedTopping = sender as CheckBox;
   if (chkSelectedTopping != null && chkSelectedTopping.Checked) {
      switch (chkSelectedTopping.Tag as string) {
         case "Relish":
            break;
         case "Kraut":
            break;
         case "Cheese":
            break;
      }
   }
}

You can now either go and hook up this event handler via the property editor in the form designer (select chkRelish, go to the properties window, select CheckedChanged and pick Toppings_Click from the dropdown) or stick this in the form's constructor:


Code:
this.chkRelish.CheckedChanged += new EventHandler(Toppings_Click);
this.chkKraut.CheckedChanged += new EventHandler(Toppings_Click);
this.chkCheese.CheckedChanged += new EventHandler(Toppings_Click);

Dare I ask what "Kraut" is? Over here it's a derogatory term for a German. :\
Back to top
Galandros


Active Member


Joined: 29 Aug 2008
Posts: 565

Posted: 21 Apr 2009 11:40:17 am    Post subject:

benryves wrote:
Dare I ask what "Kraut" is? Over here it's a derogatory term for a German. :\

I knew translation to my mother language but from that to English is a little more hard... XD

*some minutes after*
Cabbage / collard green, but not totality sure.
Or something related to a grass or a herb.

I don't know how it ended to have other meanings than the common but it has a common.
Back to top
Newbie


Bandwidth Hog


Joined: 23 Jan 2004
Posts: 2247

Posted: 21 Apr 2009 11:58:27 am    Post subject:

Galandros wrote:
benryves wrote:
Dare I ask what "Kraut" is? Over here it's a derogatory term for a German. :\

I knew translation to my mother language but from that to English is a little more hard... XD

*some minutes after*
Cabbage / collard green, but not totality sure.
Or something related to a grass or a herb.

I don't know how it ended to have other meanings than the common but it has a common.



Would never have guessed. I got the example from a vb.net book. Following the flow of things yes it is a food (cabbage) over here in the states. Next time I'll change up the foods. I didn't like the ones they used either but I was too lazy to change what I saw. Sorry, meant no offense.

thanks for your help as always.

Kraut is actually sauerkraut though. Or that's what it's called.

Nasty food though: http://www.all-creatures.org/recipes/images/i-sauerkraut.jpg


Last edited by Guest on 21 Apr 2009 12:01:44 pm; edited 1 time in total
Back to top
benryves


Active Member


Joined: 23 Feb 2006
Posts: 564

Posted: 21 Apr 2009 12:09:18 pm    Post subject:

Ah, I see. (I'm not offended, just curious)!

One thing I should probably have commented on was my use of the "as" keyword. In C#, you can convert types by casting them (CheckBox chkSelectedTopping = (CheckBox)sender;) - however, if sender cannot be converted to a CheckBox, that would throw an exception. When using the as keyword (CheckBox chkSelectedTopping = sender as CheckBox;) chkSelectedTopping will be null if sender couldn't be converted, and no exception is thrown.
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are GMT - 5 Hours

 

Advertisement