在VB.NET WinForms中以编程方式添加LineShape [英] Add LineShape programatically in VB.NET WinForms

查看:330
本文介绍了在VB.NET WinForms中以编程方式添加LineShape的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在VB.NET WinForms中以编程方式添加LineShape?

How do you add a LineShape programmatically in VB.NET WinForms?

我想为LabelCheckBox或其他内容编写类似的内容:

I'm looking to write something like you would for a Label , CheckBox or whatever else:

Dim somelabel as New Label
somelabel.Text = "Whatever"
somelabel.Location = New Point(200, 200)
Me.Controls.Add(somelabel)

等等.

我的目的是在形成4x4网格的16个Label的行和列之间创建细的分隔线.

My purpose is to create thin dividing lines between the rows and columns of 16 Labels that form a 4x4 grid.

我理解,由于LineShape是VB PowerPack的一部分,因此可能会遇到一些困难,例如必须使用Imports ...或(如果确实需要)导入.dll.但我想看看您的所有想法/解决方案!

I appreciate that, since LineShape is a part of VB PowerPacks, this may present some difficulties, such as having to use Imports ... or, if really necessary, import a .dll. But I'd like to see all your ideas/solutions!

推荐答案

首先,导入powerpacks命名空间以使您可以访问控件:

First, import the powerpacks namespace to give you access to the control:

Imports Microsoft.VisualBasic.PowerPacks

然后您可以这样做:

Dim startx As Integer
Dim starty As Integer
Dim endx As Integer
Dim endy As Integer
Dim yourline As New LineShape(startx, starty, endx, endy)

其中startx = x起始位置,starty = y起始位置,endx =结束x位置,endy =结束y位置. 如果要将其放在画布中,只需:

Where startx = the x starting position, starty = the y starting position, endx = the ending x position and endy = the ending y position. If you want to put it into a canvas, simply:

Dim yourcanvas As ShapeContainer
canvas.Parent = formName
yourline.Parent = canvas

有关更多信息和API参考,请访问: http://msdn.microsoft.com/en-us/library/bb918067.aspx

For more information and an API reference, go to: http://msdn.microsoft.com/en-us/library/bb918067.aspx

这篇关于在VB.NET WinForms中以编程方式添加LineShape的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆