C# Display a tooltip on disabled textbox (Form)

前端 未结 3 1672
野性不改
野性不改 2020-12-19 11:38

I am trying to get a tooltip to display on a disabled textbox during a mouse over. I know because the control is disabled the following won\'t work:

private          


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-19 11:51

    MouseHover wont fire if control is disabled. Instead you can check in Form MouseMove event whether you hover the textbox

        public Form1()
        {
            InitializeComponent();
            textBox1.Enabled = false;
            toolTip.InitialDelay = 0;
        }
    
        private ToolTip toolTip = new ToolTip();
        private bool isShown = false;
    
        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if(textBox1 == this.GetChildAtPoint(e.Location))
            {
                if(!isShown)
                {
                    toolTip.Show("MyToolTip", this, e.Location);
                    isShown = true;
                }
            }
            else
            {
                toolTip.Hide(textBox1);
                isShown = false;
            }
        }
    

    enter image description here

提交回复
热议问题