[英]C# Pen.DashPattern
我想在拖放的同時在兩行之間畫一條線。 其功能只是視覺上的,以便用戶知道他將行放到哪里。 該行應看起來像一次。 這是我的代碼:
Pen _marqueePen = new Pen(Color.Gray, 2);
float[] dashValues = {1f,1f};
_marqueePen.DashPattern = dashValues;
但這看起來像
我想看起來像這樣:
我是WinForms和C1 Flexgrid控件。
您可以像這樣使用自定義筆:
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像素!
這是結果行:
一些選項:
在我看來,這更像是用HatchBrush
歸檔的矩形,其HatchStyle.Percent50
和高度為3。
你可以試試
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.