vb.net多个矩形 vb矩形代码
谁知道怎么用VB.NET编写一个算长方形面积的程序?
dim a as single=...'自己输入长方形的长
专注于为中小企业提供成都网站设计、网站建设服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业台儿免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了千余家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
dim b as single=...'自己输入长方形的宽
dim c as single=a*b'计算面积
textbox1.text=c'显示面积
vb.net画一个矩形图片的代码
g = Me.picDisplay.CreateGraphics
Dim mybrush As Brush = New SolidBrush(Map_Empty_Color)
Dim rect2 As System.Drawing.Rectangle = New System.Drawing.Rectangle(0, 0, Map_Width, Map_Height)
g.FillRectangle(mybrush, rect2)
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)
End Sub
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
End Sub
Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
MyBase.OnMouseUp(e)
down = New Point(-1, -1)
selected = editting.ToList()
editting = Nothing
Invalidate()
End Sub
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 m.Msg = H100 Or m.Msg = H104 Then d = True Else If m.Msg = H101 Or m.Msg = H105 Then d = False Else Return MyBase.ProcessKeyPreview(m)
If KeyCode = Keys.ShiftKey Then
shift = d
ElseIf KeyCode = Keys.Menu Then
alt = d
End If
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)
e.Graphics.DrawRectangle(New Pen(Color.Gray) With {.DashStyle = Drawing2D.DashStyle.DashDot}, c.Left - 1, c.Top - 1, c.Width + 1, c.Height + 1)
Next
If (down.X 0) Then e.Graphics.DrawRectangle(New Pen(Color.Gray) With {.DashStyle = Drawing2D.DashStyle.DashDot}, rect)
End Sub
End Class
VB.net一个很简单的UI问题
花了二十分钟给你写了代码,已测试。建议学习并使用System.Drawing绘制。
主要是掌握Graphics.FillRectangle和DrawString的使用。
Imports System.Drawing
Public Class 进度条UI
Public 上面笔刷 As SolidBrush = New SolidBrush(Color.FromArgb(192, 175, 238, 238))
Public 下面笔刷 As SolidBrush = New SolidBrush(Color.FromArgb(192, 30, 144, 255))
Public 文字笔 As SolidBrush = New SolidBrush(Color.FromArgb(255, 255, 255, 255))
Public 字体 As Font = New Font("微软雅黑", 14.0)
Public 文字格式 As StringFormat = New StringFormat() With
{.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center}
''' summary
''' 绘制指定进度的图像。
''' 当进度变化时调用一次本方法,建议将创建的Graphics对象保存到变量而不要重复创建。。
''' /summary
''' param name="控件"绘制到此控件的工作区/param
''' param name="g"绘制到控件的Graphics对象,例如 Button1.CreateGraphics()/param
''' param name="进度"进度百分比实数,57% = 0.57/param
Public Sub 绘制(ByRef 控件 As Control, ByRef g As Graphics, ByVal 进度 As Double)
Dim 矩形 = 控件.ClientRectangle '获取控件的工作区矩形
Dim 下面高度 = CInt(矩形.Height * 进度) '获取下面颜色块的高度
Dim 中间位置 = 矩形.Top + 矩形.Height - 下面高度 '获取中间分界线的Y坐标
Dim 上矩形 = New Rectangle(矩形.X, 矩形.Y, 矩形.Width, 矩形.Height - 下面高度)
Dim 下矩形 = New Rectangle(矩形.X, 中间位置, 矩形.Width, 下面高度)
g.FillRectangle(上面笔刷, 上矩形)
g.FillRectangle(下面笔刷, 下矩形)
'绘制文字
Dim 文字 As String = String.Format("{0:0.00}%", 进度 * 100)
g.DrawString(文字, 字体, 文字笔, 矩形, 文字格式)
End Sub
End Class
下面是Form1窗体的代码:添加一个Button1和Timer1控件,将Button1尺寸拖大点
Public Class Form1
Public g As Graphics
Public 进度条UI As New 进度条UI
Public 进度 As Double
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
g = Button1.CreateGraphics()
Timer1.Enabled = Not Timer1.Enabled
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
进度 += 0.01
进度条UI.绘制(Button1, g, 进度)
End Sub
End Class
网站名称:vb.net多个矩形 vb矩形代码
本文链接:http://hbruida.cn/article/ddddioj.html