none
tooltip 一問 RRS feed

  • 問題

  • HI, 各位大大

    我自己寫咗個tooltip , "owner draw " is true.

    但點樣可以起draw border 與文字之間留有空隙?

    My part of program as follows:

     private void toolTip1_Popup(object sender, PopupEventArgs e)
     {
          if (e.AssociatedControl == button1)
           {
                 using (Font f = new Font("新細明體", 10, FontStyle.Regular))               //tooltip size
                  {
                        e.ToolTipSize = TextRenderer.MeasureText(
                        toolTip1.GetToolTip(e.AssociatedControl), f);             
                   }
            }
     }

     private void toolTip1_Draw(System.Object sender, System.Windows.Forms.DrawToolTipEventArgs e)
      {
                if (e.AssociatedControl == button1)
                {
                    e.Graphics.FillRectangle(SystemBrushes.Info, rr);        
                    e.DrawBorder();                 
                   
                    using (StringFormat sf = new StringFormat())                    
                    {
                        sf.Alignment = StringAlignment.Near;                         
                        sf.LineAlignment = StringAlignment.Near;                    
                        sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None;           
                        sf.FormatFlags = StringFormatFlags.NoWrap;                            
                       
                        using (Font f = new Font("新細明體", 9, FontStyle.Regular))
                        {
                            e.Graphics.DrawString(e.ToolTipText, f,
                                SystemBrushes.WindowFrame, e.Bounds, sf);                        
                        }
                    }

                    using (StringFormat sfv = new StringFormat())
                    {
                        sfv.Alignment = StringAlignment.Near;
                        sfv.LineAlignment = StringAlignment.Near;
                        sfv.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None;
                        sfv.FormatFlags = StringFormatFlags.NoWrap;

                        using (Font f = new Font("新細明體", 10, FontStyle.Bold))
                        {
                            e.Graphics.DrawString("Button", f,
                                SystemBrushes.WindowFrame,e.Bounds, sfv);
                        }
                    }        
                }    
    }

    private void button1_MouseEnter(object sender, EventArgs e)
    {
                button1.Text = "Button"; 
                toolTip1.Active = true;
                toolTip1.SetToolTip(button1, "\n" + "版本2.0.0.0 (屬於Microsoft Corporation)" + "\n" + ".NET Component" + "\n\n" + "當使用者按一下時引發事件。");
                toolTip1.ShowAlways = true;
     }

    thx for your help.


    2008年8月13日 上午 03:22

解答

  • HI,

     

    您的意思是要在輸出的文字和ToolTip的外框之間留空隙嗎? 如果是的話, 可以修改DrawString方法呼叫的語法, 透過第四個參數控制輸出字串的位置:

     

    e.Graphics.DrawString(e.ToolTipText, f,
                                SystemBrushes.WindowFrame, e.Bounds, sf);                        

     

    tihs

    2008年8月14日 上午 02:53

所有回覆

  • HI,

     

    您的意思是要在輸出的文字和ToolTip的外框之間留空隙嗎? 如果是的話, 可以修改DrawString方法呼叫的語法, 透過第四個參數控制輸出字串的位置:

     

    e.Graphics.DrawString(e.ToolTipText, f,
                                SystemBrushes.WindowFrame, e.Bounds, sf);                        

     

    tihs

    2008年8月14日 上午 02:53
  • thx a lot. I know how to do la!!
    2008年8月14日 上午 03:33