vb.net 如何在表格上画一条线?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1137089/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 14:18:21  来源:igfitidea点击:

how do i draw a line on a form?

vb.netwinforms

提问by l--''''''---------''''''''''''

in vb.net i would like to draw a regular line on a form. is there a control to do this?

在 vb.net 中,我想在表单上画一条常规线。有没有控制来做到这一点?

回答by Mosquito Mike

What Mitch Wheat said is generally regarded as the correct answer, and what I have done in the past. However, if you want to have a visual control that you can drag on to a form, add the Microsoft.VisualBasic.PowerPack to your visual studio toolbox. To do that right-click on toolbox select "Choose Items...". Locate "Line Shape" on the .Net Framework Components tab.

Mitch Wheat所说的一般被认为是正确的答案,以及我过去所做的。但是,如果您想要一个可以拖到窗体上的可视控件,请将 Microsoft.VisualBasic.PowerPack 添加到您的 Visual Studio 工具箱。为此,请右键单击工具箱选择“选择项目...”。在 .Net Framework 组件选项卡上找到“线条形状”。

回答by Mitch Wheat

One way at design time is to use a Label control and set it's height, or width to 1 (2px and 3D border gives a nice chiseled effect). Or else you can manually draw using GDI:

设计时的一种方法是使用 Label 控件并将其高度或宽度设置为 1(2px 和 3D 边框提供了很好的轮廓分明的效果)。或者你可以使用 GDI 手动绘制:

Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)
Dim formGraphics as System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
formGraphics.DrawLine(myPen, 0, 0, 200, 200)
myPen.Dispose()
formGraphics.Dispose()

回答by drdavem

Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
    e.Graphics.DrawLine(Pens.Black, New Point(0, Me.Height - 1), New Point(Me.Width, Me.Height - 1))
End Sub

This draws a line on the bottom of the control every time it is painted.

每次绘制时,都会在控件底部绘制一条线。