11 Replies - 23753 Views - Last Post: 30 December 2010 - 11:22 AM Rate Topic: -----

#1 oohrah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 08-August 09

Form resize with control sizing

Posted 27 December 2010 - 04:01 PM

I have been searching for code and/or a tutorial on how to proportianally resize controls and fonts. For example if I design a form at 800 X 600 and the user maximizes the form to 1600 X 1200, I need the form and controls to grow to fill the screen almost like a zoom function. If anyone can guide me in the right direction I would appriciate it.
Is This A Good Question/Topic? 0
  • +

Replies To: Form resize with control sizing

#2 Jack Eagles1  Icon User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 183
  • View blog
  • Posts: 1,152
  • Joined: 10-December 08

Re: Form resize with control sizing

Posted 27 December 2010 - 04:33 PM

Well, you'll need to use the anchor property of each object. If you set the anchor to top and left, then when you resize the form, the controls will not change size. However, if you set the anchor to something different, let's say top and right, then the control will stay pinned to its location at the top right when the form is resized. If you set the dock style to top, bottom, left, and right, the control will grow proportionally to how much you resize the form.
Was This Post Helpful? 1
  • +
  • -

#3 oohrah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 08-August 09

Re: Form resize with control sizing

Posted 27 December 2010 - 11:29 PM

Thanks for your reply Jack. The issue I had trying to use that was when I had them set was my textboxes would overlap. Of course that would be unexceptable. Those were the only ones I had found examples for too
Was This Post Helpful? 0
  • +
  • -

#4 oohrah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 08-August 09

Re: Form resize with control sizing

Posted 28 December 2010 - 09:30 AM

I have made some progress . Here is the code I have so far. This code will work one time only though. It will size the controls but if I try to resize it to the design time size the controls are gone. If I try to drag the form to resize it that way the controls run away with it to. The font also will not resize.

Public Class Form1
    Dim origWidth As Integer = 200
    Dim origHeight As Integer = 100

    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        Dim fSize As New SizeF((Me.Width / origWidth), (Me.Height / origHeight))


        TextBox1.Scale(fSize)
        TextBox2.Scale(fSize)
        Label1.Scale(fSize)
        Label2.Scale(fSize)
    End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#5 Jack Eagles1  Icon User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 183
  • View blog
  • Posts: 1,152
  • Joined: 10-December 08

Re: Form resize with control sizing

Posted 28 December 2010 - 11:01 AM

Well, it is possible to do everything that you want to do with simple division/multiplication on the resize event, but I've attached a project which demonstrates a method which I think you might prefer.

It works on the dock style of components, and the Form_Resize event to make sure that everything resizes properly. It's not perfect, but I think you'd like it better than what you've got at the moment. Take a look at the code and tell me what you think. I can link to a scan at virustotal if you're paranoid :) . Anyway my rep wouldn't be the way it is now If I went around posting viruses. And I would probably have been banned by now.

http://www.mediafire...75f8z1crjhz5rz2

This post has been edited by Jack Eagles1: 28 December 2010 - 11:05 AM

Was This Post Helpful? 1
  • +
  • -

#6 oohrah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 08-August 09

Re: Form resize with control sizing

Posted 28 December 2010 - 12:11 PM

Hey Jack

Thanks but I assume you are using 2010. I am on 2008. Is there a way to convert this to 2008 ? As far as the visur part goes, I agree, you would not have the standing you have if you did.

[UPDATE]
I was able to get to open in 2008. Almost what I was looking for. I will try to explain better. I am wanting to keep the aspect ratio the same on everything. just like if I were to zoom on the form everything grows proportionally, fonts, controls and images. Like this image

http://www.ushonors.com/resize-example.png

This post has been edited by oohrah: 28 December 2010 - 12:37 PM

Was This Post Helpful? 0
  • +
  • -

#7 Jack Eagles1  Icon User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 183
  • View blog
  • Posts: 1,152
  • Joined: 10-December 08

Re: Form resize with control sizing

Posted 28 December 2010 - 01:30 PM

Hmm. The only thing I can think of is the Control.Scale attribute. You can mess around with it, but basically, in the form resize event, you'd need to check if the size of the form is over a certain size, and then loop through each control in the form, and make it larger. I'm not sure about making them smaller again though.

[Whoo 800 posts]

This post has been edited by Jack Eagles1: 28 December 2010 - 01:32 PM

Was This Post Helpful? 1
  • +
  • -

#8 oohrah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 08-August 09

Re: Form resize with control sizing

Posted 28 December 2010 - 01:56 PM

Well congrats on the 800 post and thank you for your help too. yea the scale thing is were I think I am going to go. Any one out there with knowledge in this respect ? I give respect points :) I will continue to dig through it and if I find something I will post it.
Was This Post Helpful? 0
  • +
  • -

#9 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1052
  • View blog
  • Posts: 4,077
  • Joined: 02-July 08

Re: Form resize with control sizing

Posted 28 December 2010 - 02:00 PM

Are you moving the controls with ratio aspect?

This post has been edited by hawkvalley1: 28 December 2010 - 02:05 PM

Was This Post Helpful? 0
  • +
  • -

#10 oohrah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 08-August 09

Re: Form resize with control sizing

Posted 28 December 2010 - 11:06 PM

View Posthawkvalley1, on 28 December 2010 - 01:00 PM, said:

Are you moving the controls with ratio aspect?


hawkvalley, I haven't gotten far at all with any of it. I have tried but with no success. You have any suggestions ?
Was This Post Helpful? 0
  • +
  • -

#11 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1052
  • View blog
  • Posts: 4,077
  • Joined: 02-July 08

Re: Form resize with control sizing

Posted 29 December 2010 - 05:13 AM

The aspect ratio is the proportional difference from what the size it was to what the size is now. I would not use the sizable form, but rather control the width and height myself. Either a control or with graphics, re-size the form width and height at same time to avoid someone just changing the width or height alone. Then if the form is not square you need the wd/ht ratio for adjusting this in code. The you need 1 variable to keep track of what the dimension was then reset it after the calculations and the ratio is applied to control's; font, size and location.

Public Class Form1
    Dim origWidth As Integer = 200
    Dim origHeight As Integer = 100

    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        Dim fSize As New SizeF((Me.Width / origWidth), (Me.Height / origHeight))
        TextBox1.Scale(fSize)
        TextBox2.Scale(fSize)
        Label1.Scale(fSize)
        Label2.Scale(fSize)
          'reset them and now it works more than once
        origWidth = Me.Width
        origHeight = Me.Height
    End Sub
End Class

Was This Post Helpful? 1
  • +
  • -

#12 oohrah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 08-August 09

Re: Form resize with control sizing

Posted 30 December 2010 - 11:22 AM

Ah so simple but was just outside of my reach. Thanks man.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1