Resizing Form and Controls

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zubair1
    New Member
    • Sep 2008
    • 79

    Resizing Form and Controls

    Hello,

    I am want to Resize my form and form controls based on the users resolution.

    For example :- i am making this application in 1024x768. it obviously works and looks well too me but when my user runs this application on his pc it looks horrible and wierd because his Resolution is 800x600.

    I found a snippet on this forum to resize the window but that just isn't what i'm looking for - i want the controls and form both to resize depending on the user resolution. Like if the user has a 800x600 and the app was made with 1024x768 it should automatically resize the form and its form controls to fit on the screen.

    Could some one help me with this i am really lost :( in this form i also saw some one saying to use % sign to assign size to form and its elements but i tried this and it doesn't work :s it says its invalid.

    I am using VB.net - Visual Studio 2005 - PLZ Help :(

    Thank you,
    Regards,
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    This is going to be difficult, because you want server code to respond to client conditions.

    Some or all of this will need to be done in Javascript, like detecting the size of the window, and probably resizing the controls as well. We have a javascript forum that you can try for help on this.

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      Unless this is a windows application, in which case it *could* be much easier.
      Although 800x600 should have gone away along time ago. I can't even MAKE my computers do that resolution anymore

      Comment

      • Curtis Rutland
        Recognized Expert Specialist
        • Apr 2008
        • 3264

        #4
        Good call Plater. I assumed that this was web based.

        Comment

        • zubair1
          New Member
          • Sep 2008
          • 79

          #5
          Thanks for tips guys

          But it isn't a Web Application


          It a Windows Application sorry i wasnt very specific on the issue, its a windows app i'm not sure about there but currently here where i am many people are using this resolution.. i dont but still 800x600 is an example.

          To more simple - i want my app to automatically resize the form size to fit the current resolution and that includes the form controls too :( i'm postive its possible since many other apps i seen have this feature.

          I'm not sure how to accomplish this though :(

          But you guys are pretty lucky :) having all those cool PCs and all the other technologies at your fingertips - when things become old there it arrives here :( i hope things get much more faster here soon :)

          Thank you!
          Regards

          Comment

          • jg007
            Contributor
            • Mar 2008
            • 283

            #6
            a quick serach on this forum would have found -







            I haven't tried the code but it should give you somewhere to start

            Comment

            • jg007
              Contributor
              • Mar 2008
              • 283

              #7
              not sure if this is any use but this resizes 3 buttons and moves them so that they line up on the right so I have posted it in case you can use some of it

              Code:
              Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
              
                      Me.Location = New System.Drawing.Point(0, 0)
              
                      Me.Size = New System.Drawing.Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height)
              
              
                      Dim tempx, tempy As Integer
                      Dim screenx, screeny As Integer
                      Dim tempo As System.Drawing.Point
                      tempo = New System.Drawing.Point(1, 1)
              
                      For Each x As System.Windows.Forms.Button In Me.Controls
              
              
              
                          tempx = x.Size.Width
                          tempy = x.Size.Height
                          screenx = Me.Size.Width / 100
                          screeny = Me.Size.Height / 100
                          tempx = tempx / 100
                          tempx = tempx * (screenx * 50)
                          tempy = tempy / 100
                          tempy = tempy * (screeny * 33)
                          x.Size = New System.Drawing.Size(tempx, tempy)
                        
              
              
              
                      Next
              
                      tempo = New System.Drawing.Point(1, 1)
              
                      For Each x As System.Windows.Forms.Button In Me.Controls
                          x.Location = tempo
                          tempo = New System.Drawing.Point(x.Location.X, x.Location.Y + x.Height)
              
                      Next
              
                  End Sub

              Comment

              • Kapps
                New Member
                • Aug 2008
                • 16

                #8
                One approach to this is to check out Screen.PrimaryS creen.Bounds.He ight/Width. This will show you the total area, minus the task bar, of your monitor (resolution), or if you want just the form, you could just check out Height/Width. Upon resizing, you would have to check what the current height and width is, and then would have to just specify a constant value for the portion of the screen you want it to take, and find an event that's called every time this should change (in particular, ReSize).

                Comment

                • Plater
                  Recognized Expert Expert
                  • Apr 2007
                  • 7872

                  #9
                  I *think* if you build your controls with anchoring and such, much of the position-resizing will be automatic when you change the size of the form.
                  As for changing widget size, that might require some math.

                  Comment

                  • zubair1
                    New Member
                    • Sep 2008
                    • 79

                    #10
                    Hi,

                    Thanks for all the help and support guys :)

                    Thanks for the code jg007, really appreciate it. - i can't seem to get it to work in my app.

                    I also can't understand Anchor property :( it just says left / top / right / bottom.

                    I have 1 TAB, 2 Buttons, 2 Panel, 2 Picture Box, 1 MultiLine Textbox, 1 Progressbar :(

                    Comment

                    • Plater
                      Recognized Expert Expert
                      • Apr 2007
                      • 7872

                      #11
                      The anchor property "anchors" your widget to the selected edge (top, bottom, left, right)

                      So if you put a widget 10px from the top and 3px from the left and have it sized to be 3px from the right, if you set it to anchor to left,top,right. No matter how you resize the form, it will always be that amount of px from those edges.
                      Just play with it and you'll see.

                      Comment

                      • joedeene
                        Contributor
                        • Jul 2008
                        • 579

                        #12
                        how about looking at this from microsoft ?

                        Comment

                        • Curtis Rutland
                          Recognized Expert Specialist
                          • Apr 2008
                          • 3264

                          #13
                          Originally posted by joedeene
                          how about looking at this from microsoft ?

                          http://support.microsoft.com/kb/182070
                          Good article, but it looks to be for VB6, not VB.NET. Still, the logic may apply.

                          Comment

                          • jg007
                            Contributor
                            • Mar 2008
                            • 283

                            #14
                            Originally posted by zubair1
                            Hi,

                            Thanks for all the help and support guys :)

                            Thanks for the code jg007, really appreciate it. - i can't seem to get it to work in my app.

                            I also can't understand Anchor property :( it just says left / top / right / bottom.

                            I have 1 TAB, 2 Buttons, 2 Panel, 2 Picture Box, 1 MultiLine Textbox, 1 Progressbar :(
                            the code was more of an example and should work if you create a new application with 3x buttons then just drop the code into one of them or the form load

                            I 'think' that resize code will be something like that and will just require some playing to get the maths right, at the moment my code just splits 3 buttons between the screen height making them each 33% of it and 50% the width but you could have a set of variables with the Value for 1% of the prefered size then just resize all the controls to this scaled to the current screen

                            sorry if that is a bit unclear and if I can I will work out some code then post it .

                            Comment

                            • zubair1
                              New Member
                              • Sep 2008
                              • 79

                              #15
                              Thanks for all the support :)

                              I will try to do more inDepth into Anchors, Platter :) thanks for pointing that out by reading it it seems very cool and just what i need but as you said i will have to play around with it for awhile.

                              i also came across a third-party library from Softgroup .NET Form Resizer

                              i'm thinking of using that too, not exactly sure yet though (it seems to be alittle slow - its not exactly how all the other normal applications resize).

                              Comment

                              Working...