Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Transparent and Semi Transparent panels?

39 views
Skip to first unread message

mrabie

unread,
Jan 8, 2008, 7:00:53 AM1/8/08
to
Hi,

I was wondering if someone can help me in finding a way to create a
semi-transparent or transparent panel in netcf? For example if i have
a background image on my main form and i want to add a panel with a
button over my form, so the panel would be semi -transparent showing
the form's background image?

Thanks

Christian Resma Helle

unread,
Jan 8, 2008, 9:03:44 AM1/8/08
to
What you can do is to draw the part of the form's background image on the
control to give a so called "transparent" effect. I think you can draw on
the Panel control in .NETCF 3.5. Otherwise you'll have to can you're own
custom Panel control by creating a class that inherits from
ScrollableControl.

--
Regards,
Christian Resma Helle
http://christian-helle.blogspot.com


"mrabie" <mustaf...@gmail.com> wrote in message
news:0e01165a-b326-4f7d...@s8g2000prg.googlegroups.com...

Christian Resma Helle

unread,
Jan 8, 2008, 9:26:18 AM1/8/08
to
Otherwise you'll have to create you're own

custom Panel control by creating a class that inherits from
ScrollableControl...

Sorry for the typo

--
Regards,
Christian Resma Helle
http://christian-helle.blogspot.com


"Christian Resma Helle" <xtia...@gmail.com> wrote in message
news:eMWgeTdU...@TK2MSFTNGP02.phx.gbl...

mrabie

unread,
Jan 8, 2008, 9:45:57 AM1/8/08
to
On Jan 8, 1:26 am, "Christian Resma Helle" <xtian...@gmail.com> wrote:
> Otherwise you'll have to create you're own
> custom Panel control by creating a class that inherits from
> ScrollableControl...
>
> Sorry for the typo
>
> --
> Regards,
> Christian Resma Hellehttp://christian-helle.blogspot.com
>
> "Christian Resma Helle" <xtian...@gmail.com> wrote in messagenews:eMWgeTdU...@TK2MSFTNGP02.phx.gbl...

>
>
>
> > What you can do is to draw the part of the form's background image on the
> > control to give a so called "transparent" effect. I think you can draw on
> > the Panel control in .NETCF 3.5. Otherwise you'll have to can you're own
> > custom Panel control by creating a class that inherits from
> > ScrollableControl.
>
> > --
> > Regards,
> > Christian Resma Helle
> >http://christian-helle.blogspot.com
>
> > "mrabie" <mustafa.ra...@gmail.com> wrote in message

> >news:0e01165a-b326-4f7d...@s8g2000prg.googlegroups.com...
> >> Hi,
>
> >> I was wondering if someone can help me in finding a way to create a
> >> semi-transparent or transparent panel in netcf?  For example if i have
> >> a background image on my main form and i want to add a panel with a
> >> button over my form, so the panel would be semi -transparent showing
> >> the form's background image?
>
> >> Thanks- Hide quoted text -
>
> - Show quoted text -

Hi
thanks for the info, what if i want to create my own custom class,
where do i start looking to know how can i override the OnPaint class
to paint with a semi or transparent color?

Christian Resma Helle

unread,
Jan 9, 2008, 9:54:53 AM1/9/08
to
I don't really know of any article on the net that describes. but I took the
time to write some small code for a TransparentPanel control in .NETCF 3.5

What I did was to create an interface called IFormBackground that has a
property exposing the BackgroundImage of a form. I then created a custom
control that inherits from Panel, where I overridden the OnPaintBackground
of this control. In my OnPaintBackground I get the Parent control as
IFormBackground, if I get a NULL back then it means that the parent has no
background image coz it doesn't implement IFormBackground. Once I get my
IFormBackground instance, I draw part of the background image that my
control is on top of.

This would give you a so called transparent control effect. Here's the code
in C#

------------------
CODE START
------------------

namespace TransparentPanelSample
{
interface IFormBackground
{
Image BackgroundImage { get; }
}

class TransparentPanel : Panel
{
protected override void OnPaintBackground(PaintEventArgs e)
{
IFormBackground form = Parent as IFormBackground;
if (form == null) {
base.OnPaintBackground(e);
return;
}

e.Graphics.DrawImage(
form.BackgroundImage,
0,
0,
Bounds,
GraphicsUnit.Pixel);
}
}

class MainForm : Form, IFormBackground
{
Bitmap bmp;
TransparentPanel panel;
Button button;

public MainForm()
{
bmp = new Bitmap(
Assembly.GetExecutingAssembly().GetManifestResourceStream(
"TransparentPanelSample.background.jpg"));

panel = new TransparentPanel();
panel.Bounds = new Rectangle(20, 20, 200, 280);
panel.Visible = true;
Controls.Add(panel);

button = new Button();
button.Text = "Button1";
button.Bounds = new Rectangle(50, 50, 70, 30);
button.Visible = true;
panel.Controls.Add(button);
}

protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawImage(bmp, 0, 0);
}

public Image BackgroundImage
{
get { return bmp; }
}
}
}

---------------
CODE END
---------------

I hope this helps...

--
Regards,
Christian Resma Helle
http://christian-helle.blogspot.com

"mrabie" <mustaf...@gmail.com> wrote in message

news:4049547a-e39a-41cd...@v67g2000hse.googlegroups.com...

mrabie

unread,
Jan 10, 2008, 11:24:23 AM1/10/08
to
> Christian Resma Hellehttp://christian-helle.blogspot.com
> to paint with a semi or transparent color?- Hide quoted text -

>
> - Show quoted text -

Hey Christian

thank you so much for the code sample it was really helpful i really
appreciate it

0 new messages