5 Replies - 1994 Views - Last Post: 30 May 2009 - 01:57 AM Rate Topic: -----

#1 mattisdada  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 92
  • Joined: 30-May 08

Move a form, by dragging an image

Posted 29 May 2009 - 07:18 AM

I have made a borderless form, but i still wish to be able to drag it around the screen.

But i dont have a normal background, ive got an image that covers it. I wish to be able to drag this overlaying image around the screen.
Ive found code examples that allow you to drag the form, but you have to acctually drag the form.... Not the image (i couldn't adapt any of them)

This post has been edited by mattisdada: 29 May 2009 - 07:23 AM

Is This A Good Question/Topic? 0
  • +

Replies To: Move a form, by dragging an image

#2 ahmad_511  Icon User is offline

  • MSX
  • member icon

Reputation: 131
  • View blog
  • Posts: 722
  • Joined: 28-April 07

Re: Move a form, by dragging an image

Posted 29 May 2009 - 08:00 AM

hello,
if i understand you correctly, you have a picture box that covers the form and you want to move the form base on that picture

assuming the picture box called PictureBox1
    Dim drag As Boolean = False
    Dim x, y As Integer

    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        drag = True
        x = e.X
        y = e.Y
    End Sub

    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        If drag Then
            Me.Left = MousePosition.X - X
            Me.Top = MousePosition.Y - Y
        End If
    End Sub

    Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
        drag = False
    End Sub



hope it helps
Was This Post Helpful? 1
  • +
  • -

#3 mattisdada  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 92
  • Joined: 30-May 08

Re: Move a form, by dragging an image

Posted 29 May 2009 - 08:26 PM

You my good sir, are a god send!

This is so much simpler than the other form moving solutions i saw, and it works perfectly :) Thank you so much!

EDIT: But for future reference, what exactly is e? Thats the only part of the code i don't quite understand.
Posted Image

This post has been edited by mattisdada: 29 May 2009 - 08:35 PM

Was This Post Helpful? 0
  • +
  • -

#4 Luc001  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 617
  • Joined: 04-May 09

Re: Move a form, by dragging an image

Posted 29 May 2009 - 11:10 PM

Quote

EDIT: But for future reference, what exactly is e? Thats the only part of the code i don't quite understand.



Hi,

Most events have two parameters that are passed to them. For example, the Click event:


Private Sub SearchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchButton.Click

	End Sub


By convention, "sender" is the variable used to define which object generated the event. So in this example, the sender variable references the SearchButton that I have on my form.

By convention, "e" is the variable used to define any arguments for the event. Depending on the event, e can have any number of properties and methods.

For example the Load event and Click event "e" variable has a basic set of properties/methods. The FormClosing event "e" variable has additional properties and methods such as the e.Cancel.

What e.Cancel does depends on the event. For example, in the FormClosing event, e.Cancel will prevent the form from closing, basically cancelling the close request.
Was This Post Helpful? 1
  • +
  • -

#5 mattisdada  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 92
  • Joined: 30-May 08

Re: Move a form, by dragging an image

Posted 30 May 2009 - 01:45 AM

Ah, that makes allot of sense! Thanks guys :) Big help!

Now i have a fully skinned basic app, now i can move onto a bigger project! (all my apps will be 100% skinned as they look way better that way, and makes them all unique)
Was This Post Helpful? 0
  • +
  • -

#6 ahmad_511  Icon User is offline

  • MSX
  • member icon

Reputation: 131
  • View blog
  • Posts: 722
  • Joined: 28-April 07

Re: Move a form, by dragging an image

Posted 30 May 2009 - 01:57 AM

you're welcome :)
and thanks Luc001 for explanation
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1