vb.net 怎样获取鼠标单击点的坐标通过窗体的MouseDown事件的e.X和e.Y属性获取 。通过e.Location属性获取Point类型的坐标 。
下面的代码示例使用 Location 属性跟踪鼠标左键单击,并绘制一系列直线段作为对用户输入的响应 。如果隐藏窗体然后重新显示它 , 此示例不保留已绘制的线段 , 该代码为简单起见而被省略了 。
Dim FirstPoint As Point
Dim HaveFirstPoint As Boolean = False
Sub Form1_MouseDownDrawing(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
If HaveFirstPoint Then
Dim g As Graphics = Me.CreateGraphics()
g.DrawLine(Pens.Black, FirstPoint, e.Location)
HaveFirstPoint = False
Else
FirstPoint = e.Location
HaveFirstPoint = True
End If
End Sub
在VB.net中怎么获取 鼠标在屏幕中的坐标Private Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As POINTAPI) As Long '全屏坐标声明
Private Declare Function ScreenToClient Lib "user32.dll" (ByVal hwnd As Int32, ByRef lpPoint As POINTAPI) As Int32 '窗口坐标声明
Private Structure POINTAPI '声明坐标变量
Public x As Int32 '声明坐标变量为32位
Public y As Int32 '声明坐标变量为32位
End Structure
'以上是声明部分
'以下是窗口部分
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick '用时钟控件来取坐标,窗口上放个Timer组件,Enabled为允许,周期为10到100毫秒均可
Dim P As POINTAPI '声明坐标变量
Dim xx, yy '声明转换要用到vb.net获取窗口坐标的变量
GetCursorPos(P) '获取鼠标在屏幕中vb.net获取窗口坐标的位置
ScreenToClient(Me.Handle.ToInt32, P) '转换为本窗体vb.net获取窗口坐标的坐标
xx = P.x.ToString '把X转换成能显示到文本框的字符串格式
yy = P.y.ToString '把Y转换成能显示到文本框的字符串格式
TextBox1.Text = xx + "和" + yy '文本框的内容为X坐标和Y坐标
End Sub
VB.NET想用GetWindowRECT获取某窗口的坐标,但测试结果是L,T,R,B显示都是0,0,0,0很简单,原因有二 。第一,VB里long是32位,但是VB.NET里是64位,Dim ksWND As Integer才对 。第二,VB在API里默认传址,而VB.NET默认传值,所以API里要添加Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long,添加"ByRef"lpRect As RECT) As Integer
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long,byref lpRect As RECT) As Integer
Private Structure RECT
Dim Left As Integer
Dim Top As Integer
Dim Right As Integer
Dim Bottom As Integer
End Structure
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ksWND As integer
Dim ksTitle As String
Dim winS As RECT
If TextBox1.Text"" Then
ksTitle = TextBox1.Text
ksWND = FindWindow(vbNullString, ksTitle)
GetWindowRect(ksWND, winS)
MsgBox("左上角坐标("winS.Left","winS.Top")"vbCrLf"右下角坐标("winS.Right","winS.Bottom")"vbCrLf"窗口高"winS.Bottom - winS.Top"窗口宽"winS.Right - winS.Left)
Else
MsgBox("请填写窗口名称")
End If
End Sub
VB怎么获取当前活动窗口的坐标?'在窗体上画一个Timer控件,设置其Interval属性为100
'把代码复制到Form1的代码窗口中
'获得活动窗口句柄的API
Private
Declare
Function
GetForegroundWindow
Lib
"user32"
()
As
Long
'获得窗口区域结构的API
Private
Declare
Function
GetWindowRect
Lib
"user32"
(ByVal
推荐阅读
- 斗鱼直播期限,斗鱼直播延迟多久
- net文件安装,net 安装
- 老村长如何营销,老村长如何营销活动
- redis在php中怎么使用情况,php redis incr
- linux定制命令 linux自定义命令执行脚本
- js取对象可以吗,js 对象内获取一个属性的值
- 投币射击游戏机,投币游戏机大全
- 怪兽格斗进化游戏视频,怪兽格斗下载安装
- case函数c语言 c语言case调用函数用法