<img alt="aaaaa">鼠标移到图片上时会出现一行字.
在C#中怎么实现这种效果?用的是PictureBox控件.
注意,是winform

解决方案 »

  1.   


        class CusomPictureBox : PictureBox
        {
            private Font font=null;
            private string alt=string.Empty;
            private Color foreColor=Color.Black;
            public CusomPictureBox()
            {
            }        protected override void OnCreateControl()
            {
                font = this.FindForm().Font;
            }        public Font Font
            {
                get { return font; }
                set { font = value; }
            }        public Color ForeColor
            {
                get { return foreColor; }
                set { foreColor = value; }
            }        public string Alt
            {
                set { alt = value; }
                get { return alt; }
            }        protected override void OnPaint(PaintEventArgs pe)
            {
                base.OnPaint(pe);
                if (this.Image == null)
                {
                    pe.Graphics.DrawString(alt, font, new SolidBrush(foreColor), new PointF(10, 10));
                }
            }
        }
      

  2.   

    在 pictureBox的 MouseHover事件里加个toolTip   设一个坐标位置show出来就可以了
      

  3.   

            private void pictureBox1_MouseEnter(object sender, EventArgs e)
            {
                toolTip1.Show("tttt", this.pictureBox1, 100);
                toolTip1.AutoPopDelay = 5000;
                toolTip1.InitialDelay = 1000;
                toolTip1.ReshowDelay = 500;
            }
      

  4.   

    string txt = "要显示的内容";
    ToolTip tip = new ToolTip(this.components);
    tip.SetToolTip(this.pictureBox1, txt);
      

  5.   

    ^ō^也可直接双击工具箱->ToolTip, 新增 toolTip1 实例..此时, 两次选中 pictureBox1, 你会发现 pictureBox1->属性列表中多了个"toolTip1 上的 ToolTip"属性, 直接输入内容即可..