Trick for use of OnPaint for TextBox/ComboBox on Compact ?

M

Mark Johnson

From what I have found out today there are certain Controls where Windows
does the Painting and an override of OnPaint is not possible.
On Framework.Desktop this can be solved with the use of
"this.SetStyle(ControlStyles.UserPaint,true);",
but this is not supported on Compact.

Is there a workaround/trick to get OnPaint to work without reinventing the
Wheel (rewriting TextBox/ComboBox or whatever other Controls are effected)
?.

All I want to do is to repaint the Border so that it will look more like the
Desktop version (3D Effect).
With my own Controls this works well, but the others .. well ... look very
flat (and boring).

Mark Johnson, Berlin Germany
(e-mail address removed)
 
A

Alex Feinman [MVP]

The short answer is - no. Many messages are not routed to the managed level
at all being processed inside unmanaged part of the framework (netcfagl.dll)
 
T

Tim Wilson

You could play around with the style bits for the control to give the border
a 3D look.

using System.Runtime.InteropServices;

private const int GWL_EXSTYLE = -20;
private const int WS_EX_WINDOWEDGE = 0x00000100;
private const int WS_EX_CLIENTEDGE = 0x00000200;
private const int SWP_NOSIZE = 0x0001;
private const int SWP_NOMOVE = 0x0002;
private const int SWP_NOZORDER = 0x0004;
private const int SWP_NOACTIVATE = 0x0010;
private const int SWP_FRAMECHANGED = 0x0020;

[DllImport("coredll")]
private static extern IntPtr GetCapture();

[DllImport("coredll")]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("coredll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int
dwNewLong);

[DllImport("coredll")]
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter,
int X, int Y, int cx, int cy, int uFlags);

private void ChangeBorder(Control ctrl)
{
IntPtr hWnd;
int exStyle;
// Get handle.
ctrl.Capture = true;
hWnd = GetCapture();
ctrl.Capture = false;
// Change border.
exStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
SetWindowLong(hWnd, GWL_EXSTYLE, (exStyle | WS_EX_CLIENTEDGE));
// Refresh
SetWindowPos(hWnd, IntPtr.Zero, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE
| SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
}
 
K

Katie Schaeffer [MSFT]

Hi Mark,

Just to let you know, Textbox.BorderStyle is being considered for future
releases.

Tim's suggestion of using SetWindowLong is your best workaround - be
careful as changing some Textbox properties can cause the window to get
re-created (and your 3d border may not be re-applied).

-Katie

This posting is provided "AS IS" with no warranties, and confers no rights.

***.Net Compact Framework Info***
Faq:
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.a
spx
QuickStarts: http://samples.gotdotnet.com/quickstart/CompactFramework/
Samples:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/h
tml/CompactfxTechArt.asp

--------------------
| From: "Mark Johnson" <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| Subject: Trick for use of OnPaint for TextBox/ComboBox on Compact ?
| Date: Fri, 19 Mar 2004 17:00:28 +0100
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Lines: 19
| Message-ID: <[email protected]>
| Organization: Arcor
| NNTP-Posting-Date: 19 Mar 2004 17:00:36 MET
| NNTP-Posting-Host: 213.23.129.58
| X-Trace:
DXC=N=D:YX:0W\4gL1_>^S7Mi=Q5U85hF6f;4jW\KbG]kaM8liQbn6H@_E9]^hGU23DeG;KgWG2b
RR9h>7U1[1X5OoS51`b<7INc^j0
| X-Complaints-To: (e-mail address removed)
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGXS01.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP0
8.phx.gbl!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!
newsfeed.arcor-online.net!newsread.arcor-online.net!news.arcor.de!not-for-ma
il
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:49027
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| From what I have found out today there are certain Controls where Windows
| does the Painting and an override of OnPaint is not possible.
| On Framework.Desktop this can be solved with the use of
| "this.SetStyle(ControlStyles.UserPaint,true);",
| but this is not supported on Compact.
|
| Is there a workaround/trick to get OnPaint to work without reinventing the
| Wheel (rewriting TextBox/ComboBox or whatever other Controls are effected)
| ?.
|
| All I want to do is to repaint the Border so that it will look more like
the
| Desktop version (3D Effect).
| With my own Controls this works well, but the others .. well ... look
very
| flat (and boring).
|
| Mark Johnson, Berlin Germany
| (e-mail address removed)
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top