{"id":4029,"date":"2022-01-03T05:27:53","date_gmt":"2022-01-03T05:27:53","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=4029"},"modified":"2022-01-03T05:27:55","modified_gmt":"2022-01-03T05:27:55","slug":"7c-wxwidgets-wxfontdialog","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2022\/01\/03\/7c-wxwidgets-wxfontdialog\/","title":{"rendered":"7c.wxWidgets &#8211; wxFontDialog"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>In the sample code below, we display a line of text and then use the wxFontDialog to change the font . We have added a certain size to the wxStaticText so that if the font size is very big , it can still be seen.<\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dialog-font.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\t#include &lt;wx\/wx.h&gt;\n#endif\n\n\nclass DialogFont: public wxFrame {\n\tpublic:\n\t\tDialogFont(const wxString&amp; title);\n\t\tvoid OnClick(wxCommandEvent &amp;event);\n\tprivate:\n\t\twxStaticText *mLabel;\n};\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">dialog-font.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;wx\/fontdlg.h&gt;\n#include &quot;dialog-font.h&quot;\n\nDialogFont::DialogFont(const wxString&amp; title):\n\twxFrame(NULL, -1, title, wxDefaultPosition, wxSize(500,400)) {\n\n\twxPanel *panelMain = new wxPanel(this, -1);\n\twxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);\n\tpanelMain-&gt;SetSizer(vbox);\n\t\n\twxButton *btn1 = new wxButton(panelMain, -1, wxT(&quot;Change Font&quot;));\n\tmLabel = new wxStaticText(panelMain, -1, wxT(&quot;This is a single line of text&quot;), wxPoint(-1,-1), wxSize(200,100));\n\n\tvbox-&gt;Add(btn1, 0, wxALL | wxCENTER,5);\n\tvbox-&gt;Add(mLabel, 1, wxALL | wxEXPAND | wxCENTER, 5);\n\t\n\tbtn1-&gt;Bind(wxEVT_BUTTON, &amp;DialogFont::OnClick, this);\n\tCenter();\n}\n\n\t\nvoid DialogFont::OnClick(wxCommandEvent &amp;event) {\n\n\twxFontDialog *dlg = new wxFontDialog(this);\n\tint retVal = dlg-&gt;ShowModal();\t\n\tif (retVal == wxID_OK) {\n\t\tmLabel-&gt;SetFont(dlg-&gt;GetFontData().GetChosenFont());\t\n\t}\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\t#include &lt;wx\/wx.h&gt;\n#endif\n\nclass Main: public wxApp {\n\n\tpublic:\n\t\tvirtual bool OnInit();\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;dialog-font.h&quot;\n\nIMPLEMENT_APP(Main)\n\nbool Main::OnInit() {\n\tDialogFont *app = new DialogFont(wxT(&quot;Font Dialog &quot;));\n\tapp-&gt;Show(true);\n\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=\"400\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-56-19.png\" alt=\"\" class=\"wp-image-4033\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-56-19.png 500w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-56-19-300x240.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=\"500\" height=\"400\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-56-40.png\" alt=\"\" class=\"wp-image-4034\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-56-40.png 500w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-03-10-56-40-300x240.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW In the sample code below, we display a line of text and then use the wxFontDialog to change the font . We have added <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2022\/01\/03\/7c-wxwidgets-wxfontdialog\/\" title=\"7c.wxWidgets &#8211; wxFontDialog\">[&#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-4029","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\/4029","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=4029"}],"version-history":[{"count":4,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4029\/revisions"}],"predecessor-version":[{"id":4035,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4029\/revisions\/4035"}],"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=4029"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=4029"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=4029"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}