hello,
i am using the Graphics.DrawLine method in C# and this is fine for thin lines but for thick lines it draws really badly. i have sample code to reproduce the problem below. just create a new c# forms application and add a picture box to the form. make the picture box the same size as the form and add empty MouseUp, MouseDown and MouseMove event handlers. then add this to form1.cs:
public partial class Form1 : Form
{
//var
Pen myPen;
bool bMouseDown = false;
Point prevPoint;
Graphics g;
//ctor
public Form1()
{
InitializeComponent();
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
bMouseDown = false;
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
prevPoint = e.Location;
bMouseDown = true;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (bMouseDown)
{
Point thisPoint = e.Location;
if (prevPoint.X == 0 && prevPoint.Y == 0)
{
prevPoint = thisPoint;
return;
}
g.DrawLine(myPen, thisPoint.X, thisPoint.Y, prevPoint.X, prevPoint.Y);
prevPoint = thisPoint;
}
}
private void Form1_Load(object sender, EventArgs e)
{
myPen = new System.Drawing.Pen(System.Drawing.Color.Black);
g = pictureBox1.CreateGraphics();
myPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
myPen.Color = Color.Black;
myPen.Width = 5.0f;
}
}
as you can see pretty simple stuff. in every MouseMove event, i simply draw a line from the previous point (prevPoint) to the current point (thisPoint). the pen that i draw with is a solid black pen, 5 pixels wide.
if you run that code and use the mouse to free-draw a line, it looks ok. but now change the pen width to something like:
myPen.Width = 30.0f;
if you try it again you will see that the line is drawn horribley. what i need is for a nice thick black solid line and this is not what happens.
is there any other way to achieve what i am trying to do (free-draw a line of all thicknesses) ?