10 Replies - 9919 Views - Last Post: 15 February 2012 - 06:19 AM Rate Topic: -----

#1 stevesmith54  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 09-September 10

Making Controls Resize with the MDI Child form

Posted 23 January 2011 - 03:18 PM

Does anyone know how to make the controls on an MDI Child form resize along with the form itself? I inherited a project from another developer and I was asked specifically to make the form resize. With advice I received on this forum I now have the form resizing as expected. It will minimize, restore and maximize as well as resize with the mouse pointer. The problem is that when I increase the size of the form all I get is more blank space on the screen. The controls to do change at all. Although I thin this is normal behavior for a Windows form my bosses all seem to think that the controls resize on every other widows for they see. I wondered if anyone had successfully accomplished this. I was already advised to write a FormResize handling subroutine and this unfortunately did not work. As always any advice or help is greatly appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Making Controls Resize with the MDI Child form

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1066
  • View blog
  • Posts: 4,173
  • Joined: 02-July 08

Re: Making Controls Resize with the MDI Child form

Posted 23 January 2011 - 03:23 PM

Did you look into the Control.Scale method? You will need to iterate the control collection and scale them. Don't forget to scale the font as well - if you want that to change as well.
Was This Post Helpful? 0
  • +
  • -

#3 stevesmith54  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 09-September 10

Re: Making Controls Resize with the MDI Child form

Posted 23 January 2011 - 05:38 PM

View Posthawkvalley1, on 23 January 2011 - 03:23 PM, said:

Did you look into the Control.Scale method? You will need to iterate the control collection and scale them. Don't forget to scale the font as well - if you want that to change as well.

I will definitely look into that. Thank you for the suggestion. Always appreciated.
Was This Post Helpful? 0
  • +
  • -

#4 stevesmith54  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 09-September 10

Re: Making Controls Resize with the MDI Child form

Posted 24 January 2011 - 05:24 AM

View Poststevesmith54, on 23 January 2011 - 05:38 PM, said:

View Posthawkvalley1, on 23 January 2011 - 03:23 PM, said:

Did you look into the Control.Scale method? You will need to iterate the control collection and scale them. Don't forget to scale the font as well - if you want that to change as well.

I will definitely look into that. Thank you for the suggestion. Always appreciated.


so far I have not been successful in making this work. When I maximize thr form it does not display right. Are there any other properties on the form that need to be set in order for this to work?
Was This Post Helpful? 0
  • +
  • -

#5 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1066
  • View blog
  • Posts: 4,173
  • Joined: 02-July 08

Re: Making Controls Resize with the MDI Child form

Posted 24 January 2011 - 09:42 AM

The easiest way is to control the resize to both height and width only on a symmetrical form (400,400) with a border style of fixed. To accomplish this you have a control or rectangle, and you use the mousedown and mousemove event to resize the window symmetrically. You need a class variable Type-Single and store the size of the window in this variable(set in form load - initially), then in the top of the resize event you get your scale from that number / the new form size -> this is your scale for both width/height, and at the end of the resize event you set the variable to the current form size. Then the scale for the font size will be the same since it will adjust based on height since height and width are tied together - keeps it from growing to large if you allowed expanding only the height. You also need to play with the anchor properties too.
Was This Post Helpful? 0
  • +
  • -

#6 stevesmith54  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 09-September 10

Re: Making Controls Resize with the MDI Child form

Posted 25 January 2011 - 11:25 AM

So far I have still had no success. What I have done is created a subroutine to handle the SizeChanged event of my mdi child form. I was advised to use the Control.Scale method to resize my controls. I have determined that using the Control Scale Method with the SizeF parameter (there are other parmeters but they are obsolete) is the way to go. In a nutshell, my SizeChanged handling subroutine checks the WindowsViewState and if the WindowsViewState is maximized, I iterate through the controls and scale each one. According to my research if you scale the control you also scale the child controls.

On my form I first declare a global (for the form) variable Ctrl as follows.
Dim Ctrl As Control 


In my SizeChaged handling subroutine, I declare an SizeF type variable as follows.
 Dim ResizeFactor As System.Drawing.SizeF 


Then in my SizeChanged handling subroutine, I instantiate my SizeF variable and iterate through the controls as follows.
 If Me.WindowsViewState = FormWindowState.Maximize
            ResizeFactor = New System.Drawing.SizeF(1.24, 1.24)
            For Each Ctrl In Me.Controls
                Ctrl.Scale(ResizeFactor)
            Next
        End If 


This is very simple from a coding standpoint and it should work but doesn't. The AutoSize property on every control is set to "True", the the AutoScaleMode property is set to ...Inherit, and the AutoSizeMode property is set to ...GrowOnly (without which the form itself will not resize. Any advice or help will be greately appreciated. I feel rahter stupid right now and am probably missing something simple. Thanks.
Was This Post Helpful? 0
  • +
  • -

#7 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1066
  • View blog
  • Posts: 4,173
  • Joined: 02-July 08

Re: Making Controls Resize with the MDI Child form

Posted 25 January 2011 - 11:37 AM

You need to make changes in the form's resize event. Also you need a variable you use to calculate the diff in size. Old ht / new ht then this is you scale. Reemember to reset it after the move.
Was This Post Helpful? 0
  • +
  • -

#8 stevesmith54  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 09-September 10

Re: Making Controls Resize with the MDI Child form

Posted 25 January 2011 - 01:18 PM

View Posthawkvalley1, on 25 January 2011 - 11:37 AM, said:

You need to make changes in the form's resize event. Also you need a variable you use to calculate the diff in size. Old ht / new ht then this is you scale. Reemember to reset it after the move.

The code gets executed whether I make my subroutine handle the form.Resize event or the form.SizeChanged event. It appears that both events are fired with the form gets resizes or maximized.
I did find some examples where a global variable was declared for the original height and width and that they are compared with the new height and width after the resize. As I work on this I do have one question. How will the height and width calculations be affected by different size monitors? My goal is to make it work the same way regardless of the monitor. Thanks.
Was This Post Helpful? 0
  • +
  • -

#9 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1066
  • View blog
  • Posts: 4,173
  • Joined: 02-July 08

Re: Making Controls Resize with the MDI Child form

Posted 25 January 2011 - 01:54 PM

Well they won't change unless you tell them to. They stay at there pixel defined size til then. So it would be something you could test for using the Screen class.
Was This Post Helpful? 0
  • +
  • -

#10 todonnellpe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-February 12

Re: Making Controls Resize with the MDI Child form

Posted 15 February 2012 - 05:51 AM

Hello Steve, My name is Ted and I have been a vb programmer for years and I used to have a way that would dynamic proportion any form with all its controls but this new .net has me stymied. In a nutshell this is what I was able to do in vb6....in form load i would capture all of the original controls info (left,width,top,height and font size info) and add theem into a not visible listbox....this would tell me what the original, as designed on programmers screen, info was and then I would center the form on the screen that program is launched onto and that would trigger a resize event for the form and in that event i would proportion the controls properties of the new form size versus the original form size..this worked like a champ until vb.net. I am finding that during the resize event I cannot issue a command to change the control properties. vb6 i could use command1.width = (then use proportion equation) in vb.net when i try button1.size.width= it does not accept this..it comes back that it is a value and cannot be on left side of equation. I really do not like the docking or the anchoring. Have you been able to find an alternate route that does this type of auto-resizing? This below is the vb6 code...would be so simple if MS had left it alone

Private Sub Form_Load()
Left = (Screen.Width - Width) / 2
Top = (Screen.Height - Height) / 2
    
List1.AddItem Form1.Width
List1.AddItem Form1.Height
List1.AddItem Form1.Left
List1.AddItem Form1.Top

List1.AddItem Drive1.Width
List1.AddItem Drive1.Height
List1.AddItem Drive1.Left
List1.AddItem Drive1.Top

List1.AddItem Dir1.Width
List1.AddItem Dir1.Height
List1.AddItem Dir1.Left
List1.AddItem Dir1.Top

List1.AddItem File1.Width
List1.AddItem File1.Height
List1.AddItem File1.Left
List1.AddItem File1.Top



List1.AddItem Command1.Width
List1.AddItem Command1.Height
List1.AddItem Command1.Left
List1.AddItem Command1.Top
List1.AddItem Command1.Font.Size



    
End Sub

Private Sub Form_Resize()

Drive1.Width = Form1.Width * List1.List(4) / List1.List(0)
Drive1.Left = Form1.Width * List1.List(6) / List1.List(0)
Drive1.Top = Form1.Height * List1.List(7) / List1.List(1)

Dir1.Width = Form1.Width * List1.List(8) / List1.List(0)
Dir1.Height = Form1.Height * List1.List(9) / List1.List(1)
Dir1.Left = Form1.Width * List1.List(10) / List1.List(0)
Dir1.Top = Form1.Height * List1.List(11) / List1.List(1)

File1.Width = Form1.Width * List1.List(12) / List1.List(0)
File1.Height = Form1.Height * List1.List(13) / List1.List(1)
File1.Left = Form1.Width * List1.List(14) / List1.List(0)
File1.Top = Form1.Height * List1.List(15) / List1.List(1)

Command1.Width = Form1.Width * List1.List(16) / List1.List(0)
Command1.Height = Form1.Height * List1.List(17) / List1.List(1)
Command1.Left = Form1.Width * List1.List(18) / List1.List(0)
Command1.Top = Form1.Height * List1.List(19) / List1.List(1)
Command1.Font.Size = List1.List(20) * Form1.Height / List1.List(1)


End Sub


Was This Post Helpful? 0
  • +
  • -

#11 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1623
  • View blog
  • Posts: 5,199
  • Joined: 25-September 09

Re: Making Controls Resize with the MDI Child form

Posted 15 February 2012 - 06:18 AM

Try putting it in the ClientSizeChanged event.

EDIT:
Actually, I remember this a while back and so I went on a search. Just gotta remember you're not HawkValley anymore ;)

Resizing controls with a form

This post has been edited by CharlieMay: 15 February 2012 - 06:54 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1