1

ドラッグ アンド ドロップを使用して、2 つの行の間に線を引きたい。これの機能は単に視覚的なものであるため、ユーザーは行をどこにドロップしているかがわかります。行は、Excel の 1 回のように見えるはずです。ここに私のコード:

        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

いくつかのオプション:

  • その優れた動作を模倣する PNG グラフィックを使用して、それをコントロールに描画できます (画像を垂直に並べて表示する必要があります)。
  • y 軸と x 軸を 1 ピクセルずらして、コードで 3 本の線を描画します。
于 2014-10-23T09:49:50.747 に答える
0

それは、高さが 3 でHatchBrushある長方形のように見えます。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 に答える