Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move cmdButton at runtime 2

Status
Not open for further replies.

TallOne

Programmer
May 14, 2004
164
US
Hello All,

I'm using VB6. I've got a form that contains a frame that contains a datagrid and a cmdbutton. In my form_resize event I call a sub ResizeFrame which resizes the frame just a bit smaller than the form. Inside ResizeFrame I resize the datagrid (width a bit smaller than the frame and height minus enough height to fit a command button below the datagrid). I enforce minheight and minwidth for the form. Everythings works fine but dynamically moving the cmdbutton! How could I always force the command button to stay just a bit below the grid? Any suggestions would be great! TIA

Here's my code

Private Sub ResizeFrame()
Dim fra As Control ' Test for Frame
For Each fra In Me.Controls ' Get all controls
If TypeOf fra Is Frame Then
If fra.Visible = True Then
fra.Top = 10
fra.Left = 0
fra.Width = frmMain.ScaleWidth
fra.Height = frmMain.Height - 1200
Exit For 'We found the control to change. Only one frame visible at a time FOR NOW
End If
End If
Next

DataGrid1.Width = Me.fraCustomerView.Width - 50 'Think of way to make this work with the frame that's visible

DataGrid1.Height = Me.fraCustomerView.Height - 1000
'Call ResizeDataGrid this sub not working

End Sub


Private Sub Form_Resize()
'Check to see if form's getting too
'small forcing a min height and width
If Me.WindowState = vbMinimized Then Exit Sub 'Avoid error-NO resize if minimized
If MinHeight > frmMain.Height Then
frmMain.Height = MinHeight

ElseIf MinWidth > frmMain.Width Then
frmMain.Width = MinWidth
End If
Call ResizeFrame
End Sub

Private Sub ResizeDataGrid()

Dim grid As Control ' Test for datagrid
For Each grid In Me.Controls ' Get all controls
If TypeOf grid Is DataGrid Then
If grid.Visible = True Then
grid.Width = Me.fraCustomerView.Width - 50 'Think of way to make this work with the frame that's visible
grid.Height = Me.fraCustomerView.Height - 1000
End If
Exit For 'Found the control to change. Only one frame visible at a time FOR NOW
End If
Next
End Sub

Any suggestions would be super!
 
First of all, it seems a little unnecesary to do a For Each every time you wantto change the size of a control, can't you just call it directly by name? After all you do call them by name in some cases, like:

<CODE>
grid.Width = Me.fraCustomerView.Width - 50
grid.Height = Me.fraCustomerView.Height - 1000
</CODE>

Anyway,
You should call the move button calls in ResizeDataGrid (in your example) right before the exit for.

<CODE>
cmdButton.Top = grid.Top + grid.Height '(+ margin)
cmdButton.Left = grid.Left + grid.Width '(+ margin)
<CODE>
 
johpje,

Hi thanks for your reply! Yeah, I do call them by name as in...Me.fraCustomerView.Width - 50

<CODE>
grid.Width = Me.fraCustomerView.Width - 50
grid.Height = Me.fraCustomerView.Height - 1000
</CODE>

But I'd rather not. My ultimate goal would be to think of a way to call me.fracustomerview.width without actually referring to fracustomerview but to whichever frame is visible. My thinking is making reusable routines. I'm sure I'll have more datagrids and frames in the future. Do you think this way of resizing these controls takes too much processing time or something? I'm wondering if there is a way to resize the current visible frame and datagrid without iterating over every control AND not calling them by name. Anyways all help will be greatly appreciated as this is my first project! Oh, :( why isn't Private Sub ResizeDataGrid() not working?


Hmmm maybe I'm trying to use frames in place of MDI forms...
I'm losing my hair!
 
Any comments on my logic or code would be warmly welcomed! :) I'm definately losing sleep daily ever since I met Visual Basic...
 
I have slightly modified your code and it does what you describe in your first post. As far as not calling the controls by name, I am sure it is possible but we will have to call on some of the VB Great's in this forumn.... you can get a start by looking at the ActiveControl property of the form. Not sure that this will ever contain a frame but it would contain a datagrid and from there you can maybe get the datagrids parent... ???

Code:
Private Sub ResizeFrame()
Dim fra As Control ' Test for Frame
For Each fra In Me.Controls ' Get all controls
    If TypeOf fra Is Frame Then
        If fra.Visible = True Then
            fra.Top = 10
            fra.Left = 0
            fra.Width = frmmain.ScaleWidth
            fra.Height = frmmain.Height - 1200
            Exit For 'We found the control to change.  Only one frame visible at a time FOR NOW
        End If
    End If
Next

DataGrid1.Width = Me.fraCustomerView.Width - 50 'Think of way to make this work with the frame that's visible

DataGrid1.Height = Me.fraCustomerView.Height - 1000
Call ResizeDataGrid 'this sub not working
Command1.Top = fraCustomerView.Height - 550
End Sub


Private Sub Form_Resize()
'Check to see if form's getting too
'small forcing a min height and width
If Me.WindowState = vbMinimized Then Exit Sub 'Avoid error-NO resize if minimized
If MinHeight > frmmain.Height Then
        frmmain.Height = MinHeight

ElseIf MinWidth > frmmain.Width Then
        frmmain.Width = MinWidth
End If
Call ResizeFrame
Call ResizeDataGrid
End Sub

Private Sub ResizeDataGrid()

Dim grid As Control ' Test for datagrid
For Each grid In Me.Controls ' Get all controls
    If TypeOf grid Is DataGrid Then
        If grid.Visible = True Then
            grid.Width = Me.fraCustomerView.Width - 200 'Think of way to make this work with the frame that's visible
            grid.Height = Me.fraCustomerView.Height - 1000
        End If
        Exit For 'Found the control to change.  Only one frame visible at a time FOR NOW
     End If
Next
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top