Results 1 to 13 of 13

Thread: [RESOLVED] Moving an image with the stylus..

  1. #1

    Thread Starter
    Addicted Member noam309's Avatar
    Join Date
    Aug 2006
    Posts
    225

    Resolved [RESOLVED] Moving an image with the stylus..

    Hi,

    I have a picture in a picture box , and the picture is lager then the picturebox , I want to use the stylus to drag and move the picture in the picturebox , how to do this ?
    does somebody have a code for this? it would be very helpfull.

    thanks

    Giving an exact answer
    Saves a lot of time!!!

  2. #2
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Moving an image with the stylus..

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

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

    End Sub

    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove

    If bDragging Then
    With PictureBox1
    nx = .Left - sx + e.X
    ny = .Top - sy + e.Y
    .Location = New System.Drawing.Point(nx, ny)
    End With
    End If

    End Sub
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  3. #3

    Thread Starter
    Addicted Member noam309's Avatar
    Join Date
    Aug 2006
    Posts
    225

    Unhappy Re: Moving an image with the stylus..

    seems to be good , but what should I do with this errors I got.
    what to declare these variables?



    Thanks.

    Giving an exact answer
    Saves a lot of time!!!

  4. #4
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Moving an image with the stylus..

    declare sx, sy and bdragging
    private sx as double
    private sy as double
    private ny as double
    private nx as double
    private bDragging as boolean
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  5. #5

    Thread Starter
    Addicted Member noam309's Avatar
    Join Date
    Aug 2006
    Posts
    225

    Question Re: Moving an image with the stylus..

    hi Petevick,

    it doesn't allow to declare the variables as private, so I declared them as dim,
    is it right ? what the diference between private and dim?

    and it gives error like you can see with the printscreen, what should I do?



    thanks,

    Giving an exact answer
    Saves a lot of time!!!

  6. #6
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Moving an image with the stylus..

    Hi,
    you need to declare them in the form, or you will lose the values when you exit the subroutines!

    Where did you get the Picturebox2 = True and False from - certainly not the code I posted.

    I posted bDragging = true and bDragging = false to signify the 'mouse' is down, so you drag on a mouse move
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  7. #7

    Thread Starter
    Addicted Member noam309's Avatar
    Join Date
    Aug 2006
    Posts
    225

    Unhappy Re: Moving an image with the stylus..

    hi Petevick,

    sory for bothring you.

    I have entered your code exactly as is , but as you can see the private doesn't work. so I had to declare every variable few time with the events you have entered.
    and change somethings,
    here is the exact code you've entered but with dim ,because it gives a lot of errors,as you can see with the example:



    and this is the form with picture on it ,and its propertise:


    I have try to put the declaration with form load , and the upper part of the code before the sub begins , the declaration part , but also it doesn't work.

    the PRIVATE declaration should be in a modul ,class, and so, but it doesn't work with the form , which event should it be in ?

    thx.

    Giving an exact answer
    Saves a lot of time!!!

  8. #8
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Moving an image with the stylus..

    HI,
    the code hasn't made it - but you HAVE TO declare the variables as private to the form or the routines simply won't work.

    Private at form level means the whole form can use the variables, and they retain their value. If you just declare them in the sub, then as soon as you leave the sub, the value is lost.

    You must be doing something wrong, or trying to declare them in the wrong place.

    They should go like:-


    Public Class frmMain
    Private pubDate As Date
    Private title As String
    Private description As String
    Private hDescription As String
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  9. #9

    Thread Starter
    Addicted Member noam309's Avatar
    Join Date
    Aug 2006
    Posts
    225

    Unhappy Re: Moving an image with the stylus..

    Hi,

    Now it looks like this:


    did I was wrong with the location of the declaration?
    as you can see I got a lot of errors ,what to do?

    do you have an example of a code that you can give me that I'll look how it is with a comlete source code.

    looking forward to your answer.

    Giving an exact answer
    Saves a lot of time!!!

  10. #10
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Moving an image with the stylus..

    Why is this code in a class called help, and not in the form class????


    That is probably why you are getting errors as picturebox2 is presumably part of frmMain and not the help class

    In your form, click on picturebox, and then click on events and generate the mouseup, mousedown and mousemove events
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  11. #11

    Thread Starter
    Addicted Member noam309's Avatar
    Join Date
    Aug 2006
    Posts
    225

    Exclamation Re: Moving an image with the stylus..

    Did you meant something like this?



    It works very well to move a fixed picture, I mean I can move the picture with the stylus but freely ,it is very nice for something else I'm doing.

    but what I meant is that I have a picture as you can see with the printscreen



    and it is in a picturebox ,and it is in normal size so I can't see the rest of the picture, and with the stylus I want to move the picture in the picturebox so I can see the rest of the picture, hope I understand myself.
    Last edited by noam309; Sep 3rd, 2010 at 09:36 AM.

    Giving an exact answer
    Saves a lot of time!!!

  12. #12
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Moving an image with the stylus..

    Ah - Drop the picture box into a panel and make the picturebox larger than the panel that should do it.

    Similar to the code at http://www.codeproject.com/KB/vb/PanExample.aspx
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  13. #13

    Thread Starter
    Addicted Member noam309's Avatar
    Join Date
    Aug 2006
    Posts
    225

    Thumbs up Re: Moving an image with the stylus..

    Very Good ! THANK YOU VERY MUCH! IT IS VERY HELPFULL.
    THANK YOU ALSO FOR YOUR PATIENCE.

    Giving an exact answer
    Saves a lot of time!!!

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