Given the string below:
string s = "hello\n" + "world" + "align me";
Button1.Text = s;
No matter what i try (with either the OpenNetCF ButtonEx control or the
standard one) i cannot get each line to center on the button.
Any ideas anyone?
Try it in windows forms (c#) and it works fine. I've tried all the text
alignment options.
[System.Runtime.InteropServices.DllImport("coredll")]
private static extern IntPtr GetCapture();
[System.Runtime.InteropServices.DllImport("coredll")]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[System.Runtime.InteropServices.DllImport("coredll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int
dwNewLong);
private const int GWL_STYLE = -16;
private const int BS_CENTER = 0x00000300;
private const int BS_VCENTER = 0x00000C00;
private const int BS_MULTILINE = 0x00002000;
private void SetButtonStyle(Button ctrl)
{
IntPtr hWnd;
int style;
ctrl.Capture = true;
hWnd = GetCapture();
ctrl.Capture = false;
style = GetWindowLong(hWnd, GWL_STYLE);
SetWindowLong(hWnd, GWL_STYLE, (style | BS_CENTER | BS_VCENTER |
BS_MULTILINE));
ctrl.Refresh();
}
...
SetButtonStyle(this.button1);
In fact, you shouldn't need the (BS_CENTER | BS_VCENTER) styles as they
should already be present for a normal button. But I've included them just
to be explicit.
--
Tim Wilson
.Net Compact Framework MVP
"Rob S" <Ro...@discussions.microsoft.com> wrote in message
news:5F250FD1-2DD1-4AF9...@microsoft.com...
Peter
--
Peter Foot
Windows Embedded MVP
http://www.inthehand.com | http://blog.opennetcf.org/pfoot/
"Rob S" <Ro...@discussions.microsoft.com> wrote in message
news:5F250FD1-2DD1-4AF9...@microsoft.com...
That's a great workaround - hadn't thought of that! Unfortunately the same
technique is still required to support multi-line text in .NETCF 2.0 beta,
however you can skip the GetCapture call since the Controls in v2.0 expose
their Handle properties.
Peter
--
Peter Foot
Windows Embedded MVP
http://www.inthehand.com | http://blog.opennetcf.org/pfoot/
"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message
news:%233BgPps...@TK2MSFTNGP10.phx.gbl...
--
Tim Wilson
.Net Compact Framework MVP
"Peter Foot [MVP]" <feed...@nospam-inthehand.com> wrote in message
news:%23PFl6Uu...@TK2MSFTNGP10.phx.gbl...
"Tim Wilson" wrote:
> I'm actually redoing the ButtonEx control right now and I have put this on
> the list of things to consider. At this point, it looks like all the
> calculations will need to be done manually since ButtonEx is entirely custom
> drawn. I'm not sure if this is going to make its way in but this is one area
> where ButtonEx does not do as good a job as Button.
>
> --
> Tim Wilson
> ..Net Compact Framework MVP