#encoding: utf-8
import wx
import os
import noname class Frame( noname.MyFrame1 ):
def __init__(self,parent):
noname.MyFrame1.__init__(self,parent)
self.curBitmap = None
self.curBitmapPostion = None
self.curPointerPos = None
def m_createBitmap_buttonOnButtonClick ( self,event ):
event.Skip()
def m_bitmap1OnLeftDown ( self,event ):
self.curBitmapPostion = self.m_bitmap1.GetPosition()
self.curPointerPos = event.GetPosition()
event.Skip()
def m_bitmap1OnMotion ( self,event ):
if event.Dragging() and event.LeftIsDown() :
pos = event.GetPosition() - self.curPointerPos
self.curBitmapPostion += pos
statusVal = 'X = %d Y = %d' %(self.curBitmapPostion.x,self.curBitmapPostion.y)
self.m_statusBar1.SetStatusText(statusVal)
self.m_bitmap1.Move(self.curBitmapPostion)
event.Skip()

实现的功能是在panel上创建一个staticBitmap,然后可以用鼠标在panel上任意随鼠标拖动staticBitmap。

实际上可以拖动任意控件。

思路:

监听staticBitmap(被拖动控件)的wx.EVT_MOTION,和wx.EVT_LEFT_DOWN 事件。

当鼠标左键在staticBitmap上按下是记录此刻:

1,鼠标的位置(event.GetPosition() 这是相对坐标,而且是相对监听控件的(这里监听它的是staticBitmap))。

2,staticBitmap(被拖动控件)的位置(staticBitmap的GetPosition() 返回的是控件左上角相对父控件的位置)。

鼠标的位置是用来计算偏移的,staticBitmap的位置加上这个偏移就是被拖动的位置。

调用staticBitmap的Move(Point),将控件移动到相对父控件的。

碰到的一些问题:

1,并不是所有的event,调用Skip() 后都传递给父控件。下面链接有解答。

http://stackoverflow.com/questions/11606068/about-event-skip,

2,一开始是监听panel的wx.EVT_MOTION,但是鼠标一放到staticBitmap上,panel就监听不到这个事件了。上面链接提到了

wx.PostEvent(staticBitmap(被拖动控件).GetParent(),event),本来想把事件post给panel,这样panel来计算鼠标偏移,这样更准确,不会有闪烁的情况。但是post成功了,但是panel里面触发了这个事件,但是event.GetPosition() 依然是相对staticBitmap(被拖动控件)的,而不是相对panel(父控件)的,虽然事件触发了。

最新文章

  1. SQL转换全角/半角函数
  2. dubbo服务自动化测试搭建
  3. javascript_this的用法
  4. Direct3D学习笔记 - 浅析HDR Lighting Sample
  5. HTML基础(1)
  6. 解决Ubuntu输入正确密码后无法进入桌面,一直停留在登陆界面的问题
  7. hdu 4647 - Another Graph Game(思路题)
  8. 验证整数、小数、实数、有效位小数最简单JavaScript正则表达式
  9. Android核心分析之十五Android输入系统之输入路径详解
  10. 新颖的O2O商业模式,江水平和他的装修队
  11. jquery hide() show()
  12. QTabWidget 实现类似QQ聊天窗口(拖动分离出新的窗口)
  13. c# 用正则表达式在指定的字符串中每隔指定个数的文字插入指定字符串
  14. MySQL中间件Atlas安装及使用
  15. tensorflow ckpt文件转caffemodel时遇到的坑
  16. 远程window服务器,无法复制粘贴了
  17. MySQL(三)
  18. react~props和state的介绍与使用
  19. visual studio 的git插件推荐
  20. pip3 install mysqlclient 报错 “/bin/sh: 1: mysql_config: not found”的解决方法

热门文章

  1. 简单的Datatable转List,Json
  2. Microsoft Azure Preview portal 以及Preview Features介绍
  3. 拥抱ARM妹纸第二季 之 第三次 给我变个月亮,让约会更浪漫!
  4. Teradata 的rank() 和 row_number() 函数
  5. js 前加分号和感叹号是什么意思?
  6. PIGCMS提示“你的程序为盗版,非法授权,请联系QQ7530782或者8441010”的修复方法
  7. 网络笔记01-3 socket 实现百度页面的两种方式
  8. ASP.NET Web – AJAX 回送
  9. linux第四周作业
  10. python pip和easy_install使用方式(转载)