How can I make the arrow smoother it's a little bit jagged now

T

Tony Johansson

Here is the code that draw the x axes and the y axes with arrow on each
line.
I just wonder if it's possible to make the arrow less jagged ?

private void pnlDiagram_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;

//Move origo down to the left corner
g.TranslateTransform(pnlDiagram.Width * 1/10, pnlDiagram.Height *
9/10);

marginal = (float)Math.Min(0.1 * pnlDiagram.Width, 0.1 *
pnlDiagram.Height);
Pen pen = new Pen(Color.Blue, 1);

//Create Y axes
Point yaxelStart = new Point(0, 0);
Point yaxelEnd = new Point(0, -pnlDiagram.Height +
(int)(2*marginal));
g.DrawLine(pen, yaxelStart, yaxelEnd);

//Create arrow on Y axes
PointF[] arrowY = new PointF[3];
arrowY[0] = new PointF(-6, -pnlDiagram.Height + (int)(2 *
marginal));
arrowY[1] = new PointF(6, -pnlDiagram.Height + (int)(2 *
marginal));
arrowY[2] = new PointF(0, -pnlDiagram.Height + (int)(2 *
marginal) - 20);
g.FillPolygon(Brushes.Blue, arrowY);
g.DrawPolygon(Pens.Blue, arrowY);

//Create X axes
Point xaxelStart = new Point(0, 0);
Point xaxelEnd = new Point(pnlDiagram.Width - (int)(2 * marginal),
0);
g.DrawLine(pen, xaxelStart, xaxelEnd);

//Create arrow on X axes
PointF[] arrowX = new PointF[3];
arrowX[0] = new PointF(pnlDiagram.Width - (int)(2 * marginal), -6);
arrowX[1] = new PointF(pnlDiagram.Width - (int)(2 * marginal), 6);
arrowX[2] = new PointF(pnlDiagram.Width - (int)(2 * marginal) + 20,
0);
g.FillPolygon(Brushes.Blue, arrowX);
g.DrawPolygon(Pens.Blue, arrowX);
}

//Tony
 
T

Tony Johansson

Peter Duniho said:
Depends on what you mean. But if it's anti-aliasing you're looking for,
setting the SmoothingMode property to one of the anti-aliased values will
do that.

Pete

I added this row as you can see below
g.SmoothingMode = SmoothingMode.AntiAlias;
but I didn't see any change it's still a little bit jagged.
So why didn't this SmoothingMode have any effect when the arrow was drawn?

private void pnlDiagram_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;

//Move origo down to the left corner
g.TranslateTransform(pnlDiagram.Width * 1/10, pnlDiagram.Height *
9/10);

marginal = (float)Math.Min(0.1 * pnlDiagram.Width, 0.1 *
pnlDiagram.Height);
Pen pen = new Pen(Color.Blue, 1);

//Create Y axes
Point yaxelStart = new Point(0, 0);
Point yaxelEnd = new Point(0, -pnlDiagram.Height +
(int)(2*marginal));
g.DrawLine(pen, yaxelStart, yaxelEnd);

//Create arrow on Y axes
PointF[] arrowY = new PointF[3];
arrowY[0] = new PointF(-6, -pnlDiagram.Height + (int)(2 *
marginal));
arrowY[1] = new PointF(6, -pnlDiagram.Height + (int)(2 *
marginal));
arrowY[2] = new PointF(0, -pnlDiagram.Height + (int)(2 *
marginal) - 20);
g.FillPolygon(Brushes.Blue, arrowY);
g.DrawPolygon(Pens.Blue, arrowY);
g.SmoothingMode = SmoothingMode.AntiAlias;

//Create x axes
Point xaxelStart = new Point(0, 0);
Point xaxelEnd = new Point(pnlDiagram.Width - (int)(2 * marginal),
0);
g.DrawLine(pen, xaxelStart, xaxelEnd);

//Create arrow on X axes
PointF[] arrowX = new PointF[3];
arrowX[0] = new PointF(pnlDiagram.Width - (int)(2 * marginal), -6);
arrowX[1] = new PointF(pnlDiagram.Width - (int)(2 * marginal), 6);
arrowX[2] = new PointF(pnlDiagram.Width - (int)(2 * marginal) + 20,
0);
g.FillPolygon(Brushes.Blue, arrowX);
g.DrawPolygon(Pens.Blue, arrowX);
g.SmoothingMode = SmoothingMode.AntiAlias;
}

//Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top