簡體   English   中英

如何在ListBox的下拉區域添加邊框?

[英]How can I add a border to the Drop-down area of a ListBox?

我使用以下代碼覆蓋和繪制ListBox中的每個列表項。

      if (e.Index < 0) return;
        // if the item state is selected then change the back color 
        if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            e = new DrawItemEventArgs(e.Graphics,
                                      e.Font,
                                      e.Bounds,
                                      e.Index,
                                      e.State ^ DrawItemState.Selected,
                                      e.ForeColor,
                                      Color.Red); // Choose the color

        // Draw the background of the ListBox control for each item.
        e.DrawBackground();
        // Draw the current item text
        e.Graphics.DrawString(studentsListBox.Items[e.Index].ToString(), e.Font, Brushes.Black, e.Bounds, StringFormat.GenericDefault);
        // If the ListBox has focus, draw a focus rectangle around the selected item.
        e.DrawFocusRectangle();

代碼是我可以懷疑的,但是我還想在列表框的整個下拉部分添加一個邊框(參見下面的示例圖片。)如何將邊框添加到整個列表?

在此輸入圖像描述

由於標題是指邊界,我將專注於此。 我假設你想要改變BorderStyle超出給定的“None”,“FixedSingle”和“Fixed3D”?

ListBox不支持任何類型的BorderColors等。

最好的辦法是將BorderStyle to "None"更改BorderStyle to "None"IntegralHeight = FalseDock = Fill ,然后將其放在面板中。

對於您的面板,更改BorderStlye = NonePadding (All) = 2BackColor = Red

使用WinForms,您的選擇是有限的。

暫無
暫無

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

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