Discussion:
C# .NET DeskBand Transparent Background (Deskbar, BandObject) Problem
(too old to reply)
t***@hotmail.com
2005-02-07 14:46:27 UTC
Permalink
Hi,

Firstly apologies for the cross posting, but I'm kind of desperate
here.

I'm trying to build a deskband using .net that will sit on the taskbar
as another toolbar.

I have used as a basis for my code, the code from the CodeProject.
http://www.codeproject.com/csharp/dotnetbandobjects.asp?df=100&forumid=3788&exp=0&fr=251

However, i can't get the background of the deskband to be transparent.
So when it's integrated into the taskbar special some of the XP themes
(with gradient shading) it looks awful.

Here's the code we are using:

namespace SampleBars
{
[Guid("AE07101B-46D4-4a98-AF68-0333EA26E113")]
[BandObject("Hello World Bar", BandObjectStyle.Horizontal |
BandObjectStyle.ExplorerToolbar | BandObjectStyle.TaskbarToolBar,
HelpText = "Shows bar that says hello.")]

public class HelloWorldBar : BandObject
{
private System.ComponentModel.Container components = null;

public HelloWorldBar()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}

#region Component Designer generated code
private void InitializeComponent()
{
this.SuspendLayout();
this.MaxSize = new System.Drawing.Size(500, 32);
this.MinSize = new System.Drawing.Size(150, 32);
this.Name = "HelloWorldBar";
this.Size = new System.Drawing.Size(384, 32);
this.Title = "DB Bar";
this.ResumeLayout(false);

}
#endregion

private void button1_Click(object sender, System.EventArgs e)
{
MessageBox.Show("About to search for " + this.textbox1.Text);
}
}


I have tried this firstly:

public HelloWorldBar()
{
InitializeComponent();
this.SetStyle (System.Windows.Forms.ControlStyles.UserPaint,
true);
this.SetStyle
(System.Windows.Forms.ControlStyles.SupportsTransparentBackColor,
true);
this.BackColor = System.Drawing.Color.Transparent;
}

This has no effect.

I've also tried overiding CreateParams and setting the exStyle to |=
0x00000000020, overriding paintBackground with an empty method and this
just hides whole bar when you add it to the taskbar.

Looking at microsofts win32 msdn section on deskbands it looks like you
can just set background mode to be transparent in the paint method.
But i don't know how i can do this in C#.

Can anyone help at all?

Thanks
Simon Tomlinson
Tim Robinson
2005-02-07 20:59:36 UTC
Permalink
***@hotmail.com wrote:
[...]
Post by t***@hotmail.com
Looking at microsofts win32 msdn section on deskbands it looks like you
can just set background mode to be transparent in the paint method.
But i don't know how i can do this in C#.
[...]

On systems where UXTHEME.DLL is available, call the Win32 function
DrawThemeParentBackground. Elsewhere, fill the background with
SystemColors.Control. There may be a .NET equivalent to
DrawThemeParentBackground but I don't know of anything off the top of my
head.
--
Tim Robinson (MVP, Windows SDK)
http://mobius.sourceforge.net/
Scavy
2005-02-09 00:21:21 UTC
Permalink
Excellent Tim, thanks for that. Works brilliantly. Presumably this
will only work on XP machines? But then i should just test for XP and
use this otherwise just use the desktop system color?

Thnx
Simon
Post by Tim Robinson
[...]
Post by t***@hotmail.com
Looking at microsofts win32 msdn section on deskbands it looks like you
can just set background mode to be transparent in the paint method.
But i don't know how i can do this in C#.
[...]
On systems where UXTHEME.DLL is available, call the Win32 function
DrawThemeParentBackground. Elsewhere, fill the background with
SystemColors.Control. There may be a .NET equivalent to
DrawThemeParentBackground but I don't know of anything off the top of my
head.
--
Tim Robinson (MVP, Windows SDK)
http://mobius.sourceforge.net/
Tim Robinson
2005-02-09 00:47:06 UTC
Permalink
Post by Scavy
Post by Tim Robinson
On systems where UXTHEME.DLL is available, call the Win32 function
DrawThemeParentBackground. Elsewhere, fill the background with
SystemColors.Control. There may be a .NET equivalent to
DrawThemeParentBackground but I don't know of anything off the top of
Excellent Tim, thanks for that. Works brilliantly. Presumably this
will only work on XP machines? But then i should just test for XP and
use this otherwise just use the desktop system color?
Exactly. But don't test for XP: test whether UXTHEME.DLL is available,
and whether it exports the DrawThemeParentBackground function. If not,
fall back to the Windows 2000 method.
--
Tim Robinson (MVP, Windows SDK)
http://mobius.sourceforge.net/
Ian Bevan
2005-02-07 22:49:15 UTC
Permalink
Hi

I have just been having the exact same problem, but in C++. What I have
done, rightly or wrongly, is this:

1. Create a window that is a child of the TaskBar, but make it invisible.
2. For each control you want to appear in your deskband, make it a child
of the *taskbar*, not the window created in 1.
3. Use the window created in 1 to get the size of the client area of
your deskband and reposition the controls you created in 2 accordingly.
Note that this means doing a little jiggery pokery with co-ordinates for
both the taskbar window and the hidden window, as the controls are
children of the taskbar, not the hidden window (and so need client
co-ordinates from the taskbar client area, not the hidden window client
area).

Here's my C++ sample code, which is the OnSize method of my hidden
deskband window, showing repositioning of a child edit control:
void CFJSearchDeskBand::OnSize(UINT nType, int cx, int cy)
{
__super::OnSize(nType, cx, cy);
CRect rcTaskBar;
GetParent()->GetWindowRect(rcTaskBar);
CRect rcHiddenParent;
GetWindowRect(rcHiddenParent);
CRect rcHiddenParentClient(rcHiddenParent.left - rcTaskBar.left,
rcHiddenParent.top - rcTaskBar.top,
rcHiddenParent.left - rcTaskBar.left + rcHiddenParent.Width(),
rcHiddenParent.top - rcTaskBar.top + rcHiddenParent.Height());

const int EditHeight = 20; // height in pixels of the edit control
const int Border = 3; // a little border either side of the edit

CPoint EditTL(rcHiddenParentClient.left + 5,
rcHiddenParentClient.Height()/2 - EditHeight / 2 );

CRect EditPos(EditTL, CSize(rcHiddenParentClient.Width() - Border * 2,

EditHeight));
m_wndEdit.MoveWindow(EditPos);
}

Hope this helps.
Post by t***@hotmail.com
Hi,
Firstly apologies for the cross posting, but I'm kind of desperate
here.
I'm trying to build a deskband using .net that will sit on the taskbar
as another toolbar.
I have used as a basis for my code, the code from the CodeProject.
http://www.codeproject.com/csharp/dotnetbandobjects.asp?df=100&forumid=3788&exp=0&fr=251
However, i can't get the background of the deskband to be transparent.
So when it's integrated into the taskbar special some of the XP themes
(with gradient shading) it looks awful.
namespace SampleBars
{
[Guid("AE07101B-46D4-4a98-AF68-0333EA26E113")]
[BandObject("Hello World Bar", BandObjectStyle.Horizontal |
BandObjectStyle.ExplorerToolbar | BandObjectStyle.TaskbarToolBar,
HelpText = "Shows bar that says hello.")]
public class HelloWorldBar : BandObject
{
private System.ComponentModel.Container components = null;
public HelloWorldBar()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
#region Component Designer generated code
private void InitializeComponent()
{
this.SuspendLayout();
this.MaxSize = new System.Drawing.Size(500, 32);
this.MinSize = new System.Drawing.Size(150, 32);
this.Name = "HelloWorldBar";
this.Size = new System.Drawing.Size(384, 32);
this.Title = "DB Bar";
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
MessageBox.Show("About to search for " + this.textbox1.Text);
}
}
public HelloWorldBar()
{
InitializeComponent();
this.SetStyle (System.Windows.Forms.ControlStyles.UserPaint,
true);
this.SetStyle
(System.Windows.Forms.ControlStyles.SupportsTransparentBackColor,
true);
this.BackColor = System.Drawing.Color.Transparent;
}
This has no effect.
I've also tried overiding CreateParams and setting the exStyle to |=
0x00000000020, overriding paintBackground with an empty method and this
just hides whole bar when you add it to the taskbar.
Looking at microsofts win32 msdn section on deskbands it looks like you
can just set background mode to be transparent in the paint method.
But i don't know how i can do this in C#.
Can anyone help at all?
Thanks
Simon Tomlinson
Loading...