Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to link a radio button to a command button? (mfc c++)

how to link a radio button to a command button? (mfc c++)

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestion
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Neil Jigger
    wrote on last edited by
    #1

    good day, here is my problem on how to link the commandbutton to radio buttons (mfc) in c++: i inserted 3 radiobuttons inside a groupbox with a caption "Mode of payments"; radio1 with a caption "1. Cash (10% discount)"; radio2 with a caption "2. Two payments (5 % interest)"; radio3 with a caption "3. Three payments (10% interest); i also have two editboxes; editbox1 and editbox2. 1. with a static text "enter tuition fee:" value will be accepted in the first editbox. 2. with a static text "Your total tuition fee is:" will be displayed in the second editbox. and one command button with a caption "Compute" supposing i will select the second radio button which is "two payments (5% interest)" upon clicking the command button "compute" the result should be displayed in the second editbox under "your total tuition fee:" which is the computation on the value of the first editbox and on the second radiobutton and so on... if i will not use a commandbutton "compute" caption (to do the calculation) i can do the code and get the right result by calculating the value of the first editbox and on the radiobutton values, but when i will use commandbutton to do the calculation on the value of the first editbox to the radiobuttons that is now my problem since i cannot link the radiobuttons and the commandbutton... Please anybody help me in solving this problem...i need sample code as guide in solving this problem and on my future related projects... code experts please help me... thank again and thank you in advance... neil

    Richard Andrew x64R 1 Reply Last reply
    0
    • N Neil Jigger

      good day, here is my problem on how to link the commandbutton to radio buttons (mfc) in c++: i inserted 3 radiobuttons inside a groupbox with a caption "Mode of payments"; radio1 with a caption "1. Cash (10% discount)"; radio2 with a caption "2. Two payments (5 % interest)"; radio3 with a caption "3. Three payments (10% interest); i also have two editboxes; editbox1 and editbox2. 1. with a static text "enter tuition fee:" value will be accepted in the first editbox. 2. with a static text "Your total tuition fee is:" will be displayed in the second editbox. and one command button with a caption "Compute" supposing i will select the second radio button which is "two payments (5% interest)" upon clicking the command button "compute" the result should be displayed in the second editbox under "your total tuition fee:" which is the computation on the value of the first editbox and on the second radiobutton and so on... if i will not use a commandbutton "compute" caption (to do the calculation) i can do the code and get the right result by calculating the value of the first editbox and on the radiobutton values, but when i will use commandbutton to do the calculation on the value of the first editbox to the radiobuttons that is now my problem since i cannot link the radiobuttons and the commandbutton... Please anybody help me in solving this problem...i need sample code as guide in solving this problem and on my future related projects... code experts please help me... thank again and thank you in advance... neil

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      Could you please restate more clearly what it is you want to do? Do you want it to calculate the answer without having to click on the button?

      N 1 Reply Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        Could you please restate more clearly what it is you want to do? Do you want it to calculate the answer without having to click on the button?

        N Offline
        N Offline
        Neil Jigger
        wrote on last edited by
        #3

        i will select first on one of the radio buttons then by clicking on the command button which has a caption "compute" c++ will give an answer and it will be displayed in the second editbox.

        Richard Andrew x64R 1 Reply Last reply
        0
        • N Neil Jigger

          i will select first on one of the radio buttons then by clicking on the command button which has a caption "compute" c++ will give an answer and it will be displayed in the second editbox.

          Richard Andrew x64R Offline
          Richard Andrew x64R Offline
          Richard Andrew x64
          wrote on last edited by
          #4

          So you want it to give a different answer depending upon which radio button is chosen?

          N 1 Reply Last reply
          0
          • Richard Andrew x64R Richard Andrew x64

            So you want it to give a different answer depending upon which radio button is chosen?

            N Offline
            N Offline
            Neil Jigger
            wrote on last edited by
            #5

            yes sir if supposing i will select the first radio button which is "cash (10 % discount)" the calculated amount is the amount of the "enter tuition fee editbox1" * .90 since 10% will be deducted to the tuition fee. If radiobutton2 is selected "two payments (5% interest)" the calculated amount is the amount of the "enter tuition fee editbox1" + 5% interest. Please sir help me on this problem. neil

            Richard Andrew x64R 1 Reply Last reply
            0
            • N Neil Jigger

              yes sir if supposing i will select the first radio button which is "cash (10 % discount)" the calculated amount is the amount of the "enter tuition fee editbox1" * .90 since 10% will be deducted to the tuition fee. If radiobutton2 is selected "two payments (5% interest)" the calculated amount is the amount of the "enter tuition fee editbox1" + 5% interest. Please sir help me on this problem. neil

              Richard Andrew x64R Offline
              Richard Andrew x64R Offline
              Richard Andrew x64
              wrote on last edited by
              #6

              All you have to do is use the GetCheck() function:

              if ( radiobutton1.GetCheck() == BST_CHECKED )
              {
              // First radio button chosen
              }

              if ( radiobutton2.GetCheck() == BST_CHECKED )
              {
              // Second radio button chosen
              }

              N 2 Replies Last reply
              0
              • Richard Andrew x64R Richard Andrew x64

                All you have to do is use the GetCheck() function:

                if ( radiobutton1.GetCheck() == BST_CHECKED )
                {
                // First radio button chosen
                }

                if ( radiobutton2.GetCheck() == BST_CHECKED )
                {
                // Second radio button chosen
                }

                N Offline
                N Offline
                Neil Jigger
                wrote on last edited by
                #7

                i will try this one sir...thank you very much for the help neil

                1 Reply Last reply
                0
                • Richard Andrew x64R Richard Andrew x64

                  All you have to do is use the GetCheck() function:

                  if ( radiobutton1.GetCheck() == BST_CHECKED )
                  {
                  // First radio button chosen
                  }

                  if ( radiobutton2.GetCheck() == BST_CHECKED )
                  {
                  // Second radio button chosen
                  }

                  N Offline
                  N Offline
                  Neil Jigger
                  wrote on last edited by
                  #8

                  <big>thank you very much</big> chard your code solve my problem. I posted this problem because i dont have the sample code on how to connect the radiobutton to the command button. Spider and chandru never gave me the sample code to solve my problem. here is now my code in c++ void CTuition1Dlg::OnButton1() {      // TODO: Add your control notification handler code here      UpdateData();      if ( m_button1.GetCheck() == BST_CHECKED )      {              m_edit2 = m_edit1 * .9;           UpdateData(false);      }      if ( m_button2.GetCheck() == BST_CHECKED )      {           double x;              x = m_edit1 * .05;           m_edit2 = m_edit1 + x;           UpdateData(false);      }      if ( m_button3.GetCheck() == BST_CHECKED )      {              double x;           x = m_edit1 * .10;           m_edit2 = m_edit1 + x;           UpdateData(false);      }      UpdateData(false); } if its not for your code I cannot solve it...thank you very much do you have ym sir chard? i would like to ym you if i have a problem on programming and i wish that you will still help me. Once again thank you... neil

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups