|
| 1 | +--- |
| 2 | +title: Customizing RadDropDownList Pop-Up Location Across Dual Monitors in UI for WinForms |
| 3 | +description: Learn how to customize the pop-up location of RadDropDownList when stretched across two monitors in Telerik UI for WinForms. |
| 4 | +type: how-to |
| 5 | +page_title: Adjusting RadDropDownList Pop-Up Behavior on Dual Monitors |
| 6 | +slug: customizing-raddropdownlist-popup-dual-monitors |
| 7 | +tags: raddropdownlist, dual-monitors, pop-up-location, ui-for-winforms |
| 8 | +res_type: kb |
| 9 | +ticketid: 1687869 |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | +<table> |
| 14 | +<tbody> |
| 15 | +<tr> |
| 16 | +<td>Product</td> |
| 17 | +<td>RadDropDownList for Telerik UI for WinForms</td> |
| 18 | +</tr> |
| 19 | +<tr> |
| 20 | +<td>Version</td> |
| 21 | +<td>2024.2.514</td> |
| 22 | +</tr> |
| 23 | +</tbody> |
| 24 | +</table> |
| 25 | + |
| 26 | +## Description |
| 27 | + |
| 28 | +When RadDropDownList is stretched across two monitors, the dropdown part may exhibit unexpected behavior, such as shifting upon opening. This behavior occurs because controls like RadDropDownList are designed to operate within one monitor, scaling automatically to the monitor's DPI and resolution settings. Stretching the form across two monitors introduces complexities that may require custom handling. |
| 29 | + |
| 30 | +This knowledge base article also answers the following questions: |
| 31 | +- How can I adjust the RadDropDownList to work properly across dual monitors? |
| 32 | +- Is there a way to control the dropdown pop-up position in RadDropDownList? |
| 33 | +- How can I customize RadDropDownList to avoid shifting issues across monitors? |
| 34 | + |
| 35 | +## Solution |
| 36 | + |
| 37 | +To customize the behavior of RadDropDownList when stretched across two monitors, you can create a custom solution to control the pop-up location. Follow these steps: |
| 38 | + |
| 39 | +1. Create a custom class that inherits from `RadDropDownList`. |
| 40 | +2. Override the necessary methods to customize the dropdown pop-up behavior. |
| 41 | + |
| 42 | +### Example Implementation |
| 43 | + |
| 44 | +```vb.net |
| 45 | +Public Class CustomDropDownList |
| 46 | + Inherits RadDropDownList |
| 47 | + |
| 48 | + Protected Overrides Function CreateDropDownListElement() As RadDropDownListElement |
| 49 | + Return New CustomDropDownListElement |
| 50 | + End Function |
| 51 | + |
| 52 | + Public Overrides Property ThemeClassName As String |
| 53 | + Get |
| 54 | + Return GetType(RadDropDownList).FullName |
| 55 | + End Get |
| 56 | + Set(value As String) |
| 57 | + MyBase.ThemeClassName = value |
| 58 | + End Set |
| 59 | + End Property |
| 60 | +End Class |
| 61 | + |
| 62 | +Public Class CustomDropDownListElement |
| 63 | + Inherits RadDropDownListElement |
| 64 | + |
| 65 | + Protected Overrides ReadOnly Property ThemeEffectiveType As Type |
| 66 | + Get |
| 67 | + Return GetType(RadDropDownListElement) |
| 68 | + End Get |
| 69 | + End Property |
| 70 | + |
| 71 | + Public Class MyDropDownPopupForm |
| 72 | + Inherits DropDownPopupForm |
| 73 | + |
| 74 | + Public Sub New(ownerDropDownListElement As RadDropDownListElement) |
| 75 | + MyBase.New(ownerDropDownListElement) |
| 76 | + End Sub |
| 77 | + |
| 78 | + Public Overrides Property ThemeClassName As String |
| 79 | + Get |
| 80 | + Return GetType(RadSizablePopupControl).FullName |
| 81 | + End Get |
| 82 | + Set(value As String) |
| 83 | + MyBase.ThemeClassName = value |
| 84 | + End Set |
| 85 | + End Property |
| 86 | + |
| 87 | + Protected Overrides Function GetCorrectedLocation(currentScreen As Screen, alignmentRectangle As Rectangle, popupSize As Size) As Point |
| 88 | + Return alignmentRectangle.Location |
| 89 | + End Function |
| 90 | + End Class |
| 91 | + |
| 92 | + Protected Overrides Function CreatePopupForm() As RadPopupControlBase |
| 93 | + Dim popup As MyDropDownPopupForm = New MyDropDownPopupForm(Me) |
| 94 | + popup.VerticalAlignmentCorrectionMode = AlignmentCorrectionMode.SnapToOuterEdges |
| 95 | + popup.SizingMode = Me.DropDownSizingMode |
| 96 | + popup.Height = Me.DropDownHeight |
| 97 | + popup.HorizontalAlignmentCorrectionMode = AlignmentCorrectionMode.Smooth |
| 98 | + Me.WirePopupFormEvents(popup) |
| 99 | + Me.Popup = popup |
| 100 | + Return popup |
| 101 | + End Function |
| 102 | + |
| 103 | + Protected Overrides Function GetPopupLocation(popup As RadPopupControlBase) As Point |
| 104 | + Dim form1 = Me.ElementTree.Control.FindForm() |
| 105 | + Dim formBounds = form1.Bounds |
| 106 | + Dim controlLocationInScreen = Me.ElementTree.Control.Location |
| 107 | + Dim parentControl As Control = Me.ElementTree.Control.Parent |
| 108 | + While parentControl IsNot Nothing |
| 109 | + controlLocationInScreen.X += parentControl.Location.X |
| 110 | + controlLocationInScreen.Y += parentControl.Location.Y |
| 111 | + parentControl = parentControl.Parent |
| 112 | + End While |
| 113 | + |
| 114 | + controlLocationInScreen.X += form1.Size.Width - form1.ClientSize.Width |
| 115 | + controlLocationInScreen.Y += form1.Size.Height - form1.ClientSize.Height |
| 116 | + controlLocationInScreen.Y += Me.Bounds.Height |
| 117 | + |
| 118 | + Return controlLocationInScreen |
| 119 | + End Function |
| 120 | + |
| 121 | + Protected Overrides Function GetPopupSize(popup As RadPopupControlBase, measure As Boolean) As Size |
| 122 | + Dim size As Size = MyBase.GetPopupSize(popup, measure) |
| 123 | + size.Width = Me.BoundingRectangle.Width |
| 124 | + Return size |
| 125 | + End Function |
| 126 | +End Class |
| 127 | +``` |
| 128 | + |
| 129 | +3. Replace the standard `RadDropDownList` with the custom class `CustomDropDownList` in your project. |
| 130 | + |
| 131 | +This solution allows you to define a custom location for the dropdown pop-up and adjust its size as needed, ensuring proper behavior when stretched across dual monitors. |
| 132 | + |
| 133 | +## See Also |
| 134 | + |
| 135 | +- [RadDropDownList Documentation](https://docs.telerik.com/devtools/winforms/controls/dropdown-listcontrol/dropdownlist/overview) |
| 136 | +- [Customizing DropDowns in Telerik UI for WinForms](https://docs.telerik.com/devtools/winforms/controls/dropdown-listcontrol/dropdownlist/customizing-raddropdownlist) |
0 commit comments