XP Visual Styles on UserControl in IE

J

jwallison

(Framework 1.1)

I have an IE BandObject that is derived from : UserControl,
IObjectWithSite, IDeskBand, IDockingWindow, IOleWindow, IInputObject

This control uses DrawThemeParentBackground( this.Handle, hdc, ref rect)
to get the parent IE rebar control's gradient background to be drawn under
XP.

Everything was drawing "fine", up until the point that I added a ToolBar (or
a PictureBox, or...) to my bandObject that was docked Left . The Layout is
fine - Z-Order correct, etc. -this is only a painting problem related to
OnPaintBackground in this class, from all that I can see ;)

Now, everything has gone to hell - the background isn't being painted
correctly on EITHER a standard toolbar (docked Left) OR a ToolBar-derived
class docked Fill. It's CRAZY - even the DIRECTION that MouseOver occurs in
(right-to-left, the background paints fine, left-to-right, the background
paints each button black in what appears to be the size of the first item in
the BandObject - the ToolBar or PictureBox that is docked Left.

This seems like it should be fairly straightforward, but there seems to be
some kind of interaction between UxTheme and (docking?) I am mucking with
the DisplayRectangle of the BandObject (shrinking the width to allow for a
small button on the rigt side of the control (a LOT smaller than the area
that isn't painting the background correctly). Any pointers would be greatly
appreciated -



My OnPaintbackground() is implemented as follows:

protected override void OnPaintBackground(PaintEventArgs pevent) /*
XP Visual Style, only */
{
rect = new RECT(pevent.ClipRectangle);
try
{
IntPtr hdc = pevent.Graphics.GetHdc();
int ret = DigitalCollimation.Win32.DrawThemeParentBackground(
this.Handle, hdc, ref rect );
pevent.Graphics.ReleaseHdc( hdc);
}
catch (Exception ex)
{
Trace.WriteLine( ex.Message + "\r\nat: " + ex.StackTrace
,"OnPaintBackground()");
}
}

DrawThemeParentBackground() is defined as follows:

[DllImport( "uxtheme.dll")]
public static extern /* HRESULT */ int DrawThemeParentBackground(
IntPtr hwnd, IntPtr hdc, ref RECT prc );



RECT is defined as follows:

[StructLayout( LayoutKind.Sequential)]
public struct RECT
{
public Int32 Left;
public Int32 Top;
public Int32 Right;
public Int32 Bottom;

public int Width
{
get
{
return Right - Left;
}
}

public int Height
{
get
{
return Bottom - Top;
}
}

public RECT( int left, int top, int right, int bottom)
{
this.Left = left;
this.Top = top;
this.Right = right;
this.Bottom = bottom;
}

public RECT( Rectangle rc)
{
Left = rc.Left;
Top = rc.Top;
Right = rc.Left + rc.Width;
Bottom = rc.Top + rc.Height;
}

public static implicit operator RECT( Rectangle rc )
{
return new RECT( rc.Left, rc.Top, rc.Left + rc.Width, rc.Top +
rc.Height );
}

public static implicit operator Rectangle( RECT rc )
{
return new Rectangle( rc.Left, rc.Top, rc.Left + rc.Width, rc.Top +
rc.Height );
}

public override string ToString()
{
// TODO: change this to use String.Format?
return "{ " + Left + ", " + Top + ", " + Right + ", " + Bottom + " }";
}
}
 
Y

Ying-Shen Yu[MSFT]

Hi,

Does this problem also occur even if you show the user control in a winform
application?
Since the problem is a bit complex, it's hard to help without a repro
sample, can you sent me a simple repro sample? Then I can see what you are
doing exactly and see if I can find out a way to work around the problem.
Thanks!


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending.
 
J

jwallison

Got it.

Apparently, using Control.SetStyle( ....
ControlStyles.SupportsTransparentBackColor, true) isn't such a good thing,
in this case... funny thing is, it appears to "work" until more than one
Control-derived class instance is added to the BandObject (UserControl) in
question.

I think the following excerpt from the ControlStyles enumeration docs
explains why:

SupportsTransparentBackColor

If true, the control accepts a BackColor with an alpha component of less
than 255 to simulate transparency. Transparency will be simulated only if
the UserPaint bit is set to true ****and the parent control is derived from
Control****.

In this case, the "parent control" is IE's Rebar control, which is
definitely NOT derived from System.Windows.Forms.Control. So, no simulated
transparency (to a very large and ugly degree).

Thanks for your response -


--
Regards,

Jim Allison
(e-mail address removed)
(de-mung by removing '.1')




jwallison said:
(Framework 1.1)

I have an IE BandObject that is derived from : UserControl,
IObjectWithSite, IDeskBand, IDockingWindow, IOleWindow, IInputObject

This control uses DrawThemeParentBackground( this.Handle, hdc, ref rect)
to get the parent IE rebar control's gradient background to be drawn under
XP.

Everything was drawing "fine", up until the point that I added a ToolBar (or
a PictureBox, or...) to my bandObject that was docked Left . The Layout is
fine - Z-Order correct, etc. -this is only a painting problem related to
OnPaintBackground in this class, from all that I can see ;)

Now, everything has gone to hell - the background isn't being painted
correctly on EITHER a standard toolbar (docked Left) OR a ToolBar-derived
class docked Fill. It's CRAZY - even the DIRECTION that MouseOver occurs in
(right-to-left, the background paints fine, left-to-right, the background
paints each button black in what appears to be the size of the first item in
the BandObject - the ToolBar or PictureBox that is docked Left.

This seems like it should be fairly straightforward, but there seems to be
some kind of interaction between UxTheme and (docking?) I am mucking with
the DisplayRectangle of the BandObject (shrinking the width to allow for a
small button on the rigt side of the control (a LOT smaller than the area
that isn't painting the background correctly). Any pointers would be greatly
appreciated -



My OnPaintbackground() is implemented as follows:

protected override void OnPaintBackground(PaintEventArgs pevent) /*
XP Visual Style, only */
{
rect = new RECT(pevent.ClipRectangle);
try
{
IntPtr hdc = pevent.Graphics.GetHdc();
int ret = DigitalCollimation.Win32.DrawThemeParentBackground(
this.Handle, hdc, ref rect );
pevent.Graphics.ReleaseHdc( hdc);
}
catch (Exception ex)
{
Trace.WriteLine( ex.Message + "\r\nat: " + ex.StackTrace
,"OnPaintBackground()");
}
}

DrawThemeParentBackground() is defined as follows:

[DllImport( "uxtheme.dll")]
public static extern /* HRESULT */ int DrawThemeParentBackground(
IntPtr hwnd, IntPtr hdc, ref RECT prc );



RECT is defined as follows:

[StructLayout( LayoutKind.Sequential)]
public struct RECT
{
public Int32 Left;
public Int32 Top;
public Int32 Right;
public Int32 Bottom;

public int Width
{
get
{
return Right - Left;
}
}

public int Height
{
get
{
return Bottom - Top;
}
}

public RECT( int left, int top, int right, int bottom)
{
this.Left = left;
this.Top = top;
this.Right = right;
this.Bottom = bottom;
}

public RECT( Rectangle rc)
{
Left = rc.Left;
Top = rc.Top;
Right = rc.Left + rc.Width;
Bottom = rc.Top + rc.Height;
}

public static implicit operator RECT( Rectangle rc )
{
return new RECT( rc.Left, rc.Top, rc.Left + rc.Width, rc.Top +
rc.Height );
}

public static implicit operator Rectangle( RECT rc )
{
return new Rectangle( rc.Left, rc.Top, rc.Left + rc.Width, rc.Top +
rc.Height );
}

public override string ToString()
{
// TODO: change this to use String.Format?
return "{ " + Left + ", " + Top + ", " + Right + ", " + Bottom + " }";
}
}
 
Y

Ying-Shen Yu[MSFT]

Hi Jim,

It's really cool to write a IE Band in .NET (and also support theme!).
Just as the documentation said, transparency in .NET is simulated in the
Control class.
Now have you found a work around for this problem?
I'll monitor this thread for a few days, if you need help, please be free
to reply this thread.


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending.
 

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