シナリオは次のとおりです。
私はコードエディター (Winforms) に取り組んでおり、RichTextBox
Intellisense として機能するコンポーネントを使用しています。
「。」を押したとき ではRichTextBox
、Intellisense が表示され、その中のすべてのオブジェクトに異なる Tooltip が表示されます。
ツールチップの位置は次のSelectedIndex
とおりでした。次のコードを思いつきました。
public void SetToolTip(Intellisense intellisenseitem)
{
if (selectedItemIndex == 0)
{
toolTip.ToolTipTitle = title;
toolTip.Show(text, this, Width + 3, SelectedItemIndex, 3000);
}
if (selectedItemIndex == 1)
{
toolTip.ToolTipTitle = title;
toolTip.Show(text, this, Width + 3, SelectedItemIndex + 15, 3000);
}
if (selectedItemIndex == 2)
{
toolTip.ToolTipTitle = title;
toolTip.Show(text, this, Width + 3, SelectedItemIndex + 30, 3000);
}
if (selectedItemIndex == 3)
{
toolTip.ToolTipTitle = title;
toolTip.Show(text, this, Width + 3, SelectedItemIndex + 45, 3000);
}
if (selectedItemIndex == 4)
{
toolTip.ToolTipTitle = title;
toolTip.Show(text, this, Width + 3, SelectedItemIndex + 60, 3000);
}
if (selectedItemIndex == 5)
{
toolTip.ToolTipTitle = title;
toolTip.Show(text, this, Width + 3, SelectedItemIndex + 75, 3000);
}
if (selectedItemIndex == 6)
{
toolTip.ToolTipTitle = title;
toolTip.Show(text, this, Width + 3, SelectedItemIndex + 90, 3000);
}
if (selectedItemIndex == 7)
{
toolTip.ToolTipTitle = title;
toolTip.Show(text, this, Width + 3, SelectedItemIndex + 105, 3000);
}
if (selectedItemIndex == 8)
{
toolTip.ToolTipTitle = title;
toolTip.Show(text, this, Width + 3, SelectedItemIndex + 120, 3000);
}
if (selectedItemIndex == 9)
{
toolTip.ToolTipTitle = title;
toolTip.Show(text, this, Width + 3, SelectedItemIndex + 135, 3000);
}
if (selectedItemIndex == 10)
{
toolTip.ToolTipTitle = title;
toolTip.Show(text, this, Width + 3, SelectedItemIndex + 150, 3000);
}
if (selectedItemIndex == 11)
{
toolTip.ToolTipTitle = title;
toolTip.Show(text, this, Width + 3, SelectedItemIndex + 165, 3000);
}
if (selectedItemIndex >= 12) //still needed to fix
{
toolTip.ToolTipTitle = title;
toolTip.Show(text, this, Width + 3, SelectedItemIndex + 165, 3000);
}
}
問題は、Intellisense アイテムが 12 を超えると (Intellisense には、Visual Studio の Intellisense のように入力されたテキスト ( startswith
) をフィルター処理するフィルターがあることに注意してくださいRichtextbox
)、自動的にスクロールが行われ (最大サイズに達するため)、問題が発生しました。スクロールを使用する場合、Tooltip は Selecteditemindex に従いません。
コントロールインテリセンスはリストボックスのようなものでした(以前に私が使用するコンポーネントであると言及したため)
今私の質問は、ツールチップを常にSelectedItemIndex
インテリセンスに追従させる方法についてでした。