Here I draw the y axes but how do I get an arrow on top

T

Tony Johansson

Here I draw the y axes with 1 pixel wide this works fine.
Now I want to keep the width of the line with one pixel but I want an arrow
at the top.
If I now draw the arrow by using this code
pen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
the arrow is too small so how do I draw a bigger arrow but keep the same
width of the y axes ?


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);

Pen pen = new Pen(Color.Blue, 1);
pen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
Point yaxelStart = new Point(0, 0);
Point yaxelSlut = new Point(0, -pnlDiagram.Height +
(int)(2*0.1*pnlDiagram.Height));
g.DrawLine(pen, yaxelStart, yaxelSlut);
}

//Tony
 
T

Tony Johansson

Peter Duniho said:
And yet, once again you have not shared it here.

That's something like the third time in the last month you've done that.
If the question is worth you posting here, it's worth you posting the
answer here too. Others may be interested in your answer.

Besides, it's the polite thing to do.

Pete

Here is the solution.
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
 

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