使用滚动条值作为 PaintEventArgs 循环的参数

Using a Scrollbar value as a parameter for a PaintEventArgs loop

我正在尝试创建一个 windows.form,它使用水平滚动条作为时间控件。然后将时间值用作 85 个数组的数组索引,每个数组值(不为零)包含一个方位角,然后在地图上显示为一条线。我遇到的问题是我对 C# 和事件处理还很陌生,所以我找不到将 link hScrollBar1_Scroll 的事件(和值)传递给 PaintEventArgs 循环的方法。以下是我尝试过的代码示例:

private void hScrollBar1_Scroll(object sender, ScrollEventArgs e, [PaintEventArgs f])
int t = e.NewValue;
//There's a few lines of code here that convert the value of the scrollbar to time and
//display it in a box.
{
    for (int s = 1; s <= 85; s++)
    {
        if (ldata[s, t, 0] != 0)
        {
            DrawLinesPoint(s, t, null);
        }
    }

DrawLinesPoint() 循环的原因是因为有 85 个站点可能同时显示方位角。

起初我尝试使用 "PaintEventArgs f" 作为参数和 "ScrolleventArgs e" 但不知道如何处理事件,所以 DrawlinesPoint() 使用 "null" 而不是 "f".

public void DrawLinesPoint(int s, int t, PaintEventArgs e)
{

    Graphics g = e.Graphics;
    int c = rdata[s,0];
    Pen pen;
    switch (c)
    {
        ...
        //These bearings can be three different colours
    }
    int x1 = rdata[s,1];
    int y1 = rdata[s,2];
    int x2 = rdata[s,1] + ldata[s,t,0];
    int y2 = rdata[s,2] + ldata[s,t,1];


    g.DrawLine(pen, x1, y1, x2, y2);
}

数组 rdata[] 是二维的,保存站点的参考数据,ldata[] 是三维的,包含导入的轴承数据。

每次通过滚动条更改时间时,必须清除地图并更改显示的方位。

任何人都可以帮助这个代码吗?我很有可能完全以错误的方式执行此操作,因此我们将不胜感激。

您没有从自己的代码中调用 Paint 事件。 Windows 决定何时绘制(或者你可以通过调用 Invalidate 方法强制它绘制)。

您应该做的是重写控件的 OnPaint 方法(在需要绘制时调用)并在其中添加绘图代码:

    protected override void OnPaint(PaintEventArgs e) {
        // Add your drawing code here
    }

从那里,您可以调用具有逻辑的其他方法。

要获得更详细的答案,我们需要更多代码,例如 rdataldata。但我想你能想出来。