vb.net 2008
我們提供的服務(wù)有:成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、微信公眾號(hào)開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、輪臺(tái)ssl等。為上千企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的輪臺(tái)網(wǎng)站制作公司
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a_Point, b_Point, c_point As Point
b_Point = MousePosition '鼠標(biāo)點(diǎn)擊坐標(biāo)(屏幕上的屏幕坐標(biāo))
a_Point = PointToClient(MousePosition) 'vb.net中的窗體坐標(biāo)
c_point = PointToScreen(a_Point) '將vb.net中的窗體坐標(biāo)轉(zhuǎn)換成屏幕上的屏幕坐標(biāo)
End Sub
End Class
Private Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As POINTAPI) As Long '全屏坐標(biāo)聲明
Private Declare Function ScreenToClient Lib "user32.dll" (ByVal hwnd As Int32, ByRef lpPoint As POINTAPI) As Int32 '窗口坐標(biāo)聲明
Private Structure POINTAPI '聲明坐標(biāo)變量
Public x As Int32 '聲明坐標(biāo)變量為32位
Public y As Int32 '聲明坐標(biāo)變量為32位
End Structure
'以上是聲明部分
'以下是窗口部分
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick '用時(shí)鐘控件來取坐標(biāo),窗口上放個(gè)Timer組件,Enabled為允許,周期為10到100毫秒均可
Dim P As POINTAPI '聲明坐標(biāo)變量
Dim xx, yy '聲明轉(zhuǎn)換要用到的變量
GetCursorPos(P) '獲取鼠標(biāo)在屏幕中的位置
ScreenToClient(Me.Handle.ToInt32, P) '轉(zhuǎn)換為本窗體的坐標(biāo)
xx = P.x.ToString '把X轉(zhuǎn)換成能顯示到文本框的字符串格式
yy = P.y.ToString '把Y轉(zhuǎn)換成能顯示到文本框的字符串格式
TextBox1.Text = xx + "和" + yy '文本框的內(nèi)容為X坐標(biāo)和Y坐標(biāo)
End Sub
Dim g As Graphics = PictureBox1.CreateGraphics
g.TranslateTransform(2, 2) ‘定義原點(diǎn)坐標(biāo)
g.ScaleTransform(1, -1) ’X軸不變,反轉(zhuǎn)Y軸
以PictureBox1中(2,2)點(diǎn)為新的原點(diǎn)(0,0)
向右為X軸正方向 向上為Y軸正方向