Search code examples
winformsdynamicruntimewebbrowser-controlmove

Move a webbrowser during runtime in Windows form,C#


I'm currently working with a webbrowser control in winforms, I just want to drag and move this webbrowser to any place in the form during runtime. Is it possible? if so please tell me.


Solution

  • I've found an example on CodeProject that works really well.

    Move controls on a form at runtime

    The only problem I ran into is that I couldn't drag the WebBrowser control itself as it appears to capture mouse clicks. As a workaround I put the WebBrowser in a Panel, left a little space at the top so it looks like a title bar, then anchored the WebBrowser to fill the rest of the space.

    Put the following code somewhere appropriate like Form_Load.

    Helper.ControlMover.Init(this.TheWebBrowserPanel);
    

    You can then drag the WebBrowser control by dragging the Panel instead:

    enter image description here