CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2010
    Posts
    9

    Problems with radio button

    hi guys,

    i have a set of codes under a radio button "OnBnClickedRadio()".
    it will process some action on a image if it is check .
    The problem im facing is when the radio button is check, i would like to process the codes only once because if i continue clicking on the radio button, it will still process those codes to the image.

    is there a function to set when the radio button is being check, it will only process the codes 1 time? i cant seem to find any help here.

    advance thanks to any help!

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Problems with radio button

    Implement a boolean variable (declare it as a class member) and assign it the initial state of your radio button (as unchecked).
    Then in your OnBnClickedRadio() message handler check the previous state of the button before doing your process. Something like this:
    Code:
    // header file
    protected:
        BOOL m_bChecked;
    ....
    //  .cpp file
    // ctor
    CMyClass::CMyClass()
    {
         m_bChecked = FALSE;
    }
    ....
    CMyClass::OnBnClickedRadio()
    {
         if( !m_bChecked )
         {
              // do something
         }
         m_bChecked = TRUE;
    }
    Note that you also must change m_bChecked to FALSE every time this button is unchecked (when some other radio button in the same group is checked)
    Victor Nijegorodov

  3. #3
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Problems with radio button

    I would do it differently. Add a integer variable to your class that will remember the index of the selected radio button. Then in your onclick handler, you see if the previously selected radio button is different from this radio button. When it's different, do your action and update the member variable to reflect the new selected radiobutton.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  4. #4
    Join Date
    Jan 2010
    Posts
    9

    Re: Problems with radio button

    thanks guyS!!!

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

Featured