CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 22

Thread: 3 problems ...

  1. #1
    Join Date
    Nov 2007
    Posts
    49

    3 problems ...

    Hello all !

    I have 3 problems ...

    1. I trying to change the images in my program i run time
    I want that every time that I will hold mouse click down the image change
    and when I leave the button the image will come back to what it was ...

    I tried this code:

    Private Sub Image2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Image2.Picture = "D:\2.gif"
    End Sub

    Private Sub Image2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Image2.Picture = "D:\1.gif"
    End Sub

    this code return error ...

    How should I do it ?


    2. I designed GUI without borderstyle (borderstyle = 0) ...
    because of that the program is NOT in the taskbar how I can fix it ?


    3. I created move button but i don't know how to make it work ...
    I want that on click on this button the move will start to move the window
    How to do it ?

    thanks to helpers !
    Last edited by XtraCt; January 31st, 2008 at 04:17 PM.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: 3 problems ...

    I'll take the first one.
    Code:
    Option Explicit
    
    Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Image1.Picture = LoadPicture("c:\2.gif")
    End Sub
    
    Private Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Image1.Picture = LoadPicture("c:\1.gif")
    End Sub
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Nov 2007
    Posts
    49

    Re: 3 problems ...

    what the option explicit doing ?

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: 3 problems ...

    Change one line to this:
    Code:
    Imaze1.Picture = LoadPicture("c:\1.gif")
    and then press F5 to run it. It's priceless for finding typing mistakes that could crash later.

    If you go to Tools->Options and Tick REQUIRE VARIABLE DECLARATION, it'll get added automatically to each form/module/class for you. You'd have to add it to old forms.


    Require Variable Declaration — Determines whether explicit variable declarations are required in modules. Selecting this adds the Option Explicit statement to general declarations in any new module.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Nov 2007
    Posts
    49

    Re: 3 problems ...

    someone can help me with the other problems ?

    and thanks dglienna !

  6. #6
    Join Date
    Nov 2007
    Posts
    49

    Re: 3 problems ...

    I just succeed to solve the second problem ...

    Now I have to solve only the third one !

  7. #7
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: 3 problems ...

    To add to the first one first:
    I made similar buttons with pictures, but I don't load them every time you click on it from harddisk.
    A faster thing is: you keep the images in an ImagList control (add Microsoft Common Controls 6.0 to your toolbox).
    You can load the images into this list and have them in memory already when assigning them to the image controls. Just add an ImageList to your control, load the images into it, give them meaningful keys.
    As I have a large amount of these buttons, I took individual ImageLists, one for button-up-images, one for button-down-images, one for button-disabled. The code looks then:

    Code:
    ' imlUp is the ImageList for up-images, imlDn for down.
    Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Image1.Picture = imlDn.ListImages("Button1").Picture
    End Sub
    
    Private Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Image1.Picture = imlUp.ListImages("Button1").Picture
    End Sub
    No loading from disk takes place, then.

    As for number 3:
    I'd put a Timer on the form, (named timMove). Set interval to 100, as an example
    In the move-button click event: timMove.Enabled = True
    In the timMove_Timer() event you will put the code for moving. As you have not specified how the movement has to go, I cannot be more concrete here.
    You could
    Form1.Move Form1.Left+30, Form1.Top+30 or incrementing/decrementing Form1.Left = Form1.Left + 30
    With the above code the form will move 10 times per second for 2 pixels.
    I took 30 because this is 2 pixels on most screens.
    To be more independant, the number of twips per pixel can be taken from the Scren object
    Screen.TwipsPerPixelX
    Screen.TwipsPerPixelY

    The amount

  8. #8
    Join Date
    Nov 2007
    Posts
    49

    Re: 3 problems ...

    you can explain a little bit about the image list please ?

    1. I can use imagelist in VB6 ?
    2. Is it possible to store the images in the imagelist (in the EXE file) ?
    Last edited by XtraCt; February 1st, 2008 at 10:38 AM.

  9. #9
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: 3 problems ...

    Yes and yes.

    You have to add 'Microsoft Windows Common Controls 6.0' to your toolbox. This brings a set of new controls onto your toolbox. One of them being the ImageList.
    To use it, click and drag it to a form. Give it a meaningful name.
    Right click and select properties. In section 'Images' you can add files of .bmp, .gif or .jpg images to the list. They might be shown in a slightly distorted way, but that's normal. The images are stored in the exe then. You need not supply the bitmap files with the program.

    Each image in the list is then referred to by its index, or - and I prefer this method - by a key word you specify.
    I rather use the key because often the list may change during developement and deleting one image requires all indexed references above to be changed throughout your program.

    To assign an image from the ImageList to an Image control you go
    Image1.Picture = ImageList.ListImages("key").Picture or
    Image1.Picture = ImageList.ListImages(i).Picture
    depending on use of index or key.

  10. #10
    Join Date
    Nov 2007
    Posts
    49

    Re: 3 problems ...

    thanks about the image list !

    now i trying to make the move button
    so I want to create a button that when I click on him the form will move with the mouse movement ... got it ?
    just like I hold the left button of the mouse on the border of the window and drag him ...

    thanks again

  11. #11
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: 3 problems ...

    Use the TOP and LEFT form and set them to TOP and LEFT for Mouse in the mouse move section, but you have to set a drag/drop flag
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  12. #12
    Join Date
    Nov 2007
    Posts
    49

    Re: 3 problems ...

    I pretty new in VB6

    you can explain how to do it please ?

  13. #13
    Join Date
    Nov 2005
    Posts
    57

    Thumbs up Re: 3 problems ...

    problem 3:

    in the movemove event for the picture control:

    include a case for 'Button' to determine if you want te left or right mouse button to perform tricks.

    then use API GetCursorPos in the case statement

    the results of the API jam into > form.move

  14. #14
    Join Date
    Nov 2005
    Posts
    57

    Arrow Re: 3 problems ...

    DG: i think XtraCt wants to be able to move the image anywhere on the screen. There are no VB properties available that determine the screen position of the mousepointer are there?
    Last edited by vb_lover; February 1st, 2008 at 12:33 PM.

  15. #15
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: 3 problems ...

    Oh, there is everything you need.
    Do you want the same behaviour like dragging the form at the title bar?

    An example shows how to drag a form by grabbing it at a button.
    Use the below code in a form and add a button named Command1. This is where you grab the form.
    The relevant code for moving is in the MouseDown() and MouseMove() procedures.
    Code:
    Option Explicit
    Private Type POINTAPI
      X As Long
      Y As Long
    End Type
    
    Private Start As POINTAPI
    Private FPos As POINTAPI
    
    Private Declare Function GetCursorPos Lib "user32.dll" (ByRef lpPoint As POINTAPI) As Long
    
    Private Moving As Boolean
    
    
    Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
      GetCursorPos Start
      FPos.X = Form1.Left / Screen.TwipsPerPixelX
      FPos.Y = Form1.Top / Screen.TwipsPerPixelY
      Moving = True
    End Sub
    
    Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
      If Not Moving Then Exit Sub
      Dim NX&, NY&
      Dim NPos As POINTAPI
      GetCursorPos NPos
      NX = (FPos.X + NPos.X - Start.X) * Screen.TwipsPerPixelX
      NY = (FPos.Y + NPos.Y - Start.Y) * Screen.TwipsPerPixelY
      
      Form1.Move NX, NY
    End Sub
    
    Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
      Moving = False
    End Sub
    Last edited by WoF; February 1st, 2008 at 12:43 PM.

Page 1 of 2 12 LastLast

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

Featured