• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2439
  • Last Modified:

moving and resizing frames in runtime by user in VB

I use frames with grids on it, sometimes I want or:  the frame to move on the screen or: resize the frame while running the program.   How can I do this in VB6?
0
BIAPRO
Asked:
BIAPRO
  • 10
  • 7
1 Solution
 
itzyCommented:
0
 
BIAPROAuthor Commented:
this sample gives me the option to resize a form, and  works, my problem is  I have on a form a frame wich needs to be resized, so how can i do that ?
0
 
BrianVSoftCommented:
Resizing a frame and the grid on it can be done easily using two "Move" or "Width" statements..
How & when do you want the resize to occur? On Form ReSize ?

Eg. In Form_Resize event..
      NewWidth! = Me.Width * Ratio3: NewHite! = Me.Height * Ratio4
      Frame1.Width = NewWidth! : Frame1.Height = NewHite!
      Grid1.Width = NewWidth! - 230: Grid1.Height = NewHite! - 330

If you want the user to be able to resize the frame using the mouse you can use this attached code example..

' Example enabling a User to resize a Frame with a Grid using a tiny label as a handle..
' Add Frame1 to the form.. Add Grid1 to the frame and a tiny colored Label (Handle1)(150x150) in the bottom right of the frame..
Dim OrigX As Single, OrigY As Single ' Original Top & Left of mouse down
Dim OrigFX As Single, OrigFY As Single ' Original Top & Left of Frame
' Note.. The handle can only be dropped on an object that has a DragDrop event setup..
' Hence, both the Form and the Grid need the DragDrop event as shown..
 
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
  If Source.Name = "Handle1" Then
    With Frame1
      NewWidth! = .Width + X - OrigX - OrigFX: NewHite! = .Height + Y - OrigY - OrigFY
      .Move OrigFX, OrigFY, NewWidth!, NewHite!
      Grid1.Width = NewWidth! - 230: Grid1.Height = NewHite! - 330
      Handle1.Move NewWidth! - 150, NewHite! - 150
    End With
  End If
End Sub
 
Private Sub Grid1_DragDrop(Source As Control, X As Single, Y As Single)
  If Source.Name = "Handle1" Then
    With Frame1
      NewWidth! = .Width + X - OrigX: NewHite! = .Height + Y - OrigY
      .Move OrigFX, OrigFY, NewWidth!, NewHite!
      Grid1.Width = NewWidth! - 230: Grid1.Height = NewHite! - 330
      Handle1.Move NewWidth! - 150, NewHite! - 150
    End With
  End If
End Sub
 
Private Sub Handle1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  If Button = 1 Then
    Handle1.Drag vbBeginDrag
    OrigX = X + Handle1.Left: OrigY = Y + Handle1.Top
    OrigFX = Frame1.Left: OrigFY = Frame1.Top
  End If
End Sub

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
BIAPROAuthor Commented:
ok, I got it running, with a few new modifications due to settings in my system like lbl(name),
it moves the frame,  but at releasing mouse button it jumps back to original postition??
I can't get it in "sizing" mode.
this is the source now
Option Explicit

Public OrigX As Single, OrigY As Single
Public OrigFX As Single, OrigFY As Single
Public NewWidth!, NewHite!

Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
  If Source.Name = "lblHandle1" Then
    With fraFRAME1
      NewWidth! = .Width + X - OrigX - OrigFX: NewHite! = .Height + Y - OrigY - OrigFY
      .Move OrigFX, OrigFY, NewWidth!, NewHite!
      Grid1.Width = NewWidth! - 230: Grid1.Height = NewHite! - 330
      lblhandle1.Move NewWidth! - 150, NewHite! - 150
    End With
  End If
End Sub
 
Private Sub Grid1_DragDrop(Source As Control, X As Single, Y As Single)
  If Source.Name = "lblHandle1" Then
    With fraFRAME1
      NewWidth! = .Width + X - OrigX: NewHite! = .Height + Y - OrigY
      .Move OrigFX, OrigFY, NewWidth!, NewHite!
      Grid1.Width = NewWidth! - 230: Grid1.Height = NewHite! - 330
      lblhandle1.Move NewWidth! - 150, NewHite! - 150
    End With
  End If
End Sub
 
Private Sub lblHandle1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  If Button = 1 Then
    lblhandle1.Drag vbBeginDrag
    OrigX = X + lblhandle1.Left: OrigY = Y + lblhandle1.Top
    OrigFX = fraFRAME1.Left: OrigFY = fraFRAME1.Top
  End If
End Sub

0
 
BrianVSoftCommented:
Your code works fine when I paste it onto a form..
!st thing to check..
You are probably "Dropping" on an object that doesn't have a DragDrop event setup.. (Eg the Frame)
Whatever the mouse is over when you release the button has to have a DragDrop event..
In my example, the Frame itself was just a thin line around the grid and so was not likely to be dropped on..
When enlarging the frame, you are probably dropping on the form..
When shrinking the frame you might be dropping on the Grid OR the Frame..

If much of your frame is visible, you need to duplicate the Grid1_DragDrop code onto the Frame DragDrop
(and change or remove the border constants (eg - 230)
0
 
BIAPROAuthor Commented:
I realy don''t know what i do wrong, I still have a situation that the fram moves'and jump back to orginal location,
I did try it just with a empty frame without grid, same situation.
0
 
BrianVSoftCommented:
Try adding a break (F9) to all the lines..
   If Source.Name = "lblHandle1"
Depending on where the mouse is when you "drop", one of these lines should stop execution and you can step thru the math..
I suspect you will NOT get a break.. (because your mouse is over some object OTHER than the Form or the Grid or the Frame)
 (Whatever the mouse is over when you release the button has to have a DragDrop event..)
Try pasting your code onto a new project? - It works here!
0
 
BIAPROAuthor Commented:
I Get a break and the frame does change to very large after releasing mouse button when I chaneg the source to

Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
  If Source.Name = "fraFRAME1"   then      '  rem  "lblHandle1" Then
    With fraFRAME1
0
 
BrianVSoftCommented:
Ok, You are dragging the Frame.. You must drag the tiny Handle instead.. (the Label lbHandle1 which you placed at the bottom right corner of the Frame) Using a handle label makes the math simpler and gives the user a visual indicator that the Frame is Sizeable.. (you set the font of the lbHandle to MARLETT and add the character that normally represents "Sizeable")
0
 
BIAPROAuthor Commented:
I did upload what I have, only did change grid object to a lst object due to the grid is a third party active x i use.
So please take a look at it , think will be easier dor see whre I 'm  the dummy
Thanks
0
 
BIAPROAuthor Commented:
can't upload site says extension not allowed
0
 
BrianVSoftCommented:
Don't send your full code, I think the problem is not with the code, I think the form layout is not correct or you are Dragging the frame instead of the handle (the Label lbHandle1)
1. Is this label should be visible at the bottom right corner of the Frame?
2. Are you clicking on (and dragging) this label when you try to resize the frame?
 (You said earlier that you could see the frame move when you dragged the mouse.. That means you were dragging on the Frame! You must Drag the tiny label NOT the Frame!
3. Place my original code on a new form in a new project.. Place the tiny label on the frame,  place a grid or another large label called Grid1on the frame (covering most of the frame) and run the code.. Drag the tiny label (Handle1) outward (to make the frame larger) and see if it works..
Then experiment with shrinking and adding your real grid.
Once you understand how this example works - you can apply that knowledge to your real app.
0
 
BIAPROAuthor Commented:
ok , what would be the setting s off propertys on the form, frame,grid, because maybe I do wrong there.
I did all you did send  above,  still not what I want, sorry
0
 
BrianVSoftCommented:
See if you can extract a working VB project from this zip file..
UnZip the two files and then change their extensions by renaming them in windows explorer

Eg. Rename  Project1_vbp.txt  to  Project1.vbp
and   Form1_frm.txt  to  Form1.frm


TestDrag2.zip
0
 
BIAPROAuthor Commented:
OK Now it works, but what I see, (and mayby somehow, just can 't figure out , is that the reason my work did not doit.   )  is that the frame and label are not at design time ajustable in size,  like I can do normaly,
right ??
0
 
BrianVSoftCommented:
No.. The layout of that form is simply locked by clicking the "Lock Controls" icon which is found in the "Format" menu of VB itself. You can UnLock the layout via the same icon.
All the "Lock Controls" does is prevent objects from moving accidentally as you select them..
0
 
BIAPROAuthor Commented:
thanks a lot, I gave you lots off trouble!, but you did great for me!
regards Jack
0
 
BIAPROAuthor Commented:
Hello I added this code, now the frame can also be moved.
'--------added---------
Public Initialized As Boolean
Public OK_To_Move As Boolean
Private Type POINTAPI
 X As Long
 Y As Long
End Type
 
'--------added---------
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

 
'--------added---------
Private Sub Frame1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'If Shift = vbShiftMask Then   'this case shit is needed also
If Button = vbLeftButton Then
OK_To_Move = True
End If
'End If
End Sub


'--------added---------
Private Sub Frame1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static LastPoint As POINTAPI
Dim CurrentPoint As POINTAPI
If OK_To_Move Then
If Button = 1 Then
GetCursorPos CurrentPoint
If Not Initialized Then
LastPoint.X = CurrentPoint.X
LastPoint.Y = CurrentPoint.Y
Initialized = True
End If
With Frame1
.Move .Left + Screen.TwipsPerPixelX * (CurrentPoint.X - LastPoint.X), .Top + Screen.TwipsPerPixelY * (CurrentPoint.Y - LastPoint.Y)
End With
LastPoint = CurrentPoint
End If
End If
 
End Sub
 
'--------added---------
Private Sub Frame1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Initialized = False
OK_To_Move = False
End Sub

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 10
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now