Results 1 to 5 of 5

Thread: [2.0] using 1 Button for 2 Functions[RESOLVED]

  1. #1

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Smile [2.0] using 1 Button for 2 Functions[RESOLVED]

    I need to get one Button to both Start and Stop...Now for some reason i cant remember this for the life of me..lol
    But this is what i have I think its correct but i cant remember

    VB Code:
    1. private void button1_Click(object sender, EventArgs e)
    2. if (button1.Capture == true)
    3. {
    4. toolStripStatusLabel2.Text = " Sending Message";
    5. timer1.Enabled = true
    6. }
    7. else
    8. {
    9. if(button1.Capture == false)
    10. toolStripStatusLabel2.Text = "";
    11. timer1.Enabled = false
    12. }
    13. }
    Am i correct?? and is their a shorter version of this..lol
    Last edited by Rattlerr; Jul 24th, 2006 at 03:31 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] using 1 Button for 2 Functions

    I'm not quite sure what the Capture property has to do with this. I would probably do it either of two ways. Using a regular Button:
    Code:
    // Toogle the timer state.
    this.timer1.Enabled = !this.timer1.Enabled;
    
    // Set the label text based on the timer state.
    this.toolStripStatusLabel2.Text = this.timer1.Enabled ? "Sending Message" : string.Empty;
    or else use a CheckBox with its Appearnce property set to Button. That way it looks exactly like a regular Button but with toggle functionality, so you'd handle its CheckChanged event:
    Code:
    this.timer1.Enabled = this.toggleButton1.Checked;
    this.toolStripStatusLabel2.Text = this.toggleButton1.Checked ? "Sending Message" : string.Empty;
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Smile Re: [2.0] using 1 Button for 2 Functions

    Thxs i prefer the first method ,dont really want a checkbox type...

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] using 1 Button for 2 Functions[RESOLVED]

    Have a look at the screenshot to see what I meant. Both the controls you see are CheckBoxes with their Appearance property set to Button. RadioButtons have similar functionality.
    Attached Images Attached Images  
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Re: [2.0] using 1 Button for 2 Functions[RESOLVED]

    yeah i see what you mean...I'm using Mouse Roll overs for different background colors,so i like the other way.. but that will be handy for some of the other buttons i have on my form..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width