控件在父窗体或屏幕中的绝对坐标
来源:互联网 发布:js获取扫描枪的数据 编辑:程序博客网 时间:2024/06/07 20:08
做了一个控件,这个控件中鼠标移到某个Label上,出现一个panel,然后鼠标从label上移走或是从这个panel上移走该panel就消失。
这中间遇到了两个问题:
1、这个panel位置的问题。
用 this.FindForm().Controls.Add(panel);加该panel。但是Location的时候有问题了,panel.Location=new Point(Label.Location.X,Label.Lcation.Y);结果这个控件的Label位置是(0,0),加的时候就加到了最外层窗体的(0,0)了。于是查到了绝对坐标。换成:
Point p = Label.PointToScreen(this.FindForm().Location);p.Y += Label.Height;panel.Location = p;
就可以了。
但是这样还有另一个问题,就是当主窗体还原或者改变大小了,这个panel的位置有不正常了,因此改成:
Point p = Label.PointToScreen(new Point(0, 0));p.Y += Label.Height;Point p1 = this.FindForm().PointToScreen(new Point(0, 0));p.X -= p1.X;p.Y -= p1.Y; panel.Location = p;
这样主窗体无论位置是不是0,panel的位置就在label的位置上。
2、计算鼠标是否在panel内。
Rectangle rect = panel.Bounds; int x =MousePosition.X - this.FindForm().Left; int y = MousePosition.Y - this.FindForm().Top; if (x <= rect.Left || x >= rect.Right || y <= rect.Top || y >= rect.Bottom) { //鼠标不在panel内 }else { //鼠标在panel内。 }
- 控件在父窗体或屏幕中的绝对坐标
- android获得控件在屏幕中的绝对坐标
- android获得控件在屏幕中的绝对坐标
- Android获得控件在屏幕中的绝对坐标
- android获得控件在屏幕中的绝对坐标
- android获得控件在屏幕中的绝对坐标
- android获得控件在屏幕中的绝对坐标
- android获得控件在屏幕中的绝对坐标
- android获得控件在屏幕中的绝对坐标
- Android获得控件在屏幕中的绝对坐标
- android获得控件在屏幕中的绝对坐标
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- Android中的任务和进程详解
- 如何在Rational ClearQuest客户端中隐藏操作
- 设计模式分类
- 根据IP地址查询其所属城市
- 用Javac一次性编译多个包下的Java文件
- 控件在父窗体或屏幕中的绝对坐标
- vbox虚拟机安装Windows8方法及注意事项
- oracle创建序列
- 计算所招收2012年推荐免试生工作日程安排
- 百度笔试题:malloc/free与new/delete的区别
- 匈牙利命名法扩展
- 最全的编码总结笔记
- ITF跆拳道中的基本腿法(图文)
- ckeditor 在C#中使用