1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . ComponentModel ;
4
+ using System . Drawing ;
4
5
using System . Linq ;
5
6
using System . Threading . Tasks ;
6
7
using System . Windows . Forms ;
@@ -48,8 +49,6 @@ internal QuickMenu()
48
49
{
49
50
InitializeComponent ( ) ;
50
51
_hideDisposeMethod = HideDispose ;
51
- Show ( ) ;
52
- SetLocationToCursor ( ) ;
53
52
}
54
53
55
54
/// <summary>
@@ -113,6 +112,13 @@ public void SetData(IEnumerable<IconMenuItem<T>.DataContainer> payloads)
113
112
114
113
Height = 0 ;
115
114
}
115
+
116
+ if ( ! isLocationSet )
117
+ {
118
+ Show ( ) ;
119
+ SetLocationToCursor ( ) ;
120
+ isLocationSet = true ;
121
+ }
116
122
}
117
123
118
124
private void DebounceHiding ( )
@@ -139,6 +145,8 @@ private void OnItemClicked(IconMenuItem<T> control)
139
145
SelectionChanged ? . Invoke ( control , new MenuClickedEvent ( dataContainer ) ) ;
140
146
}
141
147
148
+ private bool isLocationSet = false ;
149
+
142
150
private async Task HideDispose ( )
143
151
{
144
152
_hiding = true ;
@@ -153,6 +161,7 @@ private async Task HideDispose()
153
161
154
162
Hide ( ) ;
155
163
Dispose ( ) ;
164
+ isLocationSet = false ;
156
165
}
157
166
158
167
private void ResetOpacity ( )
@@ -162,9 +171,16 @@ private void ResetOpacity()
162
171
163
172
private void SetLocationToCursor ( )
164
173
{
165
- var position = Cursor . Position ;
166
- SetDesktopLocation ( position . X , position . Y ) ;
167
- Location = position ;
174
+ int screenWidth = Screen . PrimaryScreen . Bounds . Width ;
175
+ int screenHeight = Screen . PrimaryScreen . Bounds . Height ;
176
+ Point qmLoc = new Point (
177
+ Math . Min ( Cursor . Position . X , screenWidth - Width ) ,
178
+ Math . Min ( Cursor . Position . Y , screenHeight - Height )
179
+ ) ;
180
+
181
+ SetDesktopLocation ( qmLoc . X , qmLoc . Y ) ;
182
+ Location = qmLoc ;
183
+ isLocationSet = true ;
168
184
}
169
185
}
170
186
}
0 commit comments