簡體   English   中英

Combobox下拉列表

[英]Combobox Drop Down list

我有一個表格上面有一個組合框。

組合框設置為DropDownList。 這些下拉項是對象的描述形式。 這意味着它們可以持續很長時間。 組合框在屏幕上的位置意味着當顯示下拉列表時,它不能全部適合屏幕。 其中一些被屏幕的右邊緣切斷。

我無法移動組合框。

他們可以通過某種方式移動控件的下拉列表部分。 也許將其置於控制之下?

更新

我附上了截圖。 你可以在這里看到表格 -

在此輸入圖像描述

輸入交易時,用戶填寫表單並單擊“保存”。 將為任何客戶輸入的許多交易將是重復交易。 這些可以保存到收藏夾。 下拉框列出了當前保存的收藏夾,當選擇一個時,程序會自動填寫交易字段。

屏幕截圖2顯示了整個程序和空間不足的組合框列表。

在此輸入圖像描述

我從截圖中了解到我可以移動表單,但我喜歡在屏幕上保留用於輸入事務的表單。

我可能需要查看界面的其他選項。

謝謝,

也許你應該創建自己的comboBox,如下所示:

http://msdn.microsoft.com/en-us/library/ms996411

抱歉遲到了:-)。 是的,你可以這樣做。 但是你需要創建一個自定義的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文章構建一個更好的ComboBox獲得的

你嘗試過設計師嗎?

Combobox.Anchor = Left | Right

嘗試設置組合的DropdownWidth

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM