Ich habe Probleme beim Zeichnen einer Linie in einem Gruppenfeld in einem einfachen Windows-Formular.Zeichnen einer Linie in Winforms
hier ist mein Code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
DrawLShapeLine(groupBox1.CreateGraphics(), 10, 10, 20, 40);
}
public void DrawLShapeLine(System.Drawing.Graphics g, int intMarginLeft, int intMarginTop, int intWidth, int intHeight)
{
Pen myPen = new Pen(Color.Black);
myPen.Width = 2;
// Create array of points that define lines to draw.
int marginleft = intMarginLeft;
int marginTop = intMarginTop;
int width = intWidth;
int height = intHeight;
int arrowSize = 3;
Point[] points =
{
new Point(marginleft, marginTop),
new Point(marginleft, height + marginTop),
new Point(marginleft + width, marginTop + height),
// Arrow
new Point(marginleft + width - arrowSize, marginTop + height - arrowSize),
new Point(marginleft + width - arrowSize, marginTop + height + arrowSize),
new Point(marginleft + width, marginTop + height)
};
g.DrawLines(myPen, points);
}
}
Wenn ich die DrawLShapeLine Methode auf eine Schaltfläche klicken Ereignis zuordnen, zieht es in Ordnung, aber es zieht nicht auf Last des Formulars.
Bitte um Rat.
Dies tut nicht diagonale Linien tho. –
Guter Tipp, wenn Sie keine diagonalen Linien * wollen und GDI + vermeiden möchten. –
Oder geben Sie eine feste einzelne Grenze. – jeromeyers