L
Lee
I have the following code
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Collections;
namespace FINN
{
public class flickerFreePictureBox : PictureBox
{
public ArrayList Lines = new ArrayList();
public flickerFreePictureBox()
{
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle (ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
//this.MouseMove += new MouseEventHandler(_MouseMove);
}
protected override void OnPaint(PaintEventArgs e)
{
bool error = false;
//e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
try
{
foreach(scribbleObject al in Lines)
{
bool Drawdot = false;
try
{
Point[] linelist = new Point[
al.linePositions.Count];
al.linePositions.CopyTo(0,linelist,0,al.linePositions.Count);
e.Graphics.DrawLines(al.pen(), linelist);
}
catch
{
Drawdot = true; //we want to draw a dot
}
if(Drawdot)
{
//Draw a single dot as the user has only
clicked, rather than clicked and dragged
//TODO: Draw a dot
}
}
}
catch
{
error = true;
}
if(error)
{
//this.OnPaint(e);
}
}
}
}
And I would like to be able to create a bitmap of what gets drawn in
OnPaint so that I can save it to file, I've tried a few things, but so
far just ended up with black bitmaps the same size as the control that
code creates, any suggestions or code snippets would be a great help.
Cheers
Lee
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Collections;
namespace FINN
{
public class flickerFreePictureBox : PictureBox
{
public ArrayList Lines = new ArrayList();
public flickerFreePictureBox()
{
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle (ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
//this.MouseMove += new MouseEventHandler(_MouseMove);
}
protected override void OnPaint(PaintEventArgs e)
{
bool error = false;
//e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
try
{
foreach(scribbleObject al in Lines)
{
bool Drawdot = false;
try
{
Point[] linelist = new Point[
al.linePositions.Count];
al.linePositions.CopyTo(0,linelist,0,al.linePositions.Count);
e.Graphics.DrawLines(al.pen(), linelist);
}
catch
{
Drawdot = true; //we want to draw a dot
}
if(Drawdot)
{
//Draw a single dot as the user has only
clicked, rather than clicked and dragged
//TODO: Draw a dot
}
}
}
catch
{
error = true;
}
if(error)
{
//this.OnPaint(e);
}
}
}
}
And I would like to be able to create a bitmap of what gets drawn in
OnPaint so that I can save it to file, I've tried a few things, but so
far just ended up with black bitmaps the same size as the control that
code creates, any suggestions or code snippets would be a great help.
Cheers
Lee