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