how to transparent picturebox and show another controls which is under it
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Lalit MPosted Mar 8, 2010, 4:43 AM
Show here example
public class Form1
{
private Bitmap _myImage = new Bitmap("C:\\myImage.gif");
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawImageUnscaled(new Bitmap(_myImage), 100, 100);
}
}
OR you can try this code sample Transparent label above a picturebox
protected override void OnPaint(PaintEventArgs e)
{
gxOff = e.Graphics;
}
private void pbx_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
DrawLabel(lblPag1, g);
}
private void DrawLabel(Label lbl, Graphics grx)
{
Rectangle rect;
if (lbl.TextAlign == ContentAlignment.TopLeft) {
gxOff.DrawString(lbl.Text, lbl.Font, new SolidBrush(lbl.ForeColor), lbl.Location.X, lbl.Location.Y);
}
else if ((lbl.TextAlign == ContentAlignment.TopCenter)) {
SizeF size;
size = grx.MeasureString(lbl.Text, lbl.Font);
int Left;
Left = (this.Width / 2) - ((int)size.Width / 2);
rect = new Rectangle(Left, lbl.Top, (int)size.Width, (int)lbl.Height);
gxOff.DrawString(lbl.Text, lbl.Font, new SolidBrush(lbl.ForeColor), rect.Location.X, rect.Location.Y);
pbx.Visible = false;
}
else if (lbl.TextAlign == ContentAlignment.TopRight) {
SizeF size;
size = grx.MeasureString(lbl.Text, lbl.Font);
int Left;
Left = lbl.Width - (int)size.Width + lbl.Left;
rect = new Rectangle(Left, lbl.Top, (int)size.Width, (int)lbl.Height);
gxOff.DrawString(lbl.Text, lbl.Font, new SolidBrush(lbl.ForeColor), rect.Location.X, rect.Location.Y);
}
}