Thanks for the pointer Jeff.
DC.GetTextExtent and DC.GetCharWidth will do the trick (later is the average
width).
Peter
···
-----Original Message-----
From: Jeff Shannon [mailto:jeff@ccvcorp.com]
Sent: Thursday, July 17, 2003 9:24 AM
To: wxPython-users@lists.wxwindows.org
Subject: Re: [wxPython-users] Establishing the length of a wx.TextCtrl
Peter Milliken wrote:
Is there any way to specify the width of a control in multiples of
character
width? Failing this, what would be the mechanism to calculate the width in
pixels given a string length and the current font?
The problem here is that most fonts are proportional, thus the width of
a 12-character string could be significantly different depending on just
what characters are in that string. Ones are much narrower than, say,
zeros, so 11-11-2001 requires less space than 30-08-2000. You could
probably construct a worst-case string, say MM/MMM/MMMM (Ms are usually
the widest character in a given font), and measure the width of that. I
believe that the measurement is done by wxDC.GetTextExtent(), which
should return a size (in pixels) for a supplied string in the current
font, as appropriate for the given DC. It may also be possible to get
an average character width for the current font -- my memory is hazy
(and I don't have the time to look anything up right now), but check for
a wxDC.GetSystemMetrics(). I *think* it's part of wxDC, and I *think*
that that's where you'd find this information, but it might be a
property of the font object instead of system metrics...
Jeff Shannon
Technician/Programmer
Credit International
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org
Warning: Copyright ResMed. Where the contents of this email and/or attachment includes materials prepared by ResMed, the use of those materials is subject exclusively to the conditions of engagement between ResMed and the intended recipient.
This communication is confidential and may contain legally privileged information. By the use of email over the Internet or other communication systems, ResMed is not waiving either confidentiality of, or legal privilege in,the content of the email and of any attachments.
If the recipient of this message is not the intended addressee, please call ResMed immediately on +61 2 9886 5000 Sydney, Australia.