• 為combobox每一項添加提示
  • 2016/10/5 17:14:01  瀏覽次數:543
  • ToolTip tt;
    private void Form1_Load(object sender, EventArgs e)
    {
          tt=new ToolTip();
    }
    private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
     {
           e.DrawBackground();
           e.DrawFocusRectangle();
           Rectangle r0 = e.Bounds;
           e.Graphics.DrawString(dt.Rows[e.Index]["address"].ToString(), e.Font, new Pen(e.ForeColor).Brush, r0);
           Size sz = TextRenderer.MeasureText(dt.Rows[e.Index]["address"].ToString(), e.Font);
           if (sz.Width > 80)
              tt.Show(dt.Rows[e.Index]["address"].ToString(), comboBox1, r0.X + r0.Width, r0.Y + r0.Height);
           else
               tt.Hide(comboBox1);
    }
    
    private void comboBox1_DropDownClosed(object sender, EventArgs e)
    {
           tt.Hide(comboBox1);
    }

     


分享:0
找几个欢乐麻将豆商