Results 1 to 17 of 17

Thread: Resize User Control - Very Urgent

  1. #1

    Thread Starter
    Hyperactive Member venkatraman_r's Avatar
    Join Date
    Jul 1999
    Location
    Chennai, INDIA
    Posts
    284

    Post

    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.

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    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

    [email protected]
    A BMW Group Company

  3. #3

    Thread Starter
    Hyperactive Member venkatraman_r's Avatar
    Join Date
    Jul 1999
    Location
    Chennai, INDIA
    Posts
    284

    Post

    But it did not worked well..It says "Expected =".

  4. #4
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    what are you trying to do anyway?

  5. #5

    Thread Starter
    Hyperactive Member venkatraman_r's Avatar
    Join Date
    Jul 1999
    Location
    Chennai, INDIA
    Posts
    284

    Post

    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.

  6. #6
    Lively Member benski's Avatar
    Join Date
    Sep 1999
    Location
    UK
    Posts
    126

    Post

    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?

  7. #7
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    I looks like your code might do that

    in your form (not the usercontrol) do this:
    Code:
    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

  8. #8

    Thread Starter
    Hyperactive Member venkatraman_r's Avatar
    Join Date
    Jul 1999
    Location
    Chennai, INDIA
    Posts
    284

    Post

    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.

    ------------------
    [email protected]
    ICQ: 45714766
    http://venkat.iscool.net

  9. #9
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    This is getting more wierd all the time
    in the usercontrol:
    Code:
    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:
    Code:
    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

    [email protected]
    A BMW Group Company

  10. #10

    Thread Starter
    Hyperactive Member venkatraman_r's Avatar
    Join Date
    Jul 1999
    Location
    Chennai, INDIA
    Posts
    284

    Post

    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.

    ------------------
    [email protected]
    ICQ: 45714766
    http://venkat.iscool.net

  11. #11
    Lively Member
    Join Date
    Jul 1999
    Posts
    99

    Post

    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?

  12. #12

    Thread Starter
    Hyperactive Member venkatraman_r's Avatar
    Join Date
    Jul 1999
    Location
    Chennai, INDIA
    Posts
    284

    Post

    ya perfect...

    venkat.

    ------------------
    [email protected]
    ICQ: 45714766
    http://venkat.iscool.net

  13. #13
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    Oh I see now what you're trying to do

    try this
    usercontrol code:
    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:

    Code:
    Private Sub Form_Resize()
    UserControl11.venkatIt
    End Sub

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

    [email protected]
    A BMW Group Company

  14. #14

    Thread Starter
    Hyperactive Member venkatraman_r's Avatar
    Join Date
    Jul 1999
    Location
    Chennai, INDIA
    Posts
    284

    Post

    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.

    ------------------
    [email protected]
    ICQ: 45714766
    http://venkat.iscool.net

  15. #15
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    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

    [email protected]
    A BMW Group Company

  16. #16
    New Member
    Join Date
    Jan 2000
    Posts
    3

    Post

    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.

  17. #17
    Member
    Join Date
    Jun 2000
    Posts
    62
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width