vb.net网格状轨迹 winform网格布局

VB.net绘制可缩放的网格坐标的相关问题你用CreateGraphics方法的吧 , 这是临时的Graphics,只要你把窗口拉出屏幕或者有其他的对话框遮挡,里面的内容就会立即重画,而CreateGraphics是临时的 , 所以不会再为你画了 。有两种方法,第一是重写重画事件Paint,第二当作图片放入pictureBox里(其实pictureBox也是重写Paint事件的)
很清楚可以看到,蓝色的是DrawLines,红色的和绿色的是画椭圆,至于捕获,是重写了MouseMove事件的,在这个事件里进行算法计算,算出对应的点,然后激活Paint事件 。
VB.NET我要用鼠标轨迹画一个矩形框 然后选中控件 。就像星际和魔兽争霸里对部队单位的选中一样~等大神回答这个类继承自Panelvb.net网格状轨迹,把它加到你的项目里面vb.net网格状轨迹 , 先运行一下vb.net网格状轨迹,然后从工具箱里把它拖到窗体上,然后再向里面添加其它控件就可以vb.net网格状轨迹了 , 支持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)
【vb.net网格状轨迹 winform网格布局】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.X0) Then e.Graphics.DrawRectangle(New Pen(Color.Gray) With {.DashStyle = Drawing2D.DashStyle.DashDot}, rect)
End Sub
End Class
vb.net的dbgrid控件的网格线该如何设置1.DataGrid 控件是一种类似于电子数据表的绑定控件,可以显示一系列行和列来表示 Recordset 对象的记录和字段 。可以使用 DataGrid 来创建一个允许最终用户阅读和写入到绝大多数数据库的应用程序 。DataGrid 控件可以在设计时快速进行配置,只需少量代码或无需代码 。当在设计时设置了DataGrid 控件的 DataSource 属性后,就会用数据源的记录集来自动填充该控件,以及自动设置该控件的列标头 。然后您就可以编辑该网格的列;删除、重新安排、添加列标头、或者调整任意一列的宽度 。

推荐阅读