Ugly groupbox caption font after .NET 1.1 SP1 upgrade

H

Herfried K. Wagner [MVP]

* "Mick Doherty said:
You obviously like to read, unlike me.

I never read a book about .NET, but I read the documentation. Sometimes
reading is necessary... though I avoid reading because it's
time-consuming.
I would still like to see a completely new set of controls to replace the
existing wrapped common controls, but then I guess that's what third party
control suites are for. If off the shelf controls worked as expected then I
would probably be bored with programming anyway, since I spend most of my
time playing with broken controls.

:)

That's what we are doing here in the group day by day: Spending our
time discussing possible bugs and issues, and finding fixes and
workarounds. I would miss that too. But I agree that a completely new
set of controls that is not a wrapper around the existing common
controls would be great.
 
C

Corey McKinnon

Dennis Sjogren said:
Hi!

I have this medium sized solution with a couple of projects and stuff.
The generated application has an <appname>.exe.manifest file to enable
XP themes. In the main window of the application I have several group
boxes, and even some group boxes within other group boxes.
FlatStyle=System on these group boxes has always worked just fine.
Round corners on the borders and blue caption text (standard
Luna/Silver theme).

Just now, I installed .NET Framework 1.1 SP1 and all the group boxes
that were inside other group boxes has these large ugly fonts in the
caption which doesn't even fit the designated space. The group boxes
that are placed directly on the form works just fine. It's only the
ones inside other group boxes.

I've verified this on several computers. pre-SP1 works, post-SP1
doesn't. I've also created a blank project with a single form. One
group box within another group box. Same result.

Visual Studio.NET 2003 7.1.3088 (Visual Basic.NET 2003)
Windows XP Professional SP2 English
.NET Framework 1.1.4322 SP1

Has anyone else encountered this? Any recommendations on how to solve
it?

Best regards,

Dennis "Dempa" Sjogren
Dalarna University, Sweden

We've also seen it here. One thing we tried was changing the
FlatStyle property from System to Standard. This fixes the problem,
but it disables the XP styling of the groupbox.

Corey
 
R

Rich Tomanio

Heres how to fix it:

Workaround 1:
Currently a workaround here is that we may put the nested child
GroupBoxes into a Panel. Since the Panel is invisible, this can have the
same visual effect.

Workaround 2:
Derive from the GroupBox class and override its WndProc function to
process the ¡°WM_PRINTCLIENT¡± message correctly:

//Please add the following using statement:
using System.Runtime.InteropServices;

public class FixedGroupBox : GroupBox
{
[DllImport("User32.dll", ExactSpelling = true, CharSet =
CharSet.Auto)]
public static extern bool GetClientRect(HandleRef hWnd, [In,
Out] ref RECT
rect);
private const int WM_PRINTCLIENT = 0x0318;
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
public RECT(int left, int top, int right, int bottom)
{
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
public RECT(System.Drawing.Rectangle r)
{
this.left = r.Left;
this.top = r.Top;
this.right = r.Right;
this.bottom = r.Bottom;
}
public static RECT FromXYWH(int x, int y, int width, int
height)
{
return new RECT(x, y, x + width, y + height);
}
public System.Drawing.Size Size
{
get
{
return new
System.Drawing.Size(this.right - this.left, this.bottom - this.top);
}
}
}
private void WmPrintClient(ref Message m)
{
RECT rect = new RECT();
GetClientRect(new HandleRef(this, Handle), ref rect);
Graphics graphics = Graphics.FromHdc(m.WParam);
Brush b = new SolidBrush(BackColor);
graphics.FillRectangle(b, rect.left, rect.top,
rect.right - rect.left, rect.bottom - rect.top);
graphics.Dispose();
b.Dispose();
m.Result = (IntPtr)1;
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_PRINTCLIENT:
WmPrintClient(ref m);
break;
default:
base.WndProc(ref m);
break;
}
}
}
 
M

Mick Doherty

Very nice, but I get exactly the same result with the following code:

\\\
using System.Windows.Forms;

public class FixedGroupBox : GroupBox
{
private const int WM_PRINTCLIENT = 0x0318;

protected override void WndProc(ref Message m)
{
if (m.Msg == WM_PRINTCLIENT)
m.Result = (IntPtr)1;
else
base.WndProc(ref m);
}

}
///

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html


Rich Tomanio said:
Heres how to fix it:

Workaround 1:
Currently a workaround here is that we may put the nested child
GroupBoxes into a Panel. Since the Panel is invisible, this can have the
same visual effect.

Workaround 2:
Derive from the GroupBox class and override its WndProc function to
process the ¡°WM_PRINTCLIENT¡± message correctly:

//Please add the following using statement:
using System.Runtime.InteropServices;

public class FixedGroupBox : GroupBox
{
[DllImport("User32.dll", ExactSpelling = true, CharSet =
CharSet.Auto)]
public static extern bool GetClientRect(HandleRef hWnd, [In,
Out] ref RECT
rect);
private const int WM_PRINTCLIENT = 0x0318;
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
public RECT(int left, int top, int right, int bottom)
{
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
public RECT(System.Drawing.Rectangle r)
{
this.left = r.Left;
this.top = r.Top;
this.right = r.Right;
this.bottom = r.Bottom;
}
public static RECT FromXYWH(int x, int y, int width, int
height)
{
return new RECT(x, y, x + width, y + height);
}
public System.Drawing.Size Size
{
get
{
return new
System.Drawing.Size(this.right - this.left, this.bottom - this.top);
}
}
}
private void WmPrintClient(ref Message m)
{
RECT rect = new RECT();
GetClientRect(new HandleRef(this, Handle), ref rect);
Graphics graphics = Graphics.FromHdc(m.WParam);
Brush b = new SolidBrush(BackColor);
graphics.FillRectangle(b, rect.left, rect.top,
rect.right - rect.left, rect.bottom - rect.top);
graphics.Dispose();
b.Dispose();
m.Result = (IntPtr)1;
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_PRINTCLIENT:
WmPrintClient(ref m);
break;
default:
base.WndProc(ref m);
break;
}
}
}
 

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