动态判断这个按钮在显示器窗口的位置和范围,如果鼠标在这个位置范围里面,则是指向了这个按钮,变为绿色,如果不在这个范围里面,则显示红色,点击就很简单了,看vb6源码,调试通过:
'=========================================================
'说明,注意,label1控件的高度需要自己事前设置好,大概是标题栏到底部的高度,再用窗体的高度减去label1空间的高度就是标题栏的高度了,如果
'需要动态修改窗体的高度,则要自己动态修改label1的高度,timer1控件设置20ms,自己看着理解了就好修改了
Dim cmd_x As Long, cmd_y As Long, cmd_width As Long, cmd_height As Long
Dim form_x As Long, form_y As Long
Dim total_x As Long, total_y As Long
Dim mouse_x As Long, mouse_y As Long '鼠标的位置
Dim color_flage As Integer '0-不在按钮范围内,1-在按钮范围内但是没有点击按钮,2-在按钮范围内点击了按钮
'============
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Dim p As POINTAPI
Private Sub Label2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
color_flage = 2 '按下标志
End If
End Sub
Private Sub Label2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 0 Then'为0是没有点击鼠标键
MeLabel2BackColor = &HFF00& '绿色
color_flage = 1 '在按钮范围但是没有按下按钮标志
End If
End Sub
Private Sub Label2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
color_flage = 1 '按下标志
End If
End Sub
Private Sub Form_Load()
total_x = ScreenWidth '显示器的分辨率
total_y = ScreenHeight
'MeLabel2Style = 1 '按钮样式,设置1才能改颜色,需要手动修改此属性
End Sub
Private Sub Timer1_Timer()
GetCursorPos p
mouse_x = pX
mouse_y = pY
form_x = Int(MeLeft / 15 + 05) '动态调整时的位置
form_y = Int(MeTop / 15 + 05)
cmd_x = Int(MeLabel2Left / 15 + 05) + form_x '按钮坐标
cmd_y = Int(MeLabel2Top / 15 + 05) + form_y + Int((MeHeight - MeLabel1Height) / 15 + 05) '要加上标题栏的高度
cmd_width = Int(MeLabel2Width / 15 + 05) '范围
cmd_height = Int(MeLabel2Height / 15 + 05)
If (mouse_x < cmd_x) Or (mouse_x > (cmd_x + cmd_width)) Then 'x方向范围
color_flage = 0 '不在按钮范围标
End If
If (mouse_y < cmd_y) Or (mouse_y > (cmd_y + cmd_height)) Then 'y方向范围
color_flage = 0 '不在按钮范围标志
End If
If color_flage = 0 Then MeLabel2BackColor = &HFF& '红色
If color_flage = 1 Then MeLabel2BackColor = &HFF00& '绿色
If color_flage = 2 Then MeLabel2BackColor = &HFFFF& '**
End Sub
稍等上代码!!
<html><head>
<script type="text/javascript">
function show_coords(event){
var x = eventclientX;
var y = eventclientY;
var say = documentall("coords");
sayinnerHTML = "X:"+x+" Y:"+y;
saystyleposition = "absolute";
saystyleleft = x + 30;
saystyletop = y;
}
</script>
</head>
<body onmousemove="show_coords(event)">
<p id="coords"></p>
</body>
<html>
希望我的回答对你有用,有用就采纳!!!谢谢!
NOKIA的非S60机子真的非常不人性化 S60与S40的区别很大,有点难形容 S60真的可以做到很多很多,而S40有局限性 即使5310和6120价钱差不多,但是我还是选择了6120 6120不仅强大,而且不像5310那样靠时尚音乐这个噱头而赢得掌声的 6120掉漆的话多多少少会有点,不过我的只是在导航键那里而已,我觉得完全可以自己涂点东西解决。通话音量是可以调节的,我并不觉得小 还有,5310的电池很小,不耐用
public class GetMousePos : MonoBehaviour
{
public Canvas canvas;//画布
private RectTransform rectTransform;//坐标
void Start()
{
canvas = GameObjectFind("Canvas")GetComponent<Canvas>();
rectTransform = canvastransform as RectTransform; //也可以写成thisGetComponent<RectTransform>(),但是不建议;
}
void Update()
{
if (InputGetMouseButtonDown(0))
{
Vector2 pos;
if (RectTransformUtilityScreenPointToLocalPointInRectangle(rectTransform, InputmousePosition, canvasworldCamera, out pos))
{
rectTransformanchoredPosition = pos;
DebugLog(pos);
}
}
}
}
新建场景,在场景中拖一个画布(Canvas),然后随便找个地方挂上这个脚本就好了。
1
RectTransformUtility:矩阵变换工具
RectTransformUtilityScreenPointToLocalPointInRectangle 从屏幕点到矩形内的本地点
Parameters 参数
rect The RectTransform to find a point inside
cam The camera associated with the screen space position
screenPoint Screen space position
localPoint Point in local space of the rect transform
Returns
bool Returns true if the plane of the RectTransform is hit, regardless of whether the point is inside the rectangle
Description 描述
Transform a screen space point to a position in the local space of a RectTransform that is on the plane of its rectangle
屏幕空间点转换为矩形变换内部的本地位置,该点在它的矩形平面上。
The cam parameter should be the camera associated with the screen point For a RectTransform in a Canvas set to Screen Space - Overlay mode, the cam parameter should be null
该cam 参数应该是该相机关联的屏幕点。对于在画布上的矩形变换设置该屏幕空间为-Overlay模式,cam 参数应该为空。
When ScreenPointToLocalPointInRectangle is used from within an event handler that provides a PointerEventData object, the correct camera can be obtained by using PointerEventDataenterEventData (for hover functionality) or PointerEventDatapressEventCamera (for click functionality) This will automatically use the correct camera (or null) for the given event
当ScreenPointToLocalPointInRectangle从事件处理器内部提供一个PointerEventData对象被使用时,相机可以通过使用PointerEventDataenterEventData(为悬停功能)或者 PointerEventDatapressEventCamera(为单击功能)被获取。该函数将会自动对指定事件使用正确的相机(或者空)。
RectTransform矩形变换
RectTransformanchoredPosition 锚点位置
The position of the pivot of this RectTransform relative to the anchor reference point
该矩形变换相对于锚点参考点的中心点位置。
The anchor reference point is where the anchors are If the anchors are not together, the four anchor positions are interpolated according to the pivot placement
锚点参考点是锚点的位置。如果锚点不在一起,四个锚点的位置是根据布置的中心点的位置插值替换的。
以上就是关于API获取鼠标指针形状全部的内容,包括:API获取鼠标指针形状、js如何获取鼠标在某元素移动时~鼠标指针在元素中的坐标、怎么用JAVA能获取系统当前鼠标指针样式(图案),如果能怎么获取如果不能用C/C++获取也可以等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)