网站建设资讯

NEWS

网站建设资讯

vb.net获取坐标,vb获取鼠标坐标

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

创新互联成立与2013年,先为友谊等服务建站,友谊等地企业,进行企业商务咨询服务。为友谊企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

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.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 '声明转换要用到的变量

GetCursorPos(P) '获取鼠标在屏幕中的位置

ScreenToClient(Me.Handle.ToInt32, P) '转换为本窗体的坐标

xx = P.x.ToString '把X转换成能显示到文本框的字符串格式

yy = P.y.ToString '把Y转换成能显示到文本框的字符串格式

TextBox1.Text = xx + "和" + yy '文本框的内容为X坐标和Y坐标

End Sub

VB.NET 一次函数求横坐标

不是已经回答了吗?

运行界面如下图:

在对应的文本框里输入对应的坐标值,单击【计算】,结果将显示在下面一个文本框里,完整代码如下:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim x2, y2, x3, y3, x4, y4, x5, y5 As Single

Dim L As Single

x2 = Val(TextBox2.Text)

y2 = Val(TextBox3.Text)

x3 = Val(TextBox4.Text)

y3 = Val(TextBox5.Text)

x4 = Val(TextBox6.Text)

y4 = Val(TextBox7.Text)

'求点P3(x3,y3)与点P4(x4,y4)的直线方程;

'(X-x4)/(x3-x4) = (Y-y4)/(y3-y4) ......(1)

'求过点P2(x2,y2)的水平直线方程为;

'Y = y2 ......(2)

'方程(1)(2) 联立可以求出两条直线的交点(x5,y5)

'由此得到交点坐标为:

x5 = (y2 - y3) * (x4 - x3) / (y4 - y3) + x3

y5 = y2

'求点P2(x2,y2)与点P5(x5,y5)之间的距离

'根据两点之间距离公式有;

L = ((x2 - x5) ^ 2 + (y2 - y5) ^ 2) ^ 0.5

TextBox1.Text = L

End Sub

End Class

VB.NET 坐标查找问题

代码就不写了,给你思路,默认左上角是原点,所以x的位置=窗口高度-y.

这样就获得xy

复杂点的办法是重写绘制,绘制十字,

简单点的办法就是十字放到picbox或者image里,然后取中,然后隐藏,确定按钮点击显示,中心位置等于坐标点,然后换算左上角控件位置,然后设置坐标.


文章标题:vb.net获取坐标,vb获取鼠标坐标
分享链接:http://cdweb.net/article/dssjihj.html