PDA

Click to See Complete Forum and Search --> : Resize User Control - Very Urgent


venkatraman_r
Jan 9th, 2000, 02:24 PM
Hi all,

Here is a piece of code that I got from somewhere...This code was used in a function and that function was called in the resize event of the form, and it works well. But I need to put this in a user control and I want it to call it in my form. I opened the usercontrol project and the code is as under;

Private Sub UserControl_Initialize()
Dim tmpControl As Control
On Error Resume Next
'Ignores errors in case the control doesn't
'have a width, height, etc.

If PrevResizeX = 0 Then
'If the previous form width was 0
'Which means that this function wasn't run before
'then change prevresizex and y and exit function
PrevResizeX = FormName.ScaleWidth
PrevResizeY = FormName.ScaleHeight
Exit Sub
End If

For Each tmpControl In FormName
'A loop to make tmpControl equal to every
'control on the form

If TypeOf tmpControl Is Line Then
'Checks the type of control, if its a
'Line, change its X1, X2, Y1, Y2 values
tmpControl.X1 = tmpControl.X1 / PrevResizeX * FormName.ScaleWidth
tmpControl.X2 = tmpControl.X2 / PrevResizeX * FormName.ScaleWidth
tmpControl.Y1 = tmpControl.Y1 / PrevResizeY * FormName.ScaleHeight
tmpControl.Y2 = tmpControl.Y2 / PrevResizeY * FormName.ScaleHeight
'These four lines see the previous ratio
'Of the control to the form, and change they're
'current ratios to the same thing
Else
'Changes everything elses left, top
'Width, and height
tmpControl.Left = tmpControl.Left / PrevResizeX * FormName.ScaleWidth
tmpControl.Top = tmpControl.Top / PrevResizeY * FormName.ScaleHeight
tmpControl.Width = tmpControl.Width / PrevResizeX * FormName.ScaleWidth
tmpControl.Height = tmpControl.Height / PrevResizeY * FormName.ScaleHeight
'These four lines see the previous ratio
'Of the control to the form, and change they're
'current ratios to the same thing
End If

Next tmpControl

PrevResizeX = FormName.ScaleWidth
PrevResizeY = FormName.ScaleHeight
'Changes prevresize x and y to current width
'and height
End Sub

------------------
Here is my problem
------------------

How do I call this control in my form. When i add this control after making the ocx, I am unable to make it work.Why is it so..Please help.

Regards.

Mark Sreeves
Jan 9th, 2000, 03:19 PM
change all occurrences of FormName to UserControl

cut and paste the whole lot into UserControl_Resize()

then use UserControl11.Move() in your form to resize it

------------------
Mark Sreeves
Analyst Programmer

Mark.Sreeves@Softlab.co.uk
A BMW Group Company

venkatraman_r
Jan 9th, 2000, 04:28 PM
But it did not worked well..It says "Expected =".

Mark Sreeves
Jan 9th, 2000, 04:37 PM
what are you trying to do anyway?

venkatraman_r
Jan 9th, 2000, 04:52 PM
This is what I need!!
I need a user control that when I just put it in my form, all my controls in the form need to get resized when i resize the form, proportionately.

I tried in the planet source.com, still I did not find exactly, what i need. :(

Did u see my mail Mark??

Venkat.

benski
Jan 9th, 2000, 05:34 PM
I've never heard of such a control!

Why don't you do it the hard way. Work out the proportions and relative sizes and positions of all your controls, then put the move/resize code inside the Form_Resize event?

Mark Sreeves
Jan 9th, 2000, 06:21 PM
I looks like your code might do that :)

in your form (not the usercontrol) do this:

Private Sub Form_Resize()
UserControl11.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
End Sub



Even then there's something wrong with the code because I tried it with a textbox in the usercontrol an it did't resize smaller properly

venkatraman_r
Jan 9th, 2000, 06:46 PM
Think my posting has been reached differently. As you said Mark, the user control itself gets enlarged when i resize the form. I need my text box or other controls (obvously not my user control) to get enlarged.

Hope I am making u clear now.

Regards,

Venkat.

------------------
venkatraman_r@hotmail.com
ICQ: 45714766
http://venkat.iscool.net

Mark Sreeves
Jan 9th, 2000, 07:23 PM
This is getting more wierd all the time :)
in the usercontrol:

Option Explicit
Dim PrevResizeX
Dim PrevResizeY
Public Sub venkatIt(frmheight As Single, frmwidth As Single)
Dim tmpControl As Control
On Error Resume Next
'Ignores errors in case the control doesn't
'have a width, height, etc.

If PrevResizeX = 0 Then
'If the previous form width was 0
'Which means that this function wasn't run before
'then change prevresizex and y and exit function
PrevResizeX = frmwidth
PrevResizeY = frmheight
Exit Sub
End If

For Each tmpControl In UserControl
'A loop to make tmpControl equal to every
'control on the form

If TypeOf tmpControl Is Line Then
'Checks the type of control, if its a
'Line, change its X1, X2, Y1, Y2 values
tmpControl.X1 = tmpControl.X1 / PrevResizeX * frmwidth
tmpControl.X2 = tmpControl.X2 / PrevResizeX * frmwidth
tmpControl.Y1 = tmpControl.Y1 / PrevResizeY * frmheight
tmpControl.Y2 = tmpControl.Y2 / PrevResizeY * frmheight
'These four lines see the previous ratio
'Of the control to the form, and change they're
'current ratios to the same thing
Else
'Changes everything elses left, top
'Width, and height
tmpControl.Left = tmpControl.Left / PrevResizeX * frmwidth
tmpControl.Top = tmpControl.Top / PrevResizeY * frmheight
tmpControl.Width = tmpControl.Width / PrevResizeX * frmwidth
tmpControl.Height = tmpControl.Height / PrevResizeY * frmheight
'These four lines see the previous ratio
'Of the control to the form, and change they're
'current ratios to the same thing
End If

Next tmpControl

PrevResizeX = frmwidth
PrevResizeY = frmheight
'Changes prevresize x and y to current width
'and height
End Sub


then in your form:

Private Sub Form_Resize()
UserControl11.venkatIt Me.ScaleHeight, Me.ScaleWidth
End Sub


if you set the form's background colour to red you will see that the controls in the usercontrol resize but not the usercontrol itself!

Why on earth do you want to do this anyway??
;)

------------------
Mark Sreeves
Analyst Programmer

Mark.Sreeves@Softlab.co.uk
A BMW Group Company

venkatraman_r
Jan 10th, 2000, 12:24 PM
Hi Mark, Good morning!!

Just didnt had my sleep last night thinking of this damn user control....I had already told many times why I need this control. I have few controls on my form....I need to put an user control on my form, such that it makes all the controls IN MY FORM to get resized when the form is resized..

Well, I need to sincerely thank you for your effort in helping me....

Its so nice of you :) :)

Warm Regards,

Venkat.

------------------
venkatraman_r@hotmail.com
ICQ: 45714766
http://venkat.iscool.net

Tonio169
Jan 10th, 2000, 02:49 PM
i see.. what you're trying to make is a control that manages the resizing of other controls contained in a form where the control is at.

am i correct?

venkatraman_r
Jan 10th, 2000, 03:01 PM
ya perfect... :) :)

venkat.

------------------
venkatraman_r@hotmail.com
ICQ: 45714766
http://venkat.iscool.net

Mark Sreeves
Jan 10th, 2000, 03:28 PM
Oh I see now what you're trying to do

try this
usercontrol code:

Option Explicit
Dim PrevResizeX As Single
Dim PrevResizeY As Single

Public Sub venkatIt()
Dim tmpControl As Control
On Error Resume Next
'Ignores errors in case the control doesn't
'have a width, height, etc.

If PrevResizeX = 0 Then
'If the previous form width was 0
'Which means that this function wasn't run before
'then change prevresizex and y and exit function
PrevResizeX = UserControl.Parent.ScaleWidth
PrevResizeY = UserControl.Parent.ScaleHeight
Exit Sub
End If

For Each tmpControl In UserControl.Parent
'A loop to make tmpControl equal to every
'control on the form

If TypeOf tmpControl Is UserControl1 Then
'do nothing
ElseIf TypeOf tmpControl Is Line Then
'Checks the type of control, if its a
'Line, change its X1, X2, Y1, Y2 values
tmpControl.X1 = tmpControl.X1 / PrevResizeX * UserControl.Parent.ScaleWidth
tmpControl.X2 = tmpControl.X2 / PrevResizeX * UserControl.Parent.ScaleWidth
tmpControl.Y1 = tmpControl.Y1 / PrevResizeY * UserControl.Parent.ScaleHeight
tmpControl.Y2 = tmpControl.Y2 / PrevResizeY * UserControl.Parent.ScaleHeight
'These four lines see the previous ratio
'Of the control to the form, and change they're
'current ratios to the same thing
Else
'Changes everything elses left, top
'Width, and height
tmpControl.Left = tmpControl.Left / PrevResizeX * UserControl.Parent.ScaleWidth
tmpControl.Top = tmpControl.Top / PrevResizeY * UserControl.Parent.ScaleHeight
tmpControl.Width = tmpControl.Width / PrevResizeX * UserControl.Parent.ScaleWidth
tmpControl.Height = tmpControl.Height / PrevResizeY * UserControl.Parent.ScaleHeight
'These four lines see the previous ratio
'Of the control to the form, and change they're
'current ratios to the same thing
End If

Next tmpControl

PrevResizeX = UserControl.Parent.ScaleWidth
PrevResizeY = UserControl.Parent.ScaleHeight
'Changes prevresize x and y to current width
'and height
End Sub


form code:


Private Sub Form_Resize()
UserControl11.venkatIt
End Sub



------------------
Mark Sreeves
Analyst Programmer

Mark.Sreeves@Softlab.co.uk
A BMW Group Company

venkatraman_r
Jan 10th, 2000, 04:13 PM
ah....that was a perfect one at last.......thank GOD and Mark...Whoooooooooooooooooooooooooooo!!!!relieved today and am going to have a good sleep tonight.... :) :) :)

Thanx Mark..Hats off to you

Venkat.

------------------
venkatraman_r@hotmail.com
ICQ: 45714766
http://venkat.iscool.net

Mark Sreeves
Jan 10th, 2000, 06:28 PM
Venkat
Glad to be of help

My boss says it's pretty smart but I ought to get on with some work now :(



------------------
Mark Sreeves
Analyst Programmer

Mark.Sreeves@Softlab.co.uk
A BMW Group Company

csdcom
Jan 12th, 2000, 11:40 AM
The code works well but what it does not do is resize any labels you might have, don't know if this was intentional or not.

lin
Dec 5th, 2002, 07:31 AM
hello to you two..

Sorry that i bug in.. you realy helped me too, but.. it doesn't work in MDIChild.. if you have any idea why, i will be glad to hear..

Lin.