Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

WxWidgets lesson 10 rendering fonts

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Description

Disadvantages of DrawText: font size and font placement position need to be calculated manually, and font width and height can not be set at will, in the case of scalability, the poor effect is based on the above shortcomings, the introduction of DrawLabel function

Application

Void DrawLabel (const wxString& text, const wxRect& rect

Int alignment = wxALIGN_LEFT | wxALIGN_TOP

Int indexAccel =-1)

The first parameter is the text content of the label

The second parameter is the rectangular area where the label is located.

The third parameter is the alignment of the text, including center alignment, left alignment, and so on, as detailed in

WxAlignment

WxALIGN_CENTER_HORIZONTAL = 0x0100

WxALIGN_CENTRE_HORIZONTAL = wxALIGN_CENTER_HORIZONTAL

WxALIGN_LEFT = wxALIGN_NOT

WxALIGN_TOP = wxALIGN_NOT

WxALIGN_RIGHT = 0x0200

WxALIGN_BOTTOM = 0x0400

WxALIGN_CENTER_VERTICAL = 0x0800

WxALIGN_CENTRE_VERTICAL = wxALIGN_CENTER_VERTICAL

This function is very useful for rendering the title of the control in a custom control.

Example: the title of the control accounts for 30% of the height of the entire control, centered and aligned

WxBufferedPaintDC dc (this)

Int titleHeight = m_size.GetHeight () * 0.3

WxRect rect (0,0, m_size.GetWidth (), titleHeight)

Dc.DrawLabel (m_szTitle, rect, wxALIGN_CENTER_HORIZONTAL | wxALIGN_TOP)

Description 0B0 indicates that starting from the upper left corner of the control, the width of the control is the rectangular width of the label and the height of the high rectangle of 30%.

Example of adopting DrawText

WxFont titleFont (wxSize (0, titleHeight), wxFONTFAMILY_SCRIPT, wxNORMAL, wxFONTWEIGHT_LIGHT)

Dc.SetFont (titleFont)

Dc.DrawText (m_szTitle, 4,0)

Note that wxSize is mainly used to set the width and height of the font, in fact, you can only set the height of the font to automatically confirm the width of the font, but the effect is often poor, the following provides a method to set the font size, the same effect is poor

WxClientDC dc (this)

/ / define an object font of a wxFont class

/ / Constructor wxFont::wxFont (font size, font type (calligraphy, art), italics,)

WxFont font (30rec wxFONTFAMILY Roman, wxNORMAL,wxBOLD)

/ / use the member function SetFont of the DC class to set the font

Dc.SetFont (font)

/ / set the background transparent or impenetrable

Dc.SetBackgroundMode (wxSOLID)

/ / set foreground color

Dc.SetTextForeground (wxColor (0,255,127))

/ / set background color

Dc.SetTextBackground (wxColor (0,36,17))

/ / write, text wxString, location wxPoint

Dc.DrawText ("9", 100100)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report