How to set wxTextCtrl text centered vertically?
How to set wxTextCtrl text centered vertically?
The wxTextCtrl document have not the method.
ps: Single-line
ps: Single-line
Re: How to set wxTextCtrl text centered vertically?
why?doublemax wrote:Not supported.
Re: How to set wxTextCtrl text centered vertically?
No idea. Most likely reasons are:
a) The native controls don't support it
b) It wasn't implemented because nobody ever needed it
a) The native controls don't support it
b) It wasn't implemented because nobody ever needed it
Use the source, Luke!
Re: How to set wxTextCtrl text centered vertically?
Oh, i just need it.I only makt it narrow.doublemax wrote:No idea. Most likely reasons are:
a) The native controls don't support it
b) It wasn't implemented because nobody ever needed it
- eranon
- Can't get richer than this
- Posts: 867
- Joined: Sun May 13, 2012 11:42 pm
- Location: France
- Contact:
Re: How to set wxTextCtrl text centered vertically?
Not sure to understand your problem, freepro (maybe a screenshot would improve perception), but maybe this top vertical alignment just happens when you use wxNO_BORDER or wxSTATIC_BORDER (seen in several threads like this one http://forums.wxwidgets.org/viewtopic.p ... 80&p=31067 and this one http://forums.wxwidgets.org/viewtopic.p ... 3&p=101541).
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
Re: How to set wxTextCtrl text centered vertically?
Yes, my problem is second. but not solution!eranon wrote:Not sure to understand your problem, freepro (maybe a screenshot would improve perception), but maybe this top vertical alignment just happens when you use wxNO_BORDER or wxSTATIC_BORDER (seen in several threads like this one http://forums.wxwidgets.org/viewtopic.p ... 80&p=31067 and this one http://forums.wxwidgets.org/viewtopic.p ... 3&p=101541).
Re: How to set wxTextCtrl text centered vertically?
I see two solutions:
a) Add a vertical margin to the wxTextCtrl. This does not work for Windows. It does for Gtk+ Also, you must choose the margin depending on the font size.
b) If you don't have borders, you can set the height for the wxTextCtrl same as font pitch (not the font size).
I would test any solution with both upper/lower case letters.
a) Add a vertical margin to the wxTextCtrl. This does not work for Windows. It does for Gtk+ Also, you must choose the margin depending on the font size.
b) If you don't have borders, you can set the height for the wxTextCtrl same as font pitch (not the font size).
I would test any solution with both upper/lower case letters.
Re: How to set wxTextCtrl text centered vertically?
Thank you, I to try!Manolo wrote:I see two solutions:
a) Add a vertical margin to the wxTextCtrl. This does not work for Windows. It does for Gtk+ Also, you must choose the margin depending on the font size.
b) If you don't have borders, you can set the height for the wxTextCtrl same as font pitch (not the font size).
I would test any solution with both upper/lower case letters.
Re: How to set wxTextCtrl text centered vertically?
Oh, no solve!freepro wrote:Thank you, I to try!Manolo wrote:I see two solutions:
a) Add a vertical margin to the wxTextCtrl. This does not work for Windows. It does for Gtk+ Also, you must choose the margin depending on the font size.
b) If you don't have borders, you can set the height for the wxTextCtrl same as font pitch (not the font size).
I would test any solution with both upper/lower case letters.
Re: How to set wxTextCtrl text centered vertically?
This is possible on Windows by modifying the non-client area of the control.
To do that, subclasswxTextCtrl and override MSWWindowProc.
There are a couple of member variables and that should be obvious enough.
Based upon code found here https://stackoverflow.com/questions/867 ... n-edit-box
To do that, subclasswxTextCtrl and override MSWWindowProc.
Code: Select all
WXLRESULT
TextEdit::MSWWindowProc(WXUINT msg, WXWPARAM wParam, WXLPARAM lParam)
{
LRESULT r = super::MSWWindowProc(msg, wParam, lParam);
if (valign_ != 0) {
// TODO: on non-windows platforms, consider using SetMargins
// to acheive vertical alignment.
if (msg == WM_SIZE) {
// Ensure we get a WM_NCCALCSIZE message
SetWindowPos((HWND)GetHWND(), NULL, 0, 0, 0, 0,
SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_FRAMECHANGED);
}
else if (msg == WM_NCCALCSIZE) {
// We already called the base wndproc so the ncrect will
// take into account any themed border etc.
auto* lpncsp = (NCCALCSIZE_PARAMS*)lParam;
auto& ncrect = lpncsp->rgrc[0];
auto outer_rect = GetRect();
wxRect client = wxRectFromRECT(ncrect);
nc_fill_rect_ = client;
nc_fill_rect_.x -= outer_rect.x;
nc_fill_rect_.y -= outer_rect.y;
auto char_height = wxWindowDC(this).GetCharHeight();
int offset = 0;
if (valign_ == wxALIGN_CENTER_VERTICAL) {
wxRect rect = wxSize(1, char_height);
rect = rect.CenterIn(client, wxVERTICAL);
offset = rect.y - client.y;
}
else {
offset = client.GetBottom() - char_height;
}
nc_fill_rect_.height = offset;
ncrect.top += offset;
}
else if (msg == WM_NCPAINT) {
// Fill missing area
wxWindowDC dc(this);
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(GetBackgroundColour());
dc.DrawRectangle(nc_fill_rect_);
}
}
return r;
}
Code: Select all
int valign_
Code: Select all
wxRect nc_fill_rect_
Based upon code found here https://stackoverflow.com/questions/867 ... n-edit-box