子类化Button[Control.OnMouseMove 方法]
2015-08-22 06:52
295 查看
下面的代码示例演示如何重写派生类中的 OnMouseHover 和 OnMouseMove 方法。 要运行该示例,请将以下代码粘贴到一个新窗体中并将该类粘贴到此窗体的后面,以构成同一个文件。 将一个 FunButton 类型的按钮添加到窗体中。
public class FunButton: Button { protected override void OnMouseHover(System.EventArgs e) { // Get the font size in Points, add one to the // size, and reset the button's font to the larger // size. float fontSize = Font.SizeInPoints; fontSize += 1; System.Drawing.Size buttonSize = Size; this.Font = new System.Drawing.Font( Font.FontFamily, fontSize, Font.Style); // Increase the size width and height of the button // by 5 points each. Size = new System.Drawing.Size(Size.Width+5, Size.Height+5); // Call myBase.OnMouseHover to activate the delegate. base.OnMouseHover(e); } protected override void OnMouseMove(MouseEventArgs e) { // Make the cursor the Hand cursor when the mouse moves // over the button. Cursor = Cursors.Hand; // Call MyBase.OnMouseMove to activate the delegate. base.OnMouseMove(e); } }
相关文章推荐
- Win10预览版10525出现错误代码0x8007232B的原因
- 【LeetCode-面试算法经典-Java实现】【168-Excel Sheet Column Title(Excell列标题)】
- 【LeetCode-面试算法经典-Java实现】【165-Compare Version Numbers(比较版本号)】
- android 应用的网络请求工具
- 【LeetCode-面试算法经典-Java实现】【160-Intersection of Two Linked Lists(单链表的交集)】
- Triangle
- VirtualBox的四种网络接入方式
- C语言的声明
- 浅谈数据挖掘中的关联规则挖掘
- 浅谈WebLogic和Tomcat
- Ugly Number II
- (转载)数据库表分割技术浅析(水平分割/垂直分割/库表散列)
- mysql视图
- mysql视图
- Unity Manual之Network 网络
- linux man命令使用详解
- LeetCode Reverse Linked List II
- LeetCode Reverse Linked List II
- POJ 1188 解题报告
- LeetCode_Surrounded Regions