5

1 つの Windows フォーム ユーザー コントロールを作成し、その中にパネルをドラッグ アンド ドロップし、そのパネル上に Panel の Paint イベントでグラフを描画しました。

private void pnlViewer_Paint(object sender, PaintEventArgs e)
{
    e.Graphics.TranslateTransform(pnlViewer.AutoScrollPosition.X, pnlViewer.AutoScrollPosition.Y);
    e.Graphics.FillRectangle(Brushes.Black, Screen.PrimaryScreen.Bounds);
    //**draw Y Axis**
    int y;
    for (int i = 0; i <= 50; i++)
    {
        y = (i * cellHeight) + cellHeight;
        e.Graphics.DrawLine(new Pen(Color.FromArgb(50, 50, 50)),
                            new Point(0, y), new Point(pageWidth, y));
    }
    //**draw X Axis**
    int x;
    for (int i = 0; i < 50; i++)
    {
        x = (i * cellWidth) + ribbonWidth;
        e.Graphics.DrawLine(new Pen(Color.FromArgb(50, 50, 50)),
                            new Point(x, 0), new Point(x, pageHeight));
    }
    DrawWaveForm(e.Graphics); **// Here the actual data of graph will draw**
}

このユーザー コントロールを WinForm にドラッグすると、Windows フォームからユーザー コントロールのこのペイント イベントが呼び出されますが、このイベントの呼び出し中にグラフが表示されますが、しばらくするとグラフが空白になります。

私はそのような方法をすべて試しInvalidate(true), Update(), Refresh()ましたが、役に立ちませんでした。

実際には、グラフの半分がフォーム上に表示され、次に同じペイント イベントが発生した後、必要な完全なグラフが表示されますが、実際には完全なグラフを表示する半分のグラフではなく、最初の Paint イベントが必要です。

4

1 に答える 1