网站首页 > 文章中心 > 其它

vb.net画矩形框

作者:小编 更新时间:2023-09-27 07:44:06 浏览量:82人看过

VB里面怎么画矩形?

使用Line方法,向Form,PictureBox这些控件都支持这个方法.

语法:

如:

加B这个参数就是矩形,加F就是用就边框颜色填充

补充:

Color参数就是边框颜色,如果省略,就用对象的ForeColor(前景色,就是字体的颜色) 属性值

VB.NET我要用鼠标轨迹画一个矩形框 然后选中控件.就像星际和魔兽争霸里对部队单位的选中一样~等大神回答

这个类继承自Panel,把它加到你的项目里面,先运行一下,然后从工具箱里把它拖到窗体上,然后再向里面添加其它控件就可以了,支持Shift加选,Alt减选

Imports?System.Linq

Imports?System.Collections

Public?Class?MyPanel

Inherits?Panel

'?选择模式,相交还是包含

Enum?SelectMode

Intersects

Contains

End?Enum

Dim?down?As?New?Point(-1,?-1)

Dim?rect?As?Rectangle

Dim?selected?As?New?List(Of?Control)

Dim?editting?As?IEnumerable(Of?Control)

Dim?mode?As?SelectMode?=?SelectMode.Contains

Dim?shift,?alt?As?Boolean

Public?Sub?New()

Me.DoubleBuffered?=?True

End?Sub

Protected?Overrides?Sub?OnMouseDown(e?As?MouseEventArgs)

MyBase.OnMouseDown(e)

down?=?e.Location

editting?=?selected.ToArray().ToList()

OnMouseMove(e)

Protected?Overrides?Sub?OnMouseMove(e?As?MouseEventArgs)

MyBase.OnMouseMove(e)

If?e.Button?=?Windows.Forms.MouseButtons.Left?Then

Dim?loc?As?New?Point(Math.Min(down.X,?e.X),?Math.Min(down.Y,?e.Y))

Dim?size?As?New?Size(Math.Abs(down.X?-?e.X),?Math.Abs(down.Y?-?e.Y))

rect?=?New?Rectangle(loc,?size)

Dim?cs?As?New?List(Of?Control)

For?Each?c?In?Controls

cs.Add(c)

Next

Dim?a?=?cs.Where(Function(n?As?Control)?(mode?=?SelectMode.Contains?And?rect.Contains(n.Bounds))?Or?(mode?=?SelectMode.Intersects?And?rect.IntersectsWith(n.Bounds)))

If?shift?Then?editting?=?a.Union(selected)?Else?If?alt?Then?editting?=?selected.Except(a)?Else?editting?=?a

Invalidate()

End?If

Protected?Overrides?Sub?OnMouseUp(e?As?MouseEventArgs)

MyBase.OnMouseUp(e)

down?=?New?Point(-1,?-1)

selected?=?editting.ToList()

editting?=?Nothing

Protected?Overrides?Function?ProcessKeyPreview(ByRef?m?As?Message)?As?Boolean

Dim?KeyCode?As?Keys?=?CInt(m.WParam)?And?CInt(Keys.KeyCode)

Dim?d?As?Boolean

If?KeyCode?=?Keys.ShiftKey?Then

shift?=?d

ElseIf?KeyCode?=?Keys.Menu?Then

alt?=?d

Return?MyBase.ProcessKeyPreview(m)

End?Function

Protected?Overrides?Sub?OnPaint(e?As?PaintEventArgs)

MyBase.OnPaint(e)

For?Each?c?As?Control?In?IIf(editting?Is?Nothing,?selected,?editting)

End?Class

vb.net画一个矩形图片的代码

g?=?Me.picDisplay.CreateGraphics

Dim?mybrush?As?Brush?=?New?SolidBrush(Map_Empty_Color)

vb.net画填充的方形矩形

Dim canvas As New ShapeContainer

' To draw anoval, substitute

' OvalShapefor RectangleShape.

DimtheShape As NewRectangleShape

' Set theform as the parent of the ShapeContainer.

canvas.Parent = Me

' Set theShapeContainer as the parent of the Shape.

theShape.Parent = canvas

' Set thesize of the shape.

' Set thelocation of the shape.

theShape.Location = New System.Drawing.Point(100,100)

' To draw arounded rectangle, add the following code:

theShape.FillStyle = FillStyle.Solid

theShape.FillColor = Color.Red

请教如何在VB中画一个填充有颜色的矩形(详细一点)

使用Line 方法

在对象上画直线和矩形.

语法

Line 方法的语法有以下对象限定符和部分:

部分 描述

object 可选的. 对象表达式,其值为"应用于"列表中的对象.如果object 省略,具有焦点的窗体作为object.

Step 可选的.关键字,指定起点坐标,它们相对于由 CurrentX 和 CurrentY 属性提供的当前图形位置.

(x1, y1) 可选的.Single (单精度浮点数),直线或矩形的起点坐标.ScaleMode 属性决定了使用的度量单位.如果省略,线起始于由 CurrentX 和 CurrentY 指示的位置.

Step 可选的.关键字,指定相对于线的起点的终点坐标.

color 可选的.Long (长整型数),画线时用的 RGB 颜色.如果它被省略,则使用 ForeColor 属性值.可用 RGB 函数或 QBColor 函数指定颜色.

B 可选的.如果包括,则利用对角坐标画出矩形.

F 可选的.如果使用了 B 选项,则 F 选项规定矩形以矩形边框的颜色填充.不能不用 B 而用 F.如果不用 F 光用 B,则矩形用当前的 FillColor 和 FillStyle 填充.FillStyle 的缺省值为 transparent.

例:

Private Sub Form_Load()

Me.AutoRedraw = True

End Sub

以上就是土嘎嘎小编为大家整理的vb.net画矩形框相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章