子类化Button[Control.OnMouseMove 方法]

17 篇文章 0 订阅
8 篇文章 0 订阅

下面的代码示例演示如何重写派生类中的 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);
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值