vb.net中GetClientRect()函数的问题对不起vb.netrect,vb.netrect我没有学过vb.netvb.netrect , 但是学过vb,希望这个可以
解决您程序的毛病 。首先您注意以下两种GetClientRect
声明的方法vb.netrect:
Option Explicit
Private Declare Function GetClientRect Lib "user32" ( _
ByVal hwnd As Long, _
ByRef lpRect As RECT _
) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Form_Load()
Dim r As RECT
Me.AutoRedraw = True
GetClientRect Me.hwnd, r
Print r.Left
Print r.Right
Print r.Top
Print r.Bottom
End Sub
----------------------------------------------------------------------------
Option Explicit
Private Declare Function GetClientRect Lib "user32" ( _
ByVal hwnd As Long, _
ByVal lpRect As Long _
) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Form_Load()
Dim r As RECT
Me.AutoRedraw = True
GetClientRect Me.hwnd, VarPtr(r)
Print r.Left
Print r.Right
Print r.Top
Print r.Bottom
End Sub
看出问题了没有 , 就在GetClientRect的第二个参数上:
一个是按地址传递,另一个是按值传递:
ByRef lpRect As RECT 用 GetClientRect Me.hwnd, r
ByVal lpRect As Long 用 GetClientRect Me.hwnd, VarPtr(r)
据我所知vb.net按值传递的比较多,应该用VarPtr获取RECT类型
(结构体)的指针,然后传递 。
希望能对你有所帮助 。
VB.NET我要用鼠标轨迹画一个矩形框 然后选中控件 。就像星际和魔兽争霸里对部队单位的选中一样~等大神回答这个类继承自Panelvb.netrect , 把它加到vb.netrect你vb.netrect的项目里面vb.netrect,先运行一下,然后从工具箱里把它拖到窗体上,然后再向里面添加其它控件就可以vb.netrect了,支持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()
【vb.netrect的简单介绍】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)
推荐阅读
- 安卓倒车全景影像app,安卓倒车影像软件
- mysql的存储过程如何调用,mysql的存储过程如何调用数据
- win2012安装.net4.0,win2012安装密钥
- cpu后面es是什么,cpu后面的xe字母是什么意思
- 提取数据怎么存mysql mysql提取数据语句
- 昆明微信小程序注册,昆明微信小程序开发公司联系方式
- 小鸡模拟器和啪啪游戏厅哪个好,小鸡模拟器和ppsspp哪个好用
- 带货第一名衣服直播主播,带货第一名衣服直播主播怎么说
- php查询数据条数函数 php查询数据条数函数怎么写