outline moves but not picture box
outline moves but not picture box
outline moves but not picture box
outline moves but not picture box
outline moves but not picture box
outline moves but not picture box outline moves but not picture box outline moves but not picture box outline moves but not picture box outline moves but not picture box outline moves but not picture box outline moves but not picture box outline moves but not picture box
outline moves but not picture box outline moves but not picture box
outline moves but not picture box
Go Back  Xtreme Visual Basic Talk > > > outline moves but not picture box


Reply
 
Thread Tools Display Modes
  #1  
Old 01-08-2017, 11:24 AM
starmanMike starmanMike is offline
Junior Contributor
 
Join Date: Oct 2005
Location: near Norwich, UK
Posts: 263
Default outline moves but not picture box


Thought I'd posted this earlier today, but it seems not! OK, I am rewriting parts of a previous app for which the following code was recommended. All I want to do is allow the user (i.e.,me) to drag a picture box across the screen. Nothing else, nothing special - just a simple 'conventional' move with the mouse down so that when the mouse button is released the picture box (with loaded picture) is somewhere else.
Code:
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Static lx As Single, ly As Single
  If Button = vbLeftButton Then 'or vbRightButton
    Picture1.Left = Picture1.Left + (X - lx)
    Picture1.Top = Picture1.Top + (Y - ly)
  Else
    lx = X: ly = Y
  End If
End Sub
...which worked on that occasion, for which thanks. But now what happens is that the outline moves but not the picture! So, what am I missing? Do I need to change some properties of the picture box, and/or write more code for various mouse procedures? I note in the above code the variables lx and ly are given no values, so they will both be zero.
Reply With Quote
  #2  
Old 01-08-2017, 02:50 PM
Cerian Knight's Avatar
Cerian Knightoutline moves but not picture box Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,177
Default

Not sure if it is your issue, but that method of moving the picture assumes the Form ScaleMode is Twips.

If the form ScaleMode is (and needs to be) Pixels, then you will have to divide (X-lx) and (Y-ly) by Screen.TwipsPerPixelX/Y.
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
  #3  
Old 01-08-2017, 04:09 PM
starmanMike starmanMike is offline
Junior Contributor
 
Join Date: Oct 2005
Location: near Norwich, UK
Posts: 263
Default

Just checked, yes the form's scalemode is twips.
On the issue of those lx and ly variables, I don't really understand what they are or where their values are got from. Looking at the quoted code (which indeed did work on that previous occasion) they presunably have values of 0, since they are created in the sub and aren't changed by anything else. So what are they doing there? 'Button' is always vbleftbutton by the way.
Reply With Quote
  #4  
Old 01-08-2017, 04:44 PM
Cerian Knight's Avatar
Cerian Knightoutline moves but not picture box Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,177
Default

In the code 'Else' clause, the lx and ly are made equal to the X and Y values of the mouse position within the picture box as you move it without the left button depressed. Because they are Static, they can be used as a reference to find out how far the pointer has moved from its starting point as you begin moving with the left button depressed.

It works fine for me, so if it worked for you and then stopped, consider other places in your code that might also be trying to simultaneously manage the position of the PictureBox.

There is a setting in Windows (Enhance Pointer Precision) that affects the granularity of the mouse (I usually turn it on)... probably not related to the issue, though.
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
  #5  
Old 01-08-2017, 05:27 PM
starmanMike starmanMike is offline
Junior Contributor
 
Join Date: Oct 2005
Location: near Norwich, UK
Posts: 263
Default

Thanks for that - but I'm confused (nothing new there then!) -
How can I move the picture box at all without the left mouse button depressed? Surely the only way to drag the box is to have the left mouse button depressed coz that's what dragging is! In fact in the else clause I wrote a "do nothing" comment because there would be no 'else' as the left mouse button would have to be 'the one'.
Reply With Quote
  #6  
Old 01-08-2017, 06:07 PM
Cerian Knight's Avatar
Cerian Knightoutline moves but not picture box Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,177
Default

The 'Else' clause always fires while the mouse button is not pressed to update the current position. Once the button is pressed, lx and ly still hold the last known unpressed coordinates so the differential coordinates can be calculated and applied dynamically.

Debug.print all the values (including Picture1.Top and .Left, as well) in the IDE so you can watch dynamically.
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
  #7  
Old 01-08-2017, 06:09 PM
starmanMike starmanMike is offline
Junior Contributor
 
Join Date: Oct 2005
Location: near Norwich, UK
Posts: 263
Default

OK, I will try that tomorrow (it's past 1 a.m. here) with the code exactly as suggested. Thanks in advance.
Reply With Quote
  #8  
Old 01-09-2017, 08:04 AM
starmanMike starmanMike is offline
Junior Contributor
 
Join Date: Oct 2005
Location: near Norwich, UK
Posts: 263
Default

Just tried and nope, outline moves (not picture) and when the mouse button is released outline snaps back to the unmoved picture. I just get the feeling that I'm missing out something so simple, like a certain property having to be some setting or other. And, as I said, the provided code worked before - so something's changed other than the code. It's worth saying that the main form - well, there is only the one form - is always maximised and it contains a stationary picture box. It's a star-charting/reporting app and the fixed picture box contains a closeup star chart, while the picture box I want to drag is the 'finder' chart, a bigger-scale view but a much smaller box. I need to be able to drag it as it can obscure parts of the main chart.

Last edited by starmanMike; 01-09-2017 at 10:12 AM.
Reply With Quote
  #9  
Old 01-09-2017, 02:42 PM
Cerian Knight's Avatar
Cerian Knightoutline moves but not picture box Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,177
Default

Make sure there is no conflicting MouseUp/Down/Click event code.

Is the 'finder' container the main chart or the form?

Perhaps show us the 'finder' PictureBox properties/values (or delete it and re-create it, letting us know exactly which properties you changed). Also, show us the exact code you are using for MouseMove, if it is different than the code in the first post.
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
  #10  
Old 01-10-2017, 03:21 PM
starmanMike starmanMike is offline
Junior Contributor
 
Join Date: Oct 2005
Location: near Norwich, UK
Posts: 263
Default

I have attached screen shots of
1) The main screen with properties window
2) Main picture box 1 with props window
3) 'Problem' picture box 2 with props window.
There is a mouse click event for PB2 but this only applies to rt-click, which makes the box invisible. This arrangement worked before (i.e. you could rt-click on the chart and drag it, though not both at the same time!) - so could I write the drag procedure, if possible, into the 'button_click' event; if right click, hide the pic, if left click, run the dragging code?
It's doubly frustrating, because I have the working 'personal' installed app running on my laptop but of course it's been compiled and the code isn't retrievable. I also have part of that working code but unfortunately not that part of it!
It's also frustrating because what I want to do should be so simple - just drag a graphic with the mouse - so thanks a load for bearing with me.
Attached Images
File Type: gif main screen.gif (41.4 KB, 8 views)
File Type: gif picture1props.gif (33.9 KB, 7 views)
File Type: gif picture2props.gif (35.2 KB, 6 views)
Reply With Quote
  #11  
Old 01-10-2017, 04:17 PM
passel's Avatar
passeloutline moves but not picture box passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,015
Default

Quote:
Originally Posted by Cerian Knight View Post
Not sure if it is your issue, but that method of moving the picture assumes the Form ScaleMode is Twips.
...
That isn't quite correct.
The code assumes the ScaleMode of the picturebox and the container are the same. They have to match, so could both be twips, or pixels, or points, etc...

I don't understand how the outline can move independent of the picture unless there was other code that used the MouseCapture (i.e. releaseCapture and sendMessage method) to move the window, and your options were to set to "show outline" when dragging.

But perhaps you're drawing the Outline in the container by some other method independent of the picturebox being moved.

Getting back to my original comment about the scalemode (or perhaps more correctly, the scale units) needing to be the same, your property windows indicate that the container picturebox's scalemode is "User" while the embedded picturebox's scalemode is "twips".
Perhaps that is the source of the failure (as I don't understand the complete situation, but that is one thing that is wrong regardless).

To have a more generic routine that should be able to convert relative motion in the child picturebox to relative motion of the container regardless of the scales in the two boxes, you need to use the ScaleX and ScaleY functions to convert between the scales.

An example where picture1 is inside picture2, and picture2's scale is arbitrarily set to a user scale with 0,0 in the middle and the width and height are around 200,200 regardless of the actual dimensions of the outer picture box.
The code should adapt the movement of the mouse in one scale to picturebox movement in the other arbitrary scale.
Code:
Option Explicit

Private Sub Form_Load()
  Picture2.Scale (-100, -100)-(100, 100)
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Static lx As Single, ly As Single
  Dim dx As Single, dy As Single
  If Button = vbLeftButton Then 'or vbRightButton
    dx = Picture2.ScaleX(X - lx, Picture1.ScaleMode, Picture2.ScaleMode)
    dy = Picture2.ScaleY(Y - ly, Picture1.ScaleMode, Picture2.ScaleMode)
    
    Picture1.Left = Picture1.Left + dx
    Picture1.Top = Picture1.Top + dy
  Else
    lx = X: ly = Y
  End If
End Sub
Replace Picture2 with whatever your container's name is.

Again, I don't fully understand the problem so don't know if this will fix it, but it definitely is an issue in any case.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #12  
Old 01-10-2017, 04:57 PM
passel's Avatar
passeloutline moves but not picture box passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,015
Default

I'm getting ready to head home, so I was just doing a double-check before heading out.

I noticed that the code you posted was to move picture1.
But in your screen captures, you indicate you want picture2 to be draggable.

So, is that your problem?
Is that what you mean by saying the outline is dragged (picture box 1) and not the picture (picture box 2)?
Are you just referencing the wrong control?

(The more generic code that self adapts to scalemode differences between parent and child could still be useful though).
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #13  
Old 01-11-2017, 04:41 AM
starmanMike starmanMike is offline
Junior Contributor
 
Join Date: Oct 2005
Location: near Norwich, UK
Posts: 263
Default

Hi - and I have to say you fellas are f***ing brilliant. Just changed the main picbox scalemode to twips, and instant success! It was that simple.
Huge, huge thanks and a pint of warm British beer for you.
Even managed to combine both hide the picbox and drag the picbox into the one picture2_click event - rt click and it disappears, left click and the drag routine runs.

Last edited by starmanMike; 01-11-2017 at 12:06 PM.
Reply With Quote
Reply

Tags
picture, single, box, mouse, code, picture1.top, outline, integer, picture1.left, button, moves, missing, properties, change, occasion, and/or, write, values, procedures, note, variables, vbrightbutton, vbleftbutton, move, conventional


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
outline moves but not picture box
outline moves but not picture box
outline moves but not picture box outline moves but not picture box
outline moves but not picture box
outline moves but not picture box
outline moves but not picture box outline moves but not picture box outline moves but not picture box outline moves but not picture box outline moves but not picture box outline moves but not picture box outline moves but not picture box
outline moves but not picture box
outline moves but not picture box
 
outline moves but not picture box
outline moves but not picture box
 
-->