Skip to content

Commit 6ec79e4

Browse files
authored
Update customizing-raddropdownlist-popup-dual-monitors.md
1 parent 74d0c7f commit 6ec79e4

File tree

1 file changed

+105
-104
lines changed

1 file changed

+105
-104
lines changed

knowledge-base/customizing-raddropdownlist-popup-dual-monitors.md

Lines changed: 105 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,21 @@ title: Customizing RadDropDownList Pop-Up Location Across Dual Monitors in UI fo
33
description: Learn how to customize the pop-up location of RadDropDownList when stretched across two monitors in Telerik UI for WinForms.
44
type: how-to
55
page_title: Adjusting RadDropDownList Pop-Up Behavior on Dual Monitors
6-
slug: customizing-raddropdownlist-popup-dual-monitors
6+
slug: dropdownlist-popup-dual-monitors
77
tags: raddropdownlist, dual-monitors, pop-up-location, ui-for-winforms
88
res_type: kb
99
ticketid: 1687869
1010
---
1111

1212
## 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>
13+
|Product Version|Product|Author|
14+
|----|----|----|
15+
|2025.2.250|RadDropDownList for WinForms|[Nadya Todorova](https://www.telerik.com/blogs/author/nadya-karaivanova)|
2516

2617
## Description
2718

2819
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.
2920

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-
3521
## Solution
3622

3723
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:
@@ -41,96 +27,111 @@ To customize the behavior of RadDropDownList when stretched across two monitors,
4127

4228
### Example Implementation
4329

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-
```
30+
````C#
31+
32+
public class CustomDropDownList : RadDropDownList
33+
{
34+
protected override RadDropDownListElement CreateDropDownListElement()
35+
{
36+
return new CustomDropDownListElement();
37+
}
38+
public override string ThemeClassName
39+
{
40+
get
41+
{
42+
return typeof(RadDropDownList).FullName;
43+
}
44+
set
45+
{
46+
base.ThemeClassName = value;
47+
}
48+
}
49+
}
50+
51+
public class CustomDropDownListElement : RadDropDownListElement
52+
{
53+
protected override Type ThemeEffectiveType
54+
{
55+
get
56+
{
57+
return typeof(RadDropDownListElement);
58+
}
59+
}
60+
61+
public class MyDropDownPopupForm : DropDownPopupForm
62+
{
63+
public MyDropDownPopupForm(RadDropDownListElement ownerDropDownListElement) : base(ownerDropDownListElement)
64+
{
65+
}
66+
67+
public override string ThemeClassName
68+
{
69+
get
70+
{
71+
return typeof(RadSizablePopupControl).FullName;
72+
}
73+
set
74+
{
75+
base.ThemeClassName = value;
76+
}
77+
}
78+
79+
protected override Point GetCorrectedLocation(Screen currentScreen, Rectangle alignmentRectangle, Size popupSize)
80+
{
81+
// MyBase.GetCorrectedLocation(currentScreen, alignmentRectangle, popupSize)
82+
return alignmentRectangle.Location;
83+
}
84+
}
85+
86+
protected override RadPopupControlBase CreatePopupForm()
87+
{
88+
MyDropDownPopupForm popup = new MyDropDownPopupForm(this);
89+
90+
popup.VerticalAlignmentCorrectionMode = AlignmentCorrectionMode.SnapToOuterEdges;
91+
popup.SizingMode = this.DropDownSizingMode;
92+
popup.Height = this.DropDownHeight;
93+
popup.HorizontalAlignmentCorrectionMode = AlignmentCorrectionMode.Smooth;
94+
this.WirePopupFormEvents(popup);
95+
96+
this.Popup = popup;
97+
return popup;
98+
}
99+
100+
protected override Point GetPopupLocation(RadPopupControlBase popup)
101+
{
102+
var form1 = this.ElementTree.Control.FindForm();
103+
var formBounds = form1.Bounds;
104+
var controlLocationInScreen = this.ElementTree.Control.Location;
105+
Control parentControl = this.ElementTree.Control.Parent;
106+
while (parentControl != null)
107+
{
108+
controlLocationInScreen.X += parentControl.Location.X;
109+
controlLocationInScreen.Y += parentControl.Location.Y;
110+
parentControl = parentControl.Parent;
111+
}
112+
113+
controlLocationInScreen.X += form1.Size.Width - form1.ClientSize.Width;
114+
controlLocationInScreen.Y += form1.Size.Height - form1.ClientSize.Height;
115+
116+
controlLocationInScreen.Y += this.Bounds.Height;
117+
118+
return controlLocationInScreen;
119+
}
120+
protected override Size GetPopupSize(RadPopupControlBase popup, bool measure)
121+
{
122+
Size size = base.GetPopupSize(popup, measure);
123+
size.Width = this.BoundingRectangle.Width;
124+
// Adjust the size as needed
125+
return size;
126+
}
127+
}
128+
129+
````
128130

129131
3. Replace the standard `RadDropDownList` with the custom class `CustomDropDownList` in your project.
130132

131133
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.
132134

133135
## See Also
134136

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)
137+
- [RadDropDownList Documentation](https://docs.telerik.com/devtools/winforms/controls/dropdown-listcontrol-and-checkeddropdownlist/dropdownlist/overview)

0 commit comments

Comments
 (0)