VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 306,833 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,771 people online right now. Registration is fast and FREE... Join Now!




Move a form, by dragging an image

 

Move a form, by dragging an image

mattisdada

29 May, 2009 - 06:18 AM
Post #1

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
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 - 06:23 AM

User is offlineProfile CardPM
+Quote Post


ahmad_511

RE: Move A Form, By Dragging An Image

29 May, 2009 - 07:00 AM
Post #2

MSX
Group Icon

Joined: 28 Apr, 2007
Posts: 514



Thanked: 37 times
Dream Kudos: 500
My Contributions
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
vb

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
User is offlineProfile CardPM
+Quote Post

mattisdada

RE: Move A Form, By Dragging An Image

29 May, 2009 - 07:26 PM
Post #3

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
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 smile.gif 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.
IPB Image

This post has been edited by mattisdada: 29 May, 2009 - 07:35 PM
User is offlineProfile CardPM
+Quote Post

Luc001

RE: Move A Form, By Dragging An Image

29 May, 2009 - 10:10 PM
Post #4

D.I.C Head
**

Joined: 4 May, 2009
Posts: 147



Thanked: 12 times
My Contributions
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:


CODE
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.
User is offlineProfile CardPM
+Quote Post

mattisdada

RE: Move A Form, By Dragging An Image

30 May, 2009 - 12:45 AM
Post #5

D.I.C Head
**

Joined: 30 May, 2008
Posts: 56


My Contributions
Ah, that makes allot of sense! Thanks guys smile.gif 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)
User is offlineProfile CardPM
+Quote Post

ahmad_511

RE: Move A Form, By Dragging An Image

30 May, 2009 - 12:57 AM
Post #6

MSX
Group Icon

Joined: 28 Apr, 2007
Posts: 514



Thanked: 37 times
Dream Kudos: 500
My Contributions
you're welcome smile.gif
and thanks Luc001 for explanation
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/20/09 10:55PM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month