1

我想在使用拖放时在 2 行之间画一条线。它的功能是简单的可视化,以便用户知道他将行放在哪里。该行应该看起来像excel一次。这是我的代码:

        Pen _marqueePen = new Pen(Color.Gray, 2);
        float[] dashValues = {1f,1f};
        _marqueePen.DashPattern = dashValues;

但这看起来像

在此处输入图像描述

我想看起来像这样:

在此处输入图像描述

我是 WinForms 和C1 Flexgrid控件。

4

3 回答 3

4

您可以像这样使用自定义笔:

using (Pen pen = new Pen(Color.Gray, 4f) )
{
    pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
    pen.DashPattern = new float[] { 0.25F, 0.25F };
    // now draw your stuff.. 
}

注意MSDN上的文档:

The elements in the dashArray array set the length of each dash 
and space in the dash pattern. The first element sets the length of a dash, 
the second element sets the length of a space, the third element sets 
the length of a dash, and so on. Consequently, each element should be a 
non-zero positive number.

The length of each dash and space in the dash pattern is the product 
of the element value in the array and the width of the Pen.

只要牢记它们的关系,您可以选择任何笔宽和任何短划线和间隙长度。因此,如果您想要最好的短划线,请确保它们乘以 1.0 像素!

这是结果行:

细虚线

于 2014-10-23T10:21:50.693 回答
1

一些选项:

  • 您可以使用模仿该 excel 行为的 PNG 图形,然后将其绘制在控件上(您必须垂直平铺图像)。
  • 用您的代码绘制三行,y 轴和 x 轴偏移一个像素。
于 2014-10-23T09:49:50.747 回答
0

在我看来,这更像是一个高度为 3HatchBrush的矩形。HatchStyle.Percent50

你可以试试

Rectangle rect = new Rectangle(0, 0, 500, 3) //you will use the values here from your cursor but height will be 3
HatchBrush brush = new HatchBrush(HatchStyle.Percent50, Color.Black);
g.FillRectangle(brush, rect);
于 2016-09-15T00:19:40.293 回答