Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在数据网格c中创建波浪线样的拼写#_C#_Winforms - Fatal编程技术网

C# 如何在数据网格c中创建波浪线样的拼写#

C# 如何在数据网格c中创建波浪线样的拼写#,c#,winforms,C#,Winforms,当用户创建一个新网格时,我想显示一条波浪线,如下所示: 我怎样才能做到?目前,我正在通过调用DrawLine来绘制它,但完成它需要很长时间 private void Form1_Paint(object sender, PaintEventArgs e) { Graphics l = e.Graphics; Pen p = new Pen(Color.Red, 1); l.DrawLine(p ,10 ,5,5,0);

当用户创建一个新网格时,我想显示一条波浪线,如下所示:

我怎样才能做到?目前,我正在通过调用
DrawLine
来绘制它,但完成它需要很长时间

    private void Form1_Paint(object sender, PaintEventArgs e)
    {
        Graphics l = e.Graphics;
        Pen p = new Pen(Color.Red, 1);
        l.DrawLine(p ,10 ,5,5,0);
        l.DrawLine(p, 10, 5, 15, 0);
        l.DrawLine(p, 20, 5, 15, 0);
        l.DrawLine(p, 20, 5, 25, 0);
        l.DrawLine(p, 30, 5, 25, 0);
        l.Dispose();
    }

DataGridView.CellPaint
事件添加处理程序

dataGridView1.CellPainting += dataGridView1_CellPainting;
这里是实现。注意:这些线位于单元格的“白盒”之外

private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
    var dg = (DataGridView) sender;

    if (e.ColumnIndex == -1 || e.RowIndex != (dg.RowCount - 1))
        return;

    using (var p = new Pen(Color.Red, 1))
    {
        var cellBounds = e.CellBounds;

        const int size = 2;
        var pts = new List<Point>();
        var h = false;
        for (int i = cellBounds.Left; i <= cellBounds.Right; i += size,h = !h)
        {
            pts.Add(
                new Point
                {
                    X = i,
                    Y = h ? cellBounds.Bottom : cellBounds.Bottom + size
                });
        }

        e.Graphics.DrawLines(p, pts.ToArray());
    }
}
private void dataGridView1\u CellPainting(对象发送方,DataGridViewCellPaintingEventArgs e)
{
var dg=(DataGridView)发送方;
如果(e.ColumnIndex==-1 | | e.RowIndex!=(dg.RowCount-1))
返回;
使用(var p=新笔(颜色:红色,1))
{
var cellBounds=e.cellBounds;
常数int size=2;
var pts=新列表();
var h=假;

对于(int i=cellBounds.Left;我尝试在datagridview的CellPaint事件中绘制线条,或重写网格的OnCellPaint方法。此外,您不应该处理从PaintEventArgs获得的图形对象,而应该处理Pen对象。