Fix the size of a tab control

B

B. Meincke

I have a tab control on a custom switchboard form. I would like a way to fix
the size of this control but I don't see any obvious way, such as a "can
grow" property I could set to a value of False.

I have a series of command buttons that move around on the form (don't ask
why!) and I don't want them to resize the tab control when they hit the edge
of it.

Thanks in advance for any advice or suggestions.
 
S

Stuart McCall

B. Meincke said:
I have a tab control on a custom switchboard form. I would like a way to
fix
the size of this control but I don't see any obvious way, such as a "can
grow" property I could set to a value of False.

I have a series of command buttons that move around on the form (don't ask
why!) and I don't want them to resize the tab control when they hit the
edge
of it.

Thanks in advance for any advice or suggestions.

So don't let the buttons 'hit' the edge. Presumably you're moving the
buttons in code, so check for a collision as you perform the move, something
like:

If Command0.Left + Command0.Width > TabCtrl.Left + TabCtrl.Width Then
Command0.Left = (TabCtrl.Left + TabCtrl.Width) - Command0.Width
End If

That's air code so you may need to play around with it till it works, but
hopefully that gives you a start.
 
B

B. Meincke

I'm afraid this doesn't seem to work. The tab control just keeps growing to
accomodate the command buttons movement.

Is there no way to restrict the growth of the TabControl?

Thanks.
 
S

Stuart McCall

B. Meincke said:
I'm afraid this doesn't seem to work. The tab control just keeps growing
to
accomodate the command buttons movement.

Could you post a snippet of the code you're using to move the buttons? Then
maybe I or someone else on here might be able to help.
Is there no way to restrict the growth of the TabControl?

Not to my knowledge, although I've never tried to move controls around one.
Why do you need to do this anyway? (just curious)
 
B

B. Meincke

Stuart McCall said:
Could you post a snippet of the code you're using to move the buttons? Then
maybe I or someone else on here might be able to help.

Certainly...

Function MoveIt(strFormName As String, strControlName As _
String)

On Error GoTo Proc_Error

Dim iMoveX As Integer
Dim iMoveY As Integer

iMoveX = Int(1000 * Rnd()) - 500
iMoveY = Int(1000 * Rnd()) - 500

again:

Forms(strFormName).Controls(strControlName).Left = Forms
_(strFormName).Controls(strControlName).Left + iMoveX
Forms(strFormName).Controls(strControlName).Top = Forms
_(strFormName).Controls(strControlName).Top + iMoveY

Beep

Proc_Exit:
Exit Function
Proc_Error:
Select Case Err.Number
Case 2100
iMoveX = -iMoveX
iMoveY = -iMoveY
Resume again
Case Else
MsgBox "Error " & Err.Number
Resume Proc_Exit
End Select

End Function
Not to my knowledge, although I've never tried to move controls around one.
Why do you need to do this anyway? (just curious)
LOL...
It's an April Fools joke, actually. I can't think of a sane reason for
wanting to do such a thing myself.

The above function will be called for each command button on our
switchboard's OnMouseMove event. All command buttons are on five tabs of a
tab control.

The error handler stops the code from failing when buttons hit the edges of
the form, but I would like to restrict button movement to the tab control
area.

Hope this helps. Thanks for your continued assistance.

BJM
 
S

Stuart McCall

B. Meincke said:
Certainly...

Function MoveIt(strFormName As String, strControlName As _
String)

On Error GoTo Proc_Error

Dim iMoveX As Integer
Dim iMoveY As Integer

iMoveX = Int(1000 * Rnd()) - 500
iMoveY = Int(1000 * Rnd()) - 500

again:

Forms(strFormName).Controls(strControlName).Left = Forms
_(strFormName).Controls(strControlName).Left + iMoveX
Forms(strFormName).Controls(strControlName).Top = Forms
_(strFormName).Controls(strControlName).Top + iMoveY

Beep

Proc_Exit:
Exit Function
Proc_Error:
Select Case Err.Number
Case 2100
iMoveX = -iMoveX
iMoveY = -iMoveY
Resume again
Case Else
MsgBox "Error " & Err.Number
Resume Proc_Exit
End Select

End Function

LOL...
It's an April Fools joke, actually. I can't think of a sane reason for
wanting to do such a thing myself.

The above function will be called for each command button on our
switchboard's OnMouseMove event. All command buttons are on five tabs of a
tab control.

The error handler stops the code from failing when buttons hit the edges
of
the form, but I would like to restrict button movement to the tab control
area.

Hope this helps. Thanks for your continued assistance.

BJM

I had a quick play around with your code this morning, but was unable to
prevent the resizing of the tab control. Here's what I tried:

Function MoveIt(strFormName As String, strControlName As String)

'On Error GoTo Proc_Error

Dim iMoveX As Integer
Dim iMoveY As Integer
Dim newLeft As Integer, newTop As Integer
Dim Ctl As Access.Control

Set Ctl = Forms(strFormName).Controls(strControlName)
iMoveX = Int(1000 * Rnd()) - 500
iMoveY = Int(1000 * Rnd()) - 500

again:

newLeft = Ctl.Left + iMoveX
If (newLeft + Ctl.Width) > (TabCtl0.Left + TabCtl0.Width) Then
newLeft = (TabCtl0.Left + TabCtl0.Width) - Ctl.Width
End If
If newLeft < TabCtl0.Left Then newLeft = TabCtl0.Left
Ctl.Left = newLeft

newTop = Ctl.Top + iMoveY
If (newTop + Ctl.Height) > (TabCtl0.Top + TabCtl0.Height) Then
newTop = (TabCtl0.Top + TabCtl0.Height) - Ctl.Height
End If
If newTop < TabCtl0.Top Then newTop = TabCtl0.Top
Ctl.Top = newTop

Beep

'Proc_Exit:
' Exit Function
'Proc_Error:
' Select Case Err.Number
' Case 2100
' iMoveX = -iMoveX
' iMoveY = -iMoveY
' Resume again
' Case Else
' MsgBox "Error " & Err.Number
' Resume Proc_Exit
' End Select

End Function

Maybe you have more time than I do to polish it off, but that's the gist of
what I meant previously.

Good luck, and if you get this implemented I hope you manage to keep your
job ;-)
 
B

B. Meincke

Thanks for the effort, Stuart. We were on the same wavelength. I tried
placing two textboxes on the form to report the Top and Left values of the
tab control and they don't seem to update when the command buttons move
beyond their boundries, even though the control does, infact, resize.

<sigh>

Oh well, it's still fun even with the tab control expanding.

And, don't worry about my job, our administration is where I got my sense of
humour from...and I promise to have our database back to normal long before
it effects staff productivity!
 
B

B. Meincke

Good luck, and if you get this implemented I hope you manage to keep your
Just a quick note to let everyone know that my "marching button" April Fool
prank was received with the good natured humour it was intended to be. I
still have a job! LOL...

btw,
I managed to keep the command buttons' movement within the original
boundries of the tab control. I kind of cheated. It wasn't the most elegant
solution, but, what I ended up doing was drawing a hidden rectangle the same
size as the tab control and using it's boundries in the function's code to
define the range of movement for the buttons.

Thanks again for everyone's help.

BJM
 
S

Stuart McCall

B. Meincke said:
Just a quick note to let everyone know that my "marching button" April
Fool
prank was received with the good natured humour it was intended to be. I
still have a job! LOL...

Did anyone prank you? If not said:
btw,
I managed to keep the command buttons' movement within the original
boundries of the tab control. I kind of cheated. It wasn't the most
elegant
solution, but, what I ended up doing was drawing a hidden rectangle the
same
size as the tab control and using it's boundries in the function's code to
define the range of movement for the buttons.

Well in all it hasn't been a wasted post. Interesting that the tab control's
size cannot be fixed (no way I can find, anyhow). Noted for future
reference...
 
H

Homer J Simpson

Well in all it hasn't been a wasted post. Interesting that the tab
control's size cannot be fixed (no way I can find, anyhow). Noted for
future reference...

Note that in VB6 the tab controls are defaulted to have an option box on
them (which is moved far to the left to fake which controls are visible).
Maybe that's the solution?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top