このコードを試してください。1つはlanguage_CmbBxという名前の2つのComboBoxを作成し、もう1つはwords_CmbBxという名前のComboBoxを作成しました。設定しましたwords_CmbBx.Visible = false;
private void language_CmbBx_SelectedIndexChanged(object sender, EventArgs e)
{
this.Cursor = new Cursor(Cursor.Current.Handle);
words_CmbBx.Location = new Point(language_CmbBx.Location.X + language_CmbBx.Width, GetLocalMousePos().Y);
words_CmbBx.Visible = true;
}
このメソッドは、マウスの位置または必要なselectedItemの位置を取得するためのものです。
public Point GetLocalMousePos()
{
Point screenPos = Cursor.Position;
return this.PointToClient(screenPos);
}
唯一の問題は、ComboBoxが開いたままにならず、開いたままにする方法がまだ見つからなかったことです。
すでに述べたように、ComboBoxを使用して目的を達成することは非常に困難です。代わりに、ListBoxを使用してみてください。
private void languages_LstBx_SelectedIndexChanged(object sender, EventArgs e)
{
this.Cursor = new Cursor(Cursor.Current.Handle);
words_LstBx.Location = new Point(language_LstBx.Location.X + language_LstBx.Width, GetLocalMousePos().Y);
words_LstBx.Visible = true;
}
同じコード、より良い結果!
私のVS2010プロジェクトはここからダウンロードできます:http ://www.abouchleih.de/projects/twocomboboxes.zip