我只想在滚动时变换点。我已经使用了e.Graphics.TranslateTransform(),但它仅适用于绘图。线的点不会更改偏移量。
private void Form1_Scroll(object sender, ScrollEventArgs e)
{
Point scrollOffset = this.AutoScrollPosition;
for (int lk = 0; lk < Pt1.Count; lk++)
{
Pt1[lk] = new Point(Pt1[lk].X + scrollOffset.X, Pt1[lk].Y + scrollOffset.Y);
Pt2[lk] = new Point(Pt2[lk].X + scrollOffset.X, Pt2[lk].Y + scrollOffset.Y);
}
this.Invalidate();
this.Update();
this.Refresh();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Point scrollOffset = this.AutoScrollPosition;
e.Graphics.TranslateTransform(scrollOffset.X, scrollOffset.Y);
e.Graphics.Clear(this.BackColor);
e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
Pen greenPen = new Pen(Color.Green,1);
greenPen.DashPattern = new float[] { 5.0F, 5.0F, 5.0F, 5.0F };
Pen red = new Pen(Color.Red,1);
red.DashPattern = new float[] { 5.0F, 5.0F, 5.0F, 5.0F };
Pen Grey = new Pen(Color.Gray,1);
Grey.DashPattern = new float[] { 5.0F, 5.0F, 5.0F, 5.0F };
#region "Draw Line using cursor"
Pen SolidGreen = new Pen(Color.Green, 1);
Pen SolidGrey = new Pen(Color.Gray, 1);
Pen Red = new Pen(Color.Red, 1);
for (int pl = 0; pl < Pt1j.Count; pl++)
{
PointF[] pointsj = new PointF[]
{
new PointF(Pt2j[pl].X, Pt2j[pl].Y),
new PointF(Pt3j[pl].X , Pt3j[pl].Y),
new PointF(Pt4j[pl].X , Pt4j[pl].Y),
new PointF(Pt5j[pl].X , Pt5j[pl].Y),
};
e.Graphics.DrawLine(Pens.Green, Pt1j[pl].X , Pt1j[pl].Y, Pt2j[pl].X, Pt2j[pl].Y);
e.Graphics.DrawCurve(Pens.Green, pointsj);
e.Graphics.DrawLine(Pens.Green, Pt5j[pl].X , Pt5j[pl].Y, Pt6j[pl].X, Pt6j[pl].Y);
}
for (int pl = 0; pl < Pt1DashedGray.Count; pl++)
{
e.Graphics.DrawLine(Grey, Pt1DashedGray[pl], Pt2DashedGray[pl]);
PointF[] pointsdhg = new PointF[]
{
new PointF(Pt2DashedGray[pl].X, Pt2DashedGray[pl].Y),
new PointF(Pt3DashedGray[pl].X, Pt3DashedGray[pl].Y),
new PointF(Pt4DashedGray[pl].X, Pt4DashedGray[pl].Y),
new PointF(Pt5DashedGray[pl].X, Pt5DashedGray[pl].Y),
};
e.Graphics.DrawCurve(Grey, pointsdhg);
e.Graphics.DrawLine(Grey, Pt5DashedGray[pl], Pt6DashedGray[pl]);
}
for (int pl = 0; pl < Pt1SolidGray.Count; pl++)
{
e.Graphics.DrawLine(SolidGrey, Pt1SolidGray[pl], Pt2SolidGray[pl]);
PointF[] pointsdhg = new PointF[]
{
new PointF(Pt2SolidGray[pl].X, Pt2SolidGray[pl].Y),
new PointF(Pt3SolidGray[pl].X, Pt3SolidGray[pl].Y),
new PointF(Pt4SolidGray[pl].X, Pt4SolidGray[pl].Y),
new PointF(Pt5SolidGray[pl].X, Pt5SolidGray[pl].Y),
};
e.Graphics.DrawCurve(SolidGrey, pointsdhg);
e.Graphics.DrawLine(SolidGrey, Pt5SolidGray[pl], Pt6SolidGray[pl]);
}
for (int pl = 0; pl < Pt1DashGreen.Count; pl++)
{
e.Graphics.DrawLine(greenPen, Pt1DashGreen[pl], Pt2DashGreen[pl]);
PointF[] pointsdhg = new PointF[]
{
new PointF(Pt2DashGreen[pl].X, Pt2DashGreen[pl].Y),
new PointF(Pt3DashGreen[pl].X, Pt3DashGreen[pl].Y),
new PointF(Pt4DashGreen[pl].X, Pt4DashGreen[pl].Y),
new PointF(Pt5DashGreen[pl].X, Pt5DashGreen[pl].Y),
};
e.Graphics.DrawCurve(greenPen, pointsdhg);
e.Graphics.DrawLine(greenPen, Pt5DashGreen[pl], Pt6DashGreen[pl]);
}
for (int i = 0; i < Pt1.Count; i++)
{
e.Graphics.DrawLine(SolidGreen, Pt1[i], Pt2[i]);
}
for (int l = 0; l < DashedGreen1.Count; l++)
{
e.Graphics.DrawLine(greenPen, DashedGreen1[l], DashedGreen2[l]);
}
for (int k = 0; k < SolidGrey1.Count; k++)
{
e.Graphics.DrawLine(SolidGrey, SolidGrey1[k], SolidGrey2[k]);
}
for (int j = 0; j < DashedGrey1.Count; j++)
{
e.Graphics.DrawLine(Grey, DashedGrey1[j], DashedGrey2[j]);
}
if (IsDrawing)
{
e.Graphics.DrawLine(Red, NewPt1.X, NewPt1.Y, NewPt2.X, NewPt2.Y);
}
if (Draw_Dashed_Green)
{
e.Graphics.DrawLine(red, DashedGreenPT1, DashedGreenPT2);
}
if (Draw_Solid_Grey)
{
e.Graphics.DrawLine(Red, SolidGreyPT1, SolidGreyPT2);
}
if (Draw_dashed_Grey)
{
e.Graphics.DrawLine(red, DashedGreyPT1, DashedGreyPT2);
}
}
需要帮助 到目前为止,这是我的代码。 BDW,线的点存储在列表中。 Paint事件中的“绘制线条”还包括跳线,上面有6个要跳的点。
所以唯一的问题是我想在使用滚动条时更改线条的点。 感谢您回答我的问题。