Results 1 to 4 of 4

Thread: [RESOLVED] Moving form at runtime, using code.

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2008
    Posts
    39

    Resolved [RESOLVED] Moving form at runtime, using code.

    What I want is a control that you click and drag to move the form (Window1). This is incredibly easy in regular visual basic, but wpf manages to make it difficult because the GUI is in a separate thread...

    I have the code for the click and drag part, but I need to know how to actually move the form, say, 1 pixel to the left at runtime.




    What I've figured out so far is that you can make doubleanimations at runtime with:
    Code:
    Dim anim As New DoubleAnimation
            anim.From = 0
            anim.To = 360
            anim.Duration() = New Duration(New TimeSpan(0, 0, 0, 0, 500))
            anim.RepeatBehavior = New RepeatBehavior(4)
    and so on...
    but I can't figure out how to use this to actually change the window's position.

  2. #2

    Thread Starter
    Member
    Join Date
    Apr 2008
    Posts
    39

    Re: Moving form at runtime, using code.

    ooh, just found a very, very simple solution.

    Code:
    Private Sub Form_MouseDown(ByVal sender As Object, ByVal e As Input.MouseEventArgs) Handles Me.MouseDown
            DragMove()
    End Sub

  3. #3
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [RESOLVED] Moving form at runtime, using code.

    Quote Originally Posted by joebobfrank
    What I want is a control that you click and drag to move the form (Window1). This is incredibly easy in regular visual basic, but wpf manages to make it difficult because the GUI is in a separate thread...
    As far as I am aware, the GUI threading is exactly the same as it is in winforms (or regular visual basic as you call it). The GUI has its own thread any any code you use within the GUI/form runs on that thread, unless you specify that it should run in a background thread. However, that doesnt matter at all because the code you would need to use (which you have found) would run on the same thread as the GUI anyway...

    Anyway I guess it doesnt matter if you have got it sorted but your post just confused me a little :P
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  4. #4

    Thread Starter
    Member
    Join Date
    Apr 2008
    Posts
    39

    Re: [RESOLVED] Moving form at runtime, using code.

    Well when I was trying to adjust the position of the window it would error and tell me it was in another thread or something alone those lines...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width