社区
C#
帖子详情
在自定义类中自动响应鼠标(移动或单击)
jjjy
2003-12-18 09:09:34
如题:
类似VC的相应鼠标消息???
怎么做
...全文
87
9
打赏
收藏
在自定义类中自动响应鼠标(移动或单击)
如题: 类似VC的相应鼠标消息??? 怎么做
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
9 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
jjjy
2003-12-18
打赏
举报
回复
现在就是不知道基类中
有关鼠标移动的处理函数
应该怎么写,
比如 处理移动图形对象的操作
有人能举个例子吗
看 wangj2001(乡村酒吧)
知道
GetCursorPos 可以获取鼠标点的位置
SetCursorPos 可以设置鼠标点的位置
很有用
jjjy
2003-12-18
打赏
举报
回复
我的基类是自己写的
定义的都是图形元素
继承类都是 像:线,多边形,园,曲线等 矢量图形元素
应该不能像 Edelweissobject(青山绿水) 说的那样做吧...
angxain
2003-12-18
打赏
举报
回复
UP
jjjy
2003-12-18
打赏
举报
回复
学习中...
Edelweissobject
2003-12-18
打赏
举报
回复
楼主我觉得你可以把自定义的类从一个类派生出来,由于基类已经具有响应鼠标(在窗口或类对象本身 上移动,单击等)消息,如果你有特殊要求就重写基类事件就可了!象下面的例子:
public class Show:System.Windows.System.Windows.Forms.Panel//基类
{
//string strContext;
public Show()
{
}
protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
{
// TODO: 添加 Show.OnMouseMove 实现
base.OnMouseMove (e);
}
protected override void OnClick(EventArgs e)
{
// TODO: 添加 Show.OnClick 实现
base.OnClick (e);
}
}
DangerousWang
2003-12-18
打赏
举报
回复
学习
jjjy
2003-12-18
打赏
举报
回复
类似与VC中的
响应鼠标(在窗口或类对象本身 上移动,单击等)消息?
在自己定义的类库中该怎么做?
可以实现吗
wangj2001
2003-12-18
打赏
举报
回复
namespace ClassLibrary.Hardware
{
// Using C# and Win32API
public class Mouse
{
internal const byte SM_MOUSEPRESENT = 19;
internal const byte SM_CMOUSEBUTTONS = 43;
internal const byte SM_MOUSEWHEELPRESENT = 75;
internal struct POINTAPI
{
internal int x;
internal int y;
}
internal struct RECT
{
internal int left ;
internal int top ;
internal int right ;
internal int bottom ;
}
[System.Runtime.InteropServices.DllImport("user32.dll" , EntryPoint="SwapMouseButton")]
internal extern static int SwapMouseButton ( int bSwap );
[System.Runtime.InteropServices.DllImport("user32" , EntryPoint="ClipCursor")]
internal extern static int ClipCursor(ref RECT lpRect);
[System.Runtime.InteropServices.DllImport( "user32.dll" , EntryPoint="GetCursorPos" )]
internal extern static int GetCursorPos( ref POINTAPI lpPoint );
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint="ShowCursor")]
internal extern static bool ShowCursor ( bool bShow ) ;
[System.Runtime.InteropServices.DllImport( "user32.dll" , EntryPoint = "EnableWindow" )]
internal extern static int EnableWindow( int hwnd , int fEnable );
[System.Runtime.InteropServices.DllImport("user32.dll" , EntryPoint="GetWindowRect")]
internal extern static int GetWindowRect( int hwnd , ref RECT lpRect ) ;
[System.Runtime.InteropServices.DllImport("user32.dll" , EntryPoint="SetCursorPos")]
internal extern static int SetCursorPos ( int x , int y ) ;
[System.Runtime.InteropServices.DllImport("user32.dll" , EntryPoint="GetSystemMetrics")]
internal extern static int GetSystemMetrics( int nIndex );
[System.Runtime.InteropServices.DllImport("user32.dll" , EntryPoint="SetDoubleClickTime")]
internal extern static int SetDoubleClickTime ( int wCount );
[System.Runtime.InteropServices.DllImport("user32.dll" , EntryPoint="GetDoubleClickTime")]
internal extern static int GetDoubleClickTime() ;
[System.Runtime.InteropServices.DllImport("kernel32.DLL", EntryPoint="Sleep")]
internal extern static void Sleep ( int dwMilliseconds ) ;
//得到鼠标相对与全屏的坐标,不是相对与你的Form的,且与你的分辨率有关系
public static int FullScreenPosition_X
{
get
{
POINTAPI _POINTAPI = new POINTAPI();
GetCursorPos ( ref _POINTAPI );
return _POINTAPI.x;
}
}
public static int FullScreenPosition_Y
{
get
{
POINTAPI _POINTAPI = new POINTAPI();
GetCursorPos ( ref _POINTAPI );
return _POINTAPI.y;
}
}
// 隐藏 显示 鼠标
public static void Hide()
{
ShowCursor( false ) ;
}
public static void Show()
{
ShowCursor( true ) ;
}
// 将鼠标锁定在你的Form里 不过你得将你的Form先锁了,Form Resize 就失效了
public static void Lock( System.Windows.Forms.Form ObjectForm )
{
RECT _FormRect = new RECT ();
GetWindowRect( ObjectForm.Handle.ToInt32() , ref _FormRect );
ClipCursor( ref _FormRect );
}
public static void UnLock()
{
RECT _ScreenRect = new RECT ();
_ScreenRect.top = 0;
_ScreenRect.left = 0;
_ScreenRect.bottom = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Bottom;
_ScreenRect.right = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right;
ClipCursor( ref _ScreenRect );
}
// 鼠标失效,不过失效的好像不只是鼠标,小心哦
public static void Disable( System.Windows.Forms.Form ObjectForm )
{
EnableWindow( ObjectForm.Handle.ToInt32() , 0 ) ;
}
public static void Enable( System.Windows.Forms.Form ObjectForm )
{
EnableWindow( ObjectForm.Handle.ToInt32() , 1 ) ;
}
// 鼠标自己移动 很想动画哦 参数是2个控件的handle
// 看这个方法前,先用凉水擦把脸。。。 反正我写的时候 头晕
public static void Move ( int From_Handle_ToInt32 , int To_Handle_ToInt32 )
{
RECT rectFrom = new RECT () ;
RECT rectTo = new RECT () ;
int i ;
GetWindowRect( From_Handle_ToInt32 , ref rectFrom ) ;
GetWindowRect( To_Handle_ToInt32 , ref rectTo ) ;
if ( ( rectFrom.left + rectFrom.right ) / 2 - ( rectTo.left + rectTo.right ) / 2 > 0 )
{
for ( i = ( rectFrom.left + rectFrom.right ) / 2 ; i >= ( rectTo.left + rectTo.right ) / 2 ; i-- )
{
SetCursorPos ( i , ( rectFrom.top + rectFrom.bottom ) / 2) ;
Sleep ( 1 ) ;
}
}
else
{
for ( i = ( rectFrom.left + rectFrom.right ) / 2 ; i <= ( rectTo.left + rectTo.right ) / 2 ; i++ )
{
SetCursorPos ( i , ( rectFrom.top + rectFrom.bottom ) / 2) ;
Sleep ( 1 ) ;
}
}
if ( ( rectFrom.top + rectFrom.bottom ) / 2 - ( rectTo.top + rectTo.bottom ) / 2 > 0 )
{
for ( i = ( rectFrom.top + rectFrom.bottom ) / 2 ; i >= ( rectTo.top + rectTo.bottom ) / 2 ; i-- )
{
SetCursorPos ( ( rectTo.left + rectTo.right ) / 2 , i ) ;
Sleep ( 1 ) ;
}
}
else
{
for ( i = ( rectFrom.top + rectFrom.bottom ) / 2 ; i <= ( rectTo.top + rectTo.bottom ) / 2 ; i++ )
{
SetCursorPos ( ( rectTo.left + rectTo.right ) / 2 , i ) ;
Sleep ( 1 ) ;
}
}
}
// 得到你的鼠标类型
public static string Type
{
get
{
if ( GetSystemMetrics( SM_MOUSEPRESENT ) == 0 )
{
return "本计算机尚未安装鼠标" ;
}
else
{
if ( GetSystemMetrics( SM_MOUSEWHEELPRESENT ) != 0 )
{
return GetSystemMetrics( SM_CMOUSEBUTTONS ) + "键滚轮鼠标" ;
}
else
{
return GetSystemMetrics( SM_CMOUSEBUTTONS ) + "键鼠标" ;
}
}
}
}
// 设置鼠标双击时间
public static void DoubleClickTime_Set( int MouseDoubleClickTime )
{
SetDoubleClickTime( MouseDoubleClickTime );
}
public static string DoubleClickTime_Get()
{
return GetDoubleClickTime().ToString() ;
}
// 设置鼠标默认主键 我是没有见过谁左手用鼠标
public static void DefaultRightButton()
{
SwapMouseButton ( 1 ) ;
}
public static void DefaultLeftButton()
{
SwapMouseButton ( 0 ) ;
}
}
}
polarlm
2003-12-18
打赏
举报
回复
还是不太懂楼主的意思
自定义
的QGraphicsItem类无法
响应
鼠标
移动
事件
自己重写了一个类,继承自QGraphicsItem类,然后我想重写 mouseMoveEvent(QGraphicsSceneMouseEvent *event); 函数,来捕捉
鼠标
移动
事件,从而实现实时显示item上光标所在位置的的坐标。 结果
鼠标
移动
的时候...
PyQt5
鼠标
点击事件(点击
响应
事件可
自定义
):
鼠标
单击
、双击、滚轮滚动、释放、
移动
等
自己写通了最常用的
鼠标
事件,具体
响应
事件,大家可以
自定义
,实现的效果如下: 具体代码如下,有任何问题,欢迎小伙伴们交流讨论。 # -*- coding: utf-8 -*- """ Created on Fri Apr 26 20:49:32 2019 @...
GMap
鼠标
拖拽与
单击
冲突问题以及按下
鼠标
移动
Marker
GMap
鼠标
拖拽与
单击
冲突问题以及按下
鼠标
移动
Marker好久没有写博客啦,之前写了三篇关于GMap的,还是想继续写下去,在之前的基础之上本篇博客就解决两个问题吧: 我们在使用
鼠标
拖拽地图时,拖拽完成后,抬起
鼠标
...
qt
自定义
鼠标
单击
事件标签QLabel
qt自带的QLabel被
单击
的时候,不会发送出被
单击
的信号signal。
QCustomPlot的使用之四-
响应
鼠标
移动
和弹起事件
在项目中使用QCustomPlot过程中,会有新的需求需要满足,比如在显示的数据表格中,
鼠标
移动
到数据线上的时候,需要实时显示当前显示的线上点的具体数据;点击这条线的时候,弹出对话框展现出数据线段的详细信息。 ...
C#
110,545
社区成员
642,580
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章