{"id":4049,"date":"2022-01-06T08:53:25","date_gmt":"2022-01-06T08:53:25","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=4049"},"modified":"2022-01-06T08:53:26","modified_gmt":"2022-01-06T08:53:26","slug":"8a-wxwidgets-wxcheckbox","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2022\/01\/06\/8a-wxwidgets-wxcheckbox\/","title":{"rendered":"8a.wxWidgets &#8211; wxCheckBox"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>A wxCheckBox acts as a toggle control &#8211; either it is checked or not checked. We can set a 3-state checkbox as well, but that is non-standard and not supported in all platforms. By default the label will appear to the right of the checkbox, but this can be changed also.<\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">checkbox.h<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;wx\/wxprec.h&gt;\n#ifndef WX_PRECOMP\n    #include &lt;wx\/wx.h&gt;\n#endif\n\nclass Checkbox: public wxFrame {\n\n    public:\n      Checkbox(const wxString &amp;title);\n      void toggle1(wxCommandEvent &amp;event);\n      void toggle2(wxCommandEvent &amp;event);\n\n    private:\n      wxCheckBox *mCk1, *mCk2;\n\n};\n\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">checkbox.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &quot;checkbox.h&quot;\n\n\nCheckbox::Checkbox(const wxString &amp;title):\n\n    wxFrame(NULL, -1, title, wxDefaultPosition, wxSize(500,200)) {\n \n    wxPanel *panel = new wxPanel(this, -1);    \n    wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);\n    panel-&gt;SetSizer(vbox);\n\n    mCk1 = new wxCheckBox(panel, -1, wxT(&quot;This is a simple checkbox&quot;));\n    mCk1-&gt;Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, &amp;Checkbox::toggle1, this);\n    \n    mCk2 = new wxCheckBox(panel, -1, wxT(&quot;Label to the left&quot;), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);\n    mCk2-&gt;Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, &amp;Checkbox::toggle2, this);\n    \n    vbox-&gt;Add(mCk1, 1, wxEXPAND);\n    vbox-&gt;Add(mCk2, 1, wxEXPAND);\n\n\n    Center();\n\n}\n\nvoid Checkbox::toggle1(wxCommandEvent &amp;event) {\n  if (mCk1-&gt;GetValue())\n\t  wxMessageBox(wxT(&quot;checked&quot;));\n  else\n\t  wxMessageBox(wxT(&quot;not checked&quot;));\n\n}\n\nvoid Checkbox::toggle2(wxCommandEvent &amp;event) {\n  if (mCk2-&gt;GetValue())\n\t  wxMessageBox(wxT(&quot;checked&quot;));\n  else\n\t  wxMessageBox(wxT(&quot;not checked&quot;));\n\n}\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">main.h<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;wx\/wxprec.h&gt;\n#ifndef WX_PRECOMP\n    #include &lt;wx\/wx.h&gt;\n#endif\n\nclass Main: public wxApp {\n\n\tpublic:\n\t        virtual bool OnInit();\n};\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">main.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &quot;main.h&quot;\n#include &quot;checkbox.h&quot;\n \nIMPLEMENT_APP(Main)\n\nbool Main::OnInit() {\n\n    Checkbox *app = new Checkbox(wxT(&quot;Checkbox&quot;));\n    app-&gt;Show(true);\n}\n\n<\/pre><\/div>\n\n\n<p>The output is shown below<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"500\" height=\"200\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-06-14-21-37.png\" alt=\"\" class=\"wp-image-4051\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-06-14-21-37.png 500w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-06-14-21-37-300x120.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"165\" height=\"166\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-06-14-21-56.png\" alt=\"\" class=\"wp-image-4052\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-06-14-21-56.png 165w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-06-14-21-56-144x144.png 144w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-06-14-21-56-150x150.png 150w\" sizes=\"auto, (max-width: 165px) 100vw, 165px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW A wxCheckBox acts as a toggle control &#8211; either it is checked or not checked. We can set a 3-state checkbox as well, but <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2022\/01\/06\/8a-wxwidgets-wxcheckbox\/\" title=\"8a.wxWidgets &#8211; wxCheckBox\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":3595,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302,365],"tags":[],"class_list":["post-4049","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cc","category-wxwidgets"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4049","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/comments?post=4049"}],"version-history":[{"count":3,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4049\/revisions"}],"predecessor-version":[{"id":4054,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4049\/revisions\/4054"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media\/3595"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=4049"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=4049"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=4049"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}