CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2009
    Posts
    3

    Unhappy How to set an event handler for a lower class radiobutton ? (moved from VC++ forum)

    **Note : I followed people suggestion to move the question from Visual C++ & C++ Programming > Visual C++ Programming to here.

    I create a user control group sub-class. There are two radiobuttons. I need to create event handlers for them.I create event handlers in the sub class and let the event handler to change a constant in the subclass. I will use a function to check the sub class constant in the upper class. Note I have commented out two lines (they are the event handler creation) because they are wrong because they create errors please help.

    I uploaded the sub-class code. Please help
    Attached Files Attached Files

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: How to set an event handler for a lower class radiobutton ? (moved from VC++ foru

    So, after having a look at your code, you seem to want to attach an event handler that is a member function of temp_groupbox to the radio buttons hosted by the temp_groupbox instance.

    Your attempt didn't work for two reasons: (1) Your syntax for the event handler delegate construction is wrong. But much more important: (2) The two event handlers you want to attach aren't defined at all, so that would never have worked at all anyway!

    For testing I attached a single event handler to both radio buttons that instead of changing a constant (which would, by the nature of constants, be impossible anyway ) sets the temp_groupbox::Text property, i.e. the group box' caption, equal to the Name property of the button that got checked.

    Here is, exemplarily, the statement to attach the event handler to the first button:

    Code:
              radioButton1->CheckedChanged += gcnew System::EventHandler(this, &temp_groupbox::radioButton_CheckedChanged);
    And here's the event handler attached to both buttons, which is a member function of temp_groupbox:

    Code:
            void radioButton_CheckedChanged(Object ^sender, EventArgs ^e)
            {
              RadioButton ^rbSender = safe_cast<RadioButton ^>(sender);
              if (rbSender->Checked)  // Don't act on a button getting _unchecked_
                Text = rbSender->Name;
            }
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    Sep 2009
    Posts
    3

    Re: How to set an event handler for a lower class radiobutton ? (moved from VC++ foru

    Thanks! My program works now

Tags for this Thread

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