|
-
Mar 17th, 2009, 01:53 AM
#1
Thread Starter
Junior Member
Problem while resizing form controls........................
hi all,
I have one problem with resizing forms.
I am developing our application in vb and i gave code for resizing forms in resize event of form. First i save the sizes of all controls in forms in form load event and then in resize event i resizes all controls of form. So that my application can run on any screen resolution.
My problem is i am using tab control for what is happening is whatever tab is active at the time of running application that controls are visible to me but other tabs controls are not visible.
When i debug the application i found that other controls left value is coming in minus that is -68940.
That's why control is not visible to user after resizing it. I am getting the problem.
Can anybody tell me what is the problem with solution.
Thanks in advance.
Regards
Guest11
-
Mar 17th, 2009, 04:07 AM
#2
Member
Re: Problem while resizing form controls........................
Ok, I wouldn't know how to help really (not too good at VB) but I do know you need to get your english better. I didn't understand any of that...
Try the google translator:
translate.google.com
Edit: All I got is that you have some sort of problem with something resizing when you push TAB.
Edit 2: By the way, where are you from?
-
Mar 17th, 2009, 04:37 AM
#3
Thread Starter
Junior Member
Re: Problem while resizing form controls........................
I had developed my vb application on 1024*768 screen resolution. My application run properly on 1024*768 screen resolution but when we try to run my application on 800*600 screen resolution than some controls are not visible to user. For that problem i wrote some code in resize event of form for resizing all controls. But when i try to calculate, controls left side value(every control in vb had left and top position value) then i got its value in minus. (i.e -68940) and thats why when i resize its position than it is not visible to user.
From left means its x-axis value and top means its y-axis value.
Code is like this
' Save the form's and controls' dimensions.
Private Sub SaveSizes()
Dim i As Integer
Dim ctl As Control
' Save the controls' positions and sizes.
ReDim m_ControlPositions(1 To Controls.Count)
i = 1
For Each ctl In Controls
With m_ControlPositions(i)
If TypeOf ctl Is Line Then
.Left = ctl.X1
.Top = ctl.Y1
.Width = ctl.X2 - ctl.X1
.Height = ctl.Y2 - ctl.Y1
Else
.Left = ctl.Left
.Top = ctl.Top
.Width = ctl.Width
.Height = ctl.Height
On Error Resume Next
.FontSize = ctl.Font.Size
On Error GoTo 0
End If
End With
i = i + 1
Next ctl
' Save the form's size.
m_FormWid = ScaleWidth
m_FormHgt = ScaleHeight
End Sub
Private Sub Form_Load()
'
SaveSizes
'Me.Height = Screen.Height
'Me.Width = Screen.Width
End Sub
'Arrange the controls for the new size.
Private Sub ResizeControls()
'Picture2.Height = Me.ScaleHeight - Picture1.Height
'Picture2.Height = Picture1.Top
Dim i As Integer
Dim ctl As Control
Dim x_scale As Single
Dim y_scale As Single
' Don't bother if we are minimized.
If WindowState = vbMinimized Then Exit Sub
' Get the form's current scale factors.
x_scale = ScaleWidth / m_FormWid
y_scale = ScaleHeight / m_FormHgt
' Position the controls.
i = 1
For Each ctl In Controls
On Error Resume Next
With m_ControlPositions(i)
If TypeOf ctl Is Line Then
ctl.X1 = x_scale * .Left
ctl.Y1 = y_scale * .Top
ctl.X2 = ctl.X1 + x_scale * .Width
ctl.Y2 = ctl.Y1 + y_scale * .Height
Else
ctl.Left = x_scale * .Left
ctl.Top = y_scale * .Top
ctl.Width = x_scale * .Width
If Not (TypeOf ctl Is ComboBox) Then
' Cannot change height of ComboBoxes.
ctl.Height = y_scale * .Height
End If
On Error Resume Next
ctl.Font.Size = y_scale * .FontSize
On Error GoTo 0
End If
End With
i = i + 1
Next ctl
End Sub
Private Sub Form_Resize()
ResizeControls
End Sub
-
Mar 17th, 2009, 05:09 AM
#4
Member
Re: Problem while resizing form controls........................
Ok I'll leave it to the pros to help you, but just use the [ code ] [ /code ] tags, without the spaces.
-
Mar 17th, 2009, 07:51 AM
#5
Frenzied Member
Re: Problem while resizing form controls........................
Yes, what you describe is a function of the SSTab control. It groups the controls placed on each "tab" and "remembers" each position of each control while in actuality it is NOT like a group of picture boxes that you use the left property on to move each picture box out of the way. It is more like a single picture box that remembers your controls position and moves them out of the way for you when you click on another tab, and thus moves those grouped controls that belong to the tab you just clicked on into view.
Now, how to help you figure this out. I just placed a SSTab control on a form. Added a text box (Text1) with a left of 330. Then added another text box with a left of 1950. So when Tab1 is shown...
Text1.Left = 330
Text2.Left = 1950 (1950 - 330 = 1620 difference)
But when I activate Tab2 the left of the two controls goes to...
Text1.Left = -74670
Text2.Left = -73050 (74670 - 73050 = 1620 difference)
Do you follow what I am getting at?
No? then read on...
The SSTab control bases the lefts off of the control(s) furthest to the left to move the contained controls for each tab but keeps their spacings, tops, heights, and widths. So, what you will need to do is to test for which tab is active and use a default left value for the control(s) furthest to the left and base your resize off of that.
Good Luck
-
Mar 17th, 2009, 08:07 AM
#6
Re: Problem while resizing form controls........................
Another common solution is to put a Frame control on
each tab, then put your controls in the Frame.
If desired, you can set each Frame's BorderStyle=0
to hide it.
-
Mar 20th, 2009, 01:10 AM
#7
Thread Starter
Junior Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|