PC Review


Reply
Thread Tools Rating: Thread Rating: 5 votes, 4.20 average.

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

 
 
Ehud
Guest
Posts: n/a
 
      29th Oct 2008
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
 
Reply With Quote
 
 
 
 
Jeff Johnson
Guest
Posts: n/a
 
      29th Oct 2008
"Ehud" <(E-Mail Removed)> wrote in message
news:810e7c85-75de-42ef-b98c-(E-Mail Removed)...

> 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?


 
Reply With Quote
 
 
 
 
Ehud
Guest
Posts: n/a
 
      29th Oct 2008
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);




On Oct 29, 4:30 pm, "Jeff Johnson" <i....@enough.spam> wrote:
> "Ehud" <ehu...@gmail.com> wrote in message
>
> news:810e7c85-75de-42ef-b98c-(E-Mail Removed)...
>
> > 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?


 
Reply With Quote
 
Ehud
Guest
Posts: n/a
 
      29th Oct 2008
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


On Oct 29, 6:19 pm, "Patrice" <http://www.chez.com/scribe/> wrote:
> In addition to Jeff, the .NET Version and the OS you are using could help....
>
> If .NET 1.1 under XP try :http://msdn.microsoft.com/en-us/library/aa289524(VS.71).aspx
>
> Else please elaborate a bit so that we are 100 % sure what is your current
> situation...
>
> --
> Patrice
>
> "Ehud" <ehu...@gmail.com> a écrit dans le message de groupe de discussion :
> 810e7c85-75de-42ef-b98c-14bb89d83...@h60g2000hsg.googlegroups.com...
>
>
>
> > 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- Hide quoted text -

>
> - Show quoted text -

 
Reply With Quote
 
Morten Wennevik [C# MVP]
Guest
Posts: n/a
 
      31st Oct 2008

"Ehud" wrote:

> 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...b;en-us;307208

--
Happy Coding!
Morten Wennevik [C# MVP]
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How does volt feel ? How does ampere feel ? Skybuck Flying DIY PC 7 3rd Jul 2011 02:47 PM
xp look and feel for winforms controls in non xp-based systems =?Utf-8?B?U3VkZWVwJydzIERhdGFHcmlkIFByb2JsZW0=?= Microsoft Dot NET Framework 3 10th Feb 2006 07:49 AM
Win XP look n Feel for Menus,Toolbars Abhishek Microsoft C# .NET 3 5th Jan 2005 11:54 AM
Re: Can't Install Delta Force, Delta Force 2 or Delta Force Land Warri Jimmy S. Windows XP Games 0 14th Aug 2004 05:51 AM
I feel seated in between two chairs and do feel unconfortable... =?Utf-8?B?UGF1bCwgQnJ1c3NlbHM=?= Windows XP Setup 2 9th Jan 2004 03:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:50 PM.