Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.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#_Line_Custom Controls - Fatal编程技术网

C# 行的自定义控件

C# 行的自定义控件,c#,line,custom-controls,C#,Line,Custom Controls,我想为直线(垂直线或水平线)设计一个自定义控件 基本用户控件为矩形,不适用于行 您对线条控制有什么想法?如果更改控件的宽度和高度,您可以调整线条。只需创建一个用户控件,并在其中添加下面的代码即可 bool horizontal= false; protected override void OnPaint(PaintEventArgs e) { if (horizontal) {

我想为直线(垂直线或水平线)设计一个自定义控件 基本用户控件为矩形,不适用于行
您对线条控制有什么想法?

如果更改控件的宽度和高度,您可以调整线条。
只需创建一个用户控件,并在其中添加下面的代码即可

  bool horizontal= false;
        protected override void OnPaint(PaintEventArgs e)
        {
            if (horizontal)
            {
                Height = 1;
                e.Graphics.DrawLine(Pens.Black, 0, 0, Width, 1);
            }
            else
            {
                Width = 1;
                e.Graphics.DrawLine(Pens.Black, 0, 0, 1, Height);
            }
        }

创建一个新的用户控件,拖动到设计器界面上,如果需要水平线,请将Height属性设置为2px左右,如果需要垂直线,请将Width属性设置为2px左右。

请更具体地回答您的问题。可能还需要关注语法,我觉得线条控制没有多大用处。。。