自定义控件的学习日志(Pro.NET2.0 Windows Forms and Custom Controls)

控件设计时鼠标的控制

  1. ControlDesigner.OnPaintAdornments,在控件设计时可以在控件上进行绘制,如下代码所示,当控件在设计时鼠标移入则在控件上画一矩形边框

         private bool mouseOver;
        protected override void OnMouseEnter()
        {
            base.OnMouseEnter();
            mouseOver = true;
            Control.Invalidate();
        }
        protected override void OnMouseLeave()
        {
            base.OnMouseLeave();
            mouseOver = false;
            Control.Invalidate();
        }
        protected override void OnPaintAdornments(System.Windows.Forms.PaintEventArgs pe)
        {
            base.OnPaintAdornments(pe);

            if (mouseOver)
            {
                pe.Graphics.DrawRectangle(pen, 0, 0, Control.Width - 1, Control.Height - 1);
            }
        }

      2.ControlDesigner.SelectionRules用于控制控件在设计是是否可以改变大小等,如下代码:

        public override System.Windows.Forms.Design.SelectionRules SelectionRules
        {
            get
            {
                return System.Windows.Forms.Design.SelectionRules.LeftSizeable | System.Windows.Forms.Design.SelectionRules.Moveable;
            }
        }
       含义为控件是设计时可以从左侧改变大小,并且是可移动的

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值