VB.net 中如何判断一个圆和一个矩形相交建立新窗体,新建timer控件 , 间隔随意,运行即可 , 输入以下代码,可以充分看到你要的效果
Dim yuanxin As New Point(50, 50) '圆心
Dim zhijing As Long = 100 '直径,其实里面用的多的是半径,但你说是直径,我就用直径
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
e.Graphics.Clear(Color.Beige) '刷除底色
Dim myRect As New RectangleF(150, 80, 100, 100) '建立矩形
e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(myRect)) '画出矩形
Dim p As System.Drawing.Drawing2D.GraphicsPath = New System.Drawing.Drawing2D.GraphicsPath() '新建路径
p.AddEllipse(yuanxin.X - zhijing \ 2, yuanxin.Y - zhijing \ 2, zhijing, zhijing) '向当前路径增加椭圆,里面的运算是把圆心转换为圆形外切矩形的左上角坐标以及这个矩形的宽和高,在本例中宽高即为圆形的直径
e.Graphics.DrawPath(Pens.Black, p) '在窗体上画出椭圆(本例中是圆形)
Dim myRegion As New [Region](p) '根据椭圆建立区域
Dim contained As Boolean = myRegion.IsVisible(myRect) '判断区域是否相交
Dim myFont As New Font("Arial", 8)
Dim myBrush As New SolidBrush(Color.Black)
e.Graphics.DrawString("相交 = "contained.ToString(), myFont, myBrush, New PointF(20, 260)) '输出结果
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
yuanxin.X= 1
Me.Refresh()
End Sub
vb.net中 如何改变button控件的形状vb.net中控件都是矩形的,如果一定要看起来是其他形状的,只能用背景图片,一般要三个背景图片 , 正常时候、鼠标移上时候、按下时候的 。分别在按钮的四个事件:MouseHover MouseLeave MouseDown MouseUp的时候更换成相应的背景图片
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.Width1, c.Height1)
Next
If (down.X0) Then e.Graphics.DrawRectangle(New Pen(Color.Gray) With {.DashStyle = Drawing2D.DashStyle.DashDot}, rect)
End Sub
End Class
vb.net可以画复杂图形吗? 就是确定好图形的形状 然后像画图 或者word中图形画三角形 矩形可以画 。基本vb.net多个矩形的形状 vb.net都是支持vb.net多个矩形的 。
谁知道怎么用VB.NET编写一个算长方形面积的程序?dim a as single=...'自己输入长方形的长
dim b as single=...'自己输入长方形的宽
dim c as single=a*b'计算面积
textbox1.text=c'显示面积
vb.net怎样改变picturebox控件的形状'我给你找到了,设置region属性就可
Private Sub PictureBox1_DoubleClick(sender As System.Object, e As System.EventArgs) Handles PictureBox1.DoubleClick
If PictureBox1.Region Is Nothing Then
Dim path As New System.Drawing.Drawing2D.GraphicsPath
path.AddEllipse(0, 0, 200, 200)
PictureBox1.Region = New Region(path)
Else
PictureBox1.Region = Nothing
End If
End Sub
'这个双击图片框使其变形,通过GraphicsPath对象可以作出各种形态来,比如可作出文字形状
【vb.net多个矩形 vbnet gridview】Dim stringText As String = "我是谁"
Dim family As New FontFamily("Arial")
Dim myfontStyle As Integer = CInt(FontStyle.Italic)
Dim emSize As Integer = 86
Dim origin As New Point(20, 20)
Dim format As StringFormat = StringFormat.GenericDefault
path.AddString(stringText, family, myfontStyle, emSize, _
origin, format)
PictureBox1.Region = New Region(path)
关于vb.net多个矩形和vbnet gridview的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。
推荐阅读
- 抖音上怎么开视频直播,抖音上怎么开视频直播教程
- 会计信息系统心得体会erp,会计信息系统心得体会300字
- 飞行上下躲避游戏,飞机躲避游戏
- 虎牙隆战直播,虎牙直播秦隆
- mysql自动时间怎么设 mysql自动记录修改时间
- css线条颜色怎么用,css画一条横线
- 电视端怎么登录会员,在电视上如何登录会员
- 安卓手机如何合并分区,安卓手机如何合并分区内存
- 包含windows云重装系统的词条