我写了一个控件,继承UserControl
public class PreviewCurvePanelControl : UserControl
然后有一个类变量
private ToolTip toolTipShowData;然后
private void InitializeComponent()
{
    this.components = new System.ComponentModel.Container();
    this.toolTipShowData = new System.Windows.Forms.ToolTip(this.components);
    this.SuspendLayout();
    // 
    // PreviewCurvePanelControl
    // 
    this.Name = "PreviewCurvePanelControl";
    this.ResumeLayout(false);
}//OnMouseDown我写了
protected override void OnMouseDown(MouseEventArgs e)
{
    toolTipShowData.Show("Test", this);
}
//OnMouseMove我也写了
protected override void OnMouseMove(MouseEventArgs e)
{
     if(e.Button==MouseButtons.Left)
         toolTipShowData.Show("Test", this);
}
//OnMouseUp是空的
protected override void OnMouseUp(MouseEventArgs e)
{}
为什么这个toolTip在我鼠标按下去的时候,不show出来...鼠标放开了反而显示出来了...
按下去不放,拖动的时候也会显示tooltip
//如果在这个事件里面写上messagebox
protected override void OnMouseDown(MouseEventArgs e)
{
    toolTipShowData.Show("Test", this);
    messagebox.show("123");
}这样...在鼠标按下去不放的时候会显示messagebox...说明事件的确是处罚了嘛...
为什么那个tooltip就是show不出来???而且,为什么,点着不松,鼠标移出控件再移进来就会显示tooltip

解决方案 »

  1.   

    而最新的测试显示:我只是新建了一个winForm的工程,拖了一个pictureBox上去...然后在这个pictureBox上放了一个ToolTip...Form.cs代码如下:using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
            {
                
                toolTip1.SetToolTip(this.pictureBox1,"5555");
                System.Diagnostics.Debug.Write("ssssssssssss");
                System.Diagnostics.Debug.Flush();
            }
        }
    }
    系统自动生成的Form.Designer.cs就没什么好看的了效果为:
    在Form刚刚构建的时候,第一次点下鼠标不松,是不会显示tip的...
    但是OutPut窗口显示了我的Debug信息...表示事件的确响应了...从第一次以后,再按下鼠标不送就有tip了为什么第一次没有???后面才有呢???
      

  2.   

    再次调试:
    结果更令人费解...程序如下:using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
            {
                ToolTip  test=new ToolTip();
                test.SetToolTip(this.pictureBox1, "88888");
                string s = string.Format("pictureBox1_MouseDown:x:[{0}], y:[{1}]", e.X, e.Y);
                System.Diagnostics.Debug.WriteLine(s);
                if (e.Button == MouseButtons.Left)
                {
                    toolTip1.SetToolTip(this.pictureBox1, "88888");
                    string ss = toolTip1.GetToolTip(pictureBox1);
                    System.Diagnostics.Debug.WriteLine(ss);
                }
                System.Diagnostics.Debug.Flush();
            }        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
            {
                if (string.Empty != toolTip1.GetToolTip(this.pictureBox1))
                {
                    string s = string.Format("pictureBox1_MouseMove:x:[{0}], y:[{1}]", e.X, e.Y);
                    System.Diagnostics.Debug.WriteLine(s);
                }            if (e.Button == MouseButtons.Left)
                {
                    toolTip1.SetToolTip(this.pictureBox1, "77777");
                    string ss = toolTip1.GetToolTip(pictureBox1);
                    System.Diagnostics.Debug.WriteLine(ss);
                }
                System.Diagnostics.Debug.Flush();
            }
        }
    }
    运行结果:依然的在form刚创建显示的时候,按下鼠标不松是不会显示888的...
    第一次按下鼠标松了以后显示888
    然后的每次按下都显示777.....神经了Debug的OutPut信息如下:pictureBox1_MouseDown:x:[96], y:[104]
    88888
    pictureBox1_MouseMove:x:[96], y:[104]
    pictureBox1_MouseMove:x:[96], y:[104]
    pictureBox1_MouseMove:x:[96], y:[104]
    pictureBox1_MouseDown:x:[96], y:[104]
    88888
    pictureBox1_MouseMove:x:[96], y:[104]
    77777
    pictureBox1_MouseMove:x:[96], y:[104]
    pictureBox1_MouseMove:x:[96], y:[104]
    pictureBox1_MouseDown:x:[96], y:[104]
    88888
    pictureBox1_MouseMove:x:[96], y:[104]
    77777
    pictureBox1_MouseMove:x:[96], y:[104]
    pictureBox1_MouseMove:x:[96], y:[104]
    pictureBox1_MouseDown:x:[96], y:[104]
    88888
    pictureBox1_MouseMove:x:[96], y:[104]
    77777
    pictureBox1_MouseMove:x:[96], y:[104]
    pictureBox1_MouseMove:x:[96], y:[104]
    pictureBox1_MouseMove:x:[99], y:[104]可见,我的鼠标根本没移动过...却在每个mousedown以后系统马上给我调mousemove....天呐...我快疯了,,,来个大虾拯救我吧
    1)为什么第一次按下鼠标不送tip不显示
    2)为什么moused以后系统老自动给我调mousemove
      

  3.   

    我快崩溃了using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
            {
                string s = string.Format("pictureBox1_MouseDown:x:[{0}], y:[{1}]", e.X, e.Y);
                System.Diagnostics.Debug.WriteLine(s);
            }        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
            {
                    string s = string.Format("pictureBox1_MouseMove:x:[{0}], y:[{1}]", e.X, e.Y);
                    System.Diagnostics.Debug.WriteLine(s);
            }        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
            {
                string s = string.Format("pictureBox1_MouseUp:x:[{0}], y:[{1}]", e.X, e.Y);
                System.Diagnostics.Debug.WriteLine(s);
            }        private void pictureBox1_MouseEnter(object sender, EventArgs e)
            {
                string s = string.Format("pictureBox1_MouseEnter");
                System.Diagnostics.Debug.WriteLine(s);
            }
        }
    }
    调试信息为:
    pictureBox1_MouseEnter
    pictureBox1_MouseMove:x:[230], y:[158]
    ...省略若干MouseMove...
    pictureBox1_MouseMove:x:[141], y:[158]
    pictureBox1_MouseDown:x:[141], y:[158]
    pictureBox1_MouseUp:x:[141], y:[158]
    pictureBox1_MouseMove:x:[141], y:[158]
    如果加上ToolTip:using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();            //toolTip1.SetToolTip(this.pictureBox1, "5555");
                toolTip1.IsBalloon = true;
                toolTip1.InitialDelay = 0;
                toolTip1.ReshowDelay = 0;
                toolTip1.AutoPopDelay = 0;
            }        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
            {
                string s = string.Format("pictureBox1_MouseDown:x:[{0}], y:[{1}]", e.X, e.Y);
                System.Diagnostics.Debug.WriteLine(s);
                if (e.Button == MouseButtons.Left)
                {                toolTip1.SetToolTip(this.pictureBox1, "88888");
                    string ss = toolTip1.GetToolTip(pictureBox1);
                    System.Diagnostics.Debug.WriteLine(ss);
                }
            }        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
            {
                if (string.Empty != toolTip1.GetToolTip(this.pictureBox1))
                {
                    string s = string.Format("pictureBox1_MouseMove:x:[{0}], y:[{1}]", e.X, e.Y);
                    System.Diagnostics.Debug.WriteLine(s);
                }            if (e.Button == MouseButtons.Left)
                {
                    toolTip1.SetToolTip(this.pictureBox1, "77777");
                    string ss = toolTip1.GetToolTip(pictureBox1);
                    System.Diagnostics.Debug.WriteLine(ss);
                }
            }        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
            {
                string s = string.Format("pictureBox1_MouseUp:x:[{0}], y:[{1}]", e.X, e.Y);
                System.Diagnostics.Debug.WriteLine(s);
            }        private void pictureBox1_MouseEnter(object sender, EventArgs e)
            {
                string s = string.Format("pictureBox1_MouseEnter");
                System.Diagnostics.Debug.WriteLine(s);
            }
        }
    }
    调试就变成了:
    pictureBox1_MouseEnter
    pictureBox1_MouseDown:x:[163], y:[115]
    88888
    pictureBox1_MouseUp:x:[163], y:[115]
    pictureBox1_MouseMove:x:[163], y:[115]
    pictureBox1_MouseMove:x:[163], y:[115]
    pictureBox1_MouseDown:x:[163], y:[115]
    88888
    pictureBox1_MouseMove:x:[163], y:[115]
    77777
    pictureBox1_MouseMove:x:[163], y:[115]
    77777
    ...省略若干同样的MouseMove信息
    pictureBox1_MouseMove:x:[163], y:[115]
    77777
    pictureBox1_MouseUp:x:[163], y:[115]
    pictureBox1_MouseMove:x:[163], y:[115]可见:
    我不显示ToolTip的时候还算正常,要显示ToolTip的时候:
    第一次按下鼠标的流程也还算正常...
    第二次,一按下鼠标...触发了Down以后,我还没Up之前不停的触发Move...难道ToolTip会重置鼠标位置???
      

  4.   

    ToolTip 的效果知道不??
    是需要停顿在上面的,而不是按住鼠标键。
      

  5.   


    谢谢你的提醒...我知道tip的效果是什么但是我需求为:按下按钮tip条显示当前坐标,并跟随鼠标移动体魄内容改变,鼠标松开或移出则tip消失...你觉得不可能做到?
      

  6.   


    谢谢你的提醒...我知道tip的效果是什么但是我需求为:按下按钮tip条显示当前坐标,并跟随鼠标移动体魄内容改变,鼠标松开或移出则tip消失...你觉得不可能做到?
      

  7.   


    谢谢你的提醒...我知道tip的效果是什么但是我需求为:按下按钮tip条显示当前坐标,并跟随鼠标移动体魄内容改变,鼠标松开或移出则tip消失...你觉得不可能做到?
      

  8.   

    总显示777我还没明白,不过不停的显示到是有可能是,你先显示了一个tip
    然后这个显示的tip挡住了你的pictureBox,或者叫间接改变了pictureBox,
    此时鼠标的x,y坐标重新取值,触发了mouse_move。
    当这个tip显示完消失时又再次改变pictureBox,同样再次触发了mouse_move。
    不知道我想的对不对,以前同事在做web的时候碰到这类的事,
    后来是把tip的显示位置离开这个控件的区域就好了,
    应该是一个道理,希望对你有帮助。
      

  9.   

    在down的事件下 ,重写鼠标焦点事件 只是一个想法 
      

  10.   

    鼠标事件的响应,象所说的显示TOOLTIP,只触发一次!
    要想达到你那样的效果,需要手动去控制显示,
    而不能采用鼠标触发机制。
      

  11.   

    我把TIP的显示位置移开了一点点,果然好了...暴汗...
      

  12.   

    我把TIP的显示位置移开了一点点,果然好了...暴汗...