2011-07-26 57 views
6

我有一个窗体上有一个组合框。Combobox下拉列表

组合框被设置为DropDownList。这些下拉项目是对象的描述性形式。这意味着他们可以变得相当长。屏幕上组合框的位置意味着当显示下拉列表时,它不能全部放在屏幕上。其中一些被屏幕的右边缘斩掉。我不能移动组合框。

是他们以某种方式移动控件的下拉列表部分。也许集中在控制之下?

更新

我附上了截图。你可以在这里看到的形式 -

enter image description here

当进入交易的用户填写表单并单击保存。将为任何客户输入的许多交易将是经常性交易。这些可以保存到收藏夹。下拉框列出当前保存的收藏夹,当选择一个时,程序自动填写交易字段。

截图2显示整个程序和组合框列表中的空间不足。

enter image description here

我从截图知道我可以移动的形式,但我想保持什么形式进入中心的屏幕上交易。我可能不得不查看接口的其他选项。

感谢,

+1

建议:为什么不使用下拉用更简单的名称/线,并与完整的描述,当用户选择一个人口多行文本框进入组合框。这样,文本框可以容纳所有的文本,用户很高兴:) – woohoo

+0

看起来像你有类似的问题,这个http://stackoverflow.com/questions/2395747/combo-box-dropdown-position – kavun

+0

如何关于使用提供滚动条的单列ListBox或ListView。用ComboBox实现这一点并不容易。 – CharithJ

回答

0

你尝试在设计

Combobox.Anchor = Left | Right 
+0

@ user476683。这不利于我们。 – user476683

0

尝试将组合的DropdownWidth设置。

0

对不起迟到张贴:-)。是的,你可以这么做。但是您需要创建一个自定义ComboBox并覆盖WndProc方法的基地ComboBox;

它是这样的;

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