How to force a Win 32 Common Controls look & feel for .NET controls

  • Thread starter Thread starter Ehud
  • Start date Start date
E

Ehud

Hi,

I'd like to force a .NET control to look exactly like its Win 32
Common Control counterpart.
Specifically, I'm interested in Check Box control. The location of the
box within the control and the way the text is drawn on the control in
different between Win 32 and .NET but I would like it to be exactly
the same.

Any idea?


Thanks,
Ehud
 
I'd like to force a .NET control to look exactly like its Win 32
Common Control counterpart.
Specifically, I'm interested in Check Box control. The location of the
box within the control and the way the text is drawn on the control in
different between Win 32 and .NET but I would like it to be exactly
the same.

You'll have to be a little more specific. .NET does not control the looks of
controls. It doesn't draw anything itself, except maybe toolstrips. Most
..NET controls are just wrappers over the Win32 controls, and it's the
low-level (Win32) control that handles its own drawing. The main cause of
differently-appearing controls is themes.

Can you post some sample .NET code that will create a text box that displays
differently than a check box in some built-in OS dialog?
 
Hi Jeff,

I created a sample for each platform.
In .NET: a checkbox where CheckAlign is TopLeft and TextAlign is
TopLeft.
In Win32: I used the window styles BS_TOP | BS_LEFT.

When I execute the .NET code the check appears at the top + left side
of the check box control.
When I execute the Win32 code the check appears at the left side but
vertically centered to the text (not to the control).
In both cases the text is drawn fine except that in .NET it is
trimmed.
I couldn't find any value for CheckAlign that will place the check at
the same position as in Win32.


Ehud


C# Code (automatically generated by the forms designer)
=========================================
this.checkBox1.BackColor =
System.Drawing.SystemColors.Control;
this.checkBox1.CheckAlign =
System.Drawing.ContentAlignment.TopLeft;
this.checkBox1.Font = new System.Drawing.Font("Microsoft Sans
Serif", 48F);
this.checkBox1.Location = new System.Drawing.Point(0, 0);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(231, 134);
this.checkBox1.TabIndex = 0;
this.checkBox1.Text = "checkBox1";
this.checkBox1.TextAlign =
System.Drawing.ContentAlignment.TopLeft;
this.checkBox1.UseVisualStyleBackColor = false;

Win32 Code
=========================================
HWND hCheckbox = CreateWindow(WC_BUTTONW, L"checkBox1",
WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | BS_AUTOCHECKBOX |
BS_TOP | BS_LEFT,
0, 0, 231, 134, hWnd, NULL, hInstance, NULL);

LOGFONT lf;
ZeroMemory(&lf, sizeof(lf));
wcscpy_s(lf.lfFaceName, _countof(lf.lfFaceName), L"Microsoft Sans
Serif");
lf.lfHeight = 72;
lf.lfCharSet = DEFAULT_CHARSET;
HFONT hFont = CreateFontIndirect(&lf);

SendMessage(hCheckbox, WM_SETFONT, (WPARAM)hFont, (LPARAM)0);
 
Thank you Patrice.

The MSDN link is indeed helpful. The check is located at the same
position within the control as in Win32.
The problem is that if the text is long then in Win32 it is trimmed
while in .NET the text is drawn as multiline text.
I'd like .NET to draw the text in a single line and trim it as needed
just like Win32 does with check box control.

Ehud
 
Ehud said:
Hi,

I'd like to force a .NET control to look exactly like its Win 32
Common Control counterpart.
Specifically, I'm interested in Check Box control. The location of the
box within the control and the way the text is drawn on the control in
different between Win 32 and .NET but I would like it to be exactly
the same.

Any idea?


Thanks,
Ehud

Hi Ehud,

Are you thinking about the GDI vs GDI+ problem? Win32 uses GDI which is
resolution dependent but more "exact" display of text in a given resolution.
GDI+ is resolution independent and looks the same no matter what device or
resolution you use, including when printing.

http://support.microsoft.com/default.aspx?scid=kb;en-us;307208
 
Back
Top