@@ -50,6 +50,7 @@ public class FormsDesignerViewContent : AbstractViewContentHandlingLoadErrors, I
5050 readonly Control pleaseWaitLabel = new Label ( ) { Text = StringParser . Parse ( "${res:Global.PleaseWait}" ) , TextAlign = ContentAlignment . MiddleCenter } ;
5151 DesignSurface designSurface ;
5252 bool disposing ;
53+ Timer timer = new Timer { Interval = 200 } ;
5354
5455 readonly IViewContent primaryViewContent ;
5556 readonly IDesignerLoaderProvider loaderProvider ;
@@ -142,10 +143,11 @@ protected override string LoadErrorHeaderText {
142143
143144 this . IsActiveViewContentChanged += this . IsActiveViewContentChangedHandler ;
144145
146+ timer . Tick += Timer_Tick ;
145147 FileService . FileRemoving += this . FileServiceFileRemoving ;
146148 SD . Debugger . DebugStarting += this . DebugStarting ;
147149 }
148-
150+
149151 public FormsDesignerViewContent ( IViewContent primaryViewContent , IDesignerLoaderProvider loaderProvider )
150152 : this ( primaryViewContent )
151153 {
@@ -168,6 +170,20 @@ public FormsDesignerViewContent(IViewContent primaryViewContent, OpenedFile mock
168170 this . Files . Add ( primaryViewContent . PrimaryFile ) ;
169171 }
170172
173+ void Timer_Tick ( object sender , System . EventArgs e )
174+ {
175+ // The WinForms designer internally relies on Application.Idle for some actions, e.g. 'Show Code'
176+ // This event does not get raised in a WPF application.
177+ // While we do forward WPF's equivalent idle event to WinForms (see WorkbenchStartup.cs),
178+ // it doesn't happen often enough -- in particular, it doesn't get raised while the mouse
179+ // is over the WinForms design surface.
180+ // This caused the bug: https://github.com/icsharpcode/SharpDevelop/issues/525
181+ // As a workaround, we use a timer to raise the event while the designer is open.
182+ // Note: this timer is implemented in the WinForms designer and not globally in SharpDevelop
183+ // so that we don't wake up the CPU unnecessarily when the designer is not in use.
184+ Application . RaiseIdle ( e ) ;
185+ }
186+
171187 bool inMasterLoadOperation ;
172188
173189 protected override void LoadInternal ( OpenedFile file , System . IO . Stream stream )
@@ -344,6 +360,7 @@ void LoadDesigner()
344360 UpdatePropertyPad ( ) ;
345361
346362 hasUnmergedChanges = false ;
363+ timer . Start ( ) ;
347364
348365 LoggingService . Info ( "Form Designer: END INITIALIZE" ) ;
349366 }
@@ -404,6 +421,7 @@ void UnloadDesigner()
404421 {
405422 LoggingService . Debug ( "FormsDesigner unloading, setting ActiveDesignSurface to null" ) ;
406423 designSurfaceManager . ActiveDesignSurface = null ;
424+ timer . Stop ( ) ;
407425
408426 bool savedIsDirty = ( this . DesignerCodeFile == null ) ? false : this . DesignerCodeFile . IsDirty ;
409427 this . UserContent = this . pleaseWaitLabel ;
0 commit comments