当Combobox向上打开时,工具提示显示在错误的位置

时间:2014-10-16 09:32:46

标签: c# winforms tooltip

我有向上方向的Combobox开口,在绘制模式下我添加了一个工具提示。

向下打开时,工具尖端显示在完美的位置。但在向上打开时,工具提示显示在10-15项以下。

if (e.Index < 0)
{ 
    return;
}

string text = cmbVariablesExp2.GetItemText(cmbVariablesExp2.Items[e.Index]);
e.DrawBackground();

using (SolidBrush br = new SolidBrush(e.ForeColor))
{ 
    e.Graphics.DrawString(text, e.Font, br, e.Bounds); 
}

if ((e.State & DrawItemState.Selected) == DrawItemState.Selected 
         && cmbVariablesExp2Dropdowned)
{ 
    toolTip1.Show(text, cmbVariablesExp2, e.Bounds.Right, e.Bounds.Bottom); 
}
e.DrawFocusRectangle();

1 个答案:

答案 0 :(得分:0)

快速解决您的问题

if ((e.State & DrawItemState.Selected) == DrawItemState.Selected 
   && dropdownward)
{ 
    toolTip1.Show(text, cmbVariablesExp2, e.Bounds.Right, e.Bounds.Bottom); 
}
else if ((e.State & DrawItemState.Selected) == DrawItemState.Selected 
     && dropupward)
{
    toolTip1.Show(text, cmbVariablesExp2, e.Bounds.Right, 
        e.Bounds.Bottom -cmbVariablesExp2.DropDownHeight); 
}

但我不知道如何确定下拉方向是向上还是向下。

相关问题