I've recently migrated over from VB6 to VB.Net and C#. I decided to rewrite a fairly simple program that drew lines onto a semitransparent form and then made the form completely transparent once the drawing was complete.
The problem that I've found with C# is that after I call Bitmap.MakeTransparent(), I cannot use GraphicsPath to draw on the form. Is there some way of setting the bitmap back having a solid background after calling MakeTransparent
Any help would be greatly appreciated.
Will Vandergrift
Wilz Modz

GraphicsPath on Transparent Bitmap
eyupcinar
gafferuk
Here is the code for setting up the graphics object and also for drawing the lines and displaying the bitmap.
private void frmMain_Load(object sender, EventArgs e)
{
//=============================================================
//Create a drawing surface with the same dimensions as the form //=============================================================m_objDrawingSurface =
new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height);objGraphics =
Graphics.FromImage(m_objDrawingSurface); //m_objDrawingSurface.MakeTransparent(Color.FromArgb(254, 255, 255));Above line commented out because if not, I cannot draw on the form.
objGraphics.Clear(
Color.FromArgb(254, 255, 255)); //============================================== //Create a rectangle the same size as the bitmap //==============================================rectBounds =
new Rectangle(0, 0,m_objDrawingSurface.Width, m_objDrawingSurface.Height);
//============================= //Setup pen for drawing on form //=============================MyPen =
new Pen(Color.Blue, 3);MyPen.DashStyle = System.Drawing.Drawing2D.
DashStyle.Solid;}
private void frmMain_MouseDown(object sender, MouseEventArgs e){
//================================================== //If the left mouse button is pressed, start drawing //================================================== if (e.Button == MouseButtons.Left){
//============================= //Setup the graphicsPath object //This is the key to drawing //smooth lines with GDI+ //=============================PenPath =
new System.Drawing.Drawing2D.GraphicsPath();Drawing =
true;PenPath.StartFigure();
}
}
private void frmMain_MouseMove(object sender, MouseEventArgs e){
//============================================================== //Draw a line if the user is pressing the left mouse button down //============================================================== if (Drawing == true){
//========================================== //Draw the line and force the form to redraw //==========================================PenPath.AddLine(e.X, e.Y, e.X, e.Y);
objGraphics.DrawPath(MyPen, PenPath);
this.Invalidate();}
}
private void frmMain_MouseUp(object sender, MouseEventArgs e){
//================================================== //If the left mouse button is released, stop drawing //================================================== if (e.Button == MouseButtons.Left){
Drawing =
false; //================== //Clean up resources //==================PenPath.Dispose();
}
}
private void frmMain_Paint(object sender, PaintEventArgs e){
//============================================= //Draw the contents of the bitmap onto the form //=============================================e.Graphics.DrawImage(m_objDrawingSurface, 0, 0,
m_objDrawingSurface.Width, m_objDrawingSurface.Height);
}
Sorry, there's a lot of code here but maybe it will help to explain things.
Thanks again for your help.