2011-07-26 14 views
6

私はそれにコンボボックスを持つフォームを持っています。Comboboxドロップダウンリスト

コンボボックスはDropDownListに設定されています。これらのドロップダウン項目は、オブジェクトの記述形式です。これは彼らがかなり長くなることを意味します。画面上のコンボボックスの位置とは、ドロップダウンリストが表示されているときに画面に収まるとは限りません。その一部は画面の右端で切り取られます。

コンボボックスを移動できません。

コントロールのドロップダウンリストの一部を移動できる方法です。おそらくそれを制御の中心に置いていますか?

更新

私はスクリーンショットを添付しました。

enter image description here

取引を入力するとき、ユーザーがフォームに入力し、[保存]をクリックする - あなたはこちらのフォームを見ることができます。ただし、任意のクライアントに対して入力される多数のトランザクションは、定期的なトランザクションになります。これらはお気に入りに保存することができます。ドロップダウンボックスには現在保存されているお気に入りが表示され、選択されている場合はプログラムによって自動的に取引項目が入力されます。

全体のプログラムとスペースを使い果たしたコンボボックスのリストを示すスクリーンショット2です。

enter image description here

私は、フォームを移動することができ、スクリーンショットから実現が、私は、画面の中心に取引を入力するためのフォームを維持したいです。

私はインターフェイスのための他のオプションを見なければならないかもしれません。

おかげで、

+1

提案:単純名/線を有するドロップダウン、およびユーザが1つを選択したときに完全な説明が取り込まれる複数行のテキストボックスを使用しない理由コンボボックスのエントリ。この方法では、テキストボックスは、すべてのテキストを保持することができ、ユーザーは満足しています:) – woohoo

+0

あなたはこれと同様の問題を抱えているように見えるhttp://stackoverflow.com/questions/2395747/combo-box-dropdown-position – kavun

+0

スクロールバーを提供する単一列のListBoxまたはListViewの使用について説明します。 ComboBoxでこれを達成するのは簡単ではありません。 – CharithJ

答えて

0

あなたはコンボのDropdownWidthを設定してみてくださいデザイナーに

Combobox.Anchor = Left | Right 
+0

@ user476683これは残念なことに助けにはなりませんでした。 – user476683

0

を設定してみてくださいました。ここに示されているよう

0

申し訳ありません:-)。はい、あなたはそれを行うことができます。しかし、カスタムComboBoxを作成し、ComboBoxWndProcメソッドをオーバーライドする必要があります。

そのようです。

System.Runtime.InteropServices 

private const int SWP_NOSIZE = 0x1; 
private const int WM_CTLCOLORLISTBOX = 0x0134; 

[DllImport("user32.dll")] 
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int 
X, int Y, int cx, int cy, uint uFlags); 

protected override void WndProc(ref Message m) 
{ 
    if (m.Msg == WM_CTLCOLORLISTBOX) 
    { 
     // Make sure we are inbounds of the screen 
     int left = this.PointToScreen(new Point(0, 0)).X; 

     //Only do this if the dropdown is going off right edge of screen 
     if (this.DropDownWidth > Screen.PrimaryScreen.WorkingArea.Width - left) 
     { 
      // Get the current combo position and size 
      Rectangle comboRect = this.RectangleToScreen(this.ClientRectangle); 

      int dropHeight = 0; 
      int topOfDropDown = 0; 
      int leftOfDropDown = 0; 

      //Calculate dropped list height 
      for (int i = 0; (i < this.Items.Count && i < this.MaxDropDownItems); i++) 
      { 
       dropHeight += this.ItemHeight; 
      } 

      //Set top position of the dropped list if 
      //it goes off the bottom of the screen 
      if (dropHeight > Screen.PrimaryScreen.WorkingArea.Height - 
        this.PointToScreen(new Point(0, 0)).Y) 
      { 
       topOfDropDown = comboRect.Top - dropHeight - 2; 
      } 
      else 
      { 
       topOfDropDown = comboRect.Bottom; 
      } 

      //Calculate shifted left position 
      leftOfDropDown = comboRect.Left - (this.DropDownWidth - 
        (Screen.PrimaryScreen.WorkingArea.Width - left)); 
      //when using the SWP_NOSIZE flag, cx and cy params are ignored 
      SetWindowPos(m.LParam, 
         IntPtr.Zero, 
         leftOfDropDown, 
         topOfDropDown, 
         0, 
         0, 
         SWP_NOSIZE); 
      } 
     } 

     base.WndProc(ref m); 
} 

コードは、MSDNの記事から入手されBuilding a Better ComboBox