Announcement

Collapse
No announcement yet.

Resizing Windows

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Resizing Windows

    Good day all! I've been searching around and I'm kinda stuck somewhere else.

    I'm working in powerbasic forms tool and I want to create a box for the program that can be resized. If someone drags the bottom right corner, lets say, it will allow me to resize the main window and dynamically resize teh textboxes within. I'm thinking that the textboxes will be a percentage of the main window in width and height, instead of a fixed pixel value.

    Also, I'd like to make sure that the user doesn't shrink the main window below a certain pixel size.

    Is this possible?

    Frank

  • #2
    Hi Frank,
    The control resizing as you've described it is not something I've done. Do a search on "AutoSize Controls" and you'll find a few links of interest, such as here and here.

    But, you're saying you don't want to drag the main dialog to resize all of the controls inside? Instead, you want to drag on a box? Where would the box be - inside the main dialog or on a popup dialog? Can you clarify a bit on this?

    As for this ...
    Also, I'd like to make sure that the user doesn't shrink the main window below a certain pixel size.
    Here's one approach:
    Code:
    'Compilable Example:
    #Compiler PBWin 9, PBWin 10  Uses Example#1 method
    #Compile EXE
    #Dim All
    #Include "Win32API.inc"
    Global hDlg As Dword
    
    Function PBMain() As Long
       Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
       Control Add Button, hDlg, 100,"Push", 50,10,100,20
       Dialog Show Modal hDlg Call DlgProc
    End Function
    
    CallBack Function DlgProc() As Long
       Select Case CB.Msg
          Case %WM_GETMINMAXINFO
             Local MM As MINMAXINFO Ptr
             MM=CB.lParam
             @MM.ptMinTrackSize.x=150  '<-- Min X size of your window
             @MM.ptMinTrackSize.y=150  '<-- Min Y size of your window
             @MM.ptMaxTrackSize.x=500  '<-- Max X size of your window
             @MM.ptMaxTrackSize.y=500  '<-- Max Y size of your window
       End Select
    End Function

    Comment


    • #3
      Oh, I think I get it now. While working in PBForms, you'd like there to be a "Resize All" tool that can resize a dialog and all of it's children - within the PBForms environment. You're not asking to dynamically change controls sizing while the application is running.

      If so, then my bad. The links I gave you were for dynamic, runtime sizing. I don't personally use PBForms, so I'm not at all sure if what you ask is possible.
      Last edited by Gary Beene; 8 Mar 2012, 07:58 PM.

      Comment


      • #4
        In PB Forms, Select an appropriate style for the dialog and add code from Gary's demo as required.
        (eg %WS_THICKFRAME OR %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR %WS_SYSMENU).

        Pierre also posted a nice example here that shows how to resize the controls along with the dialog.
        Rgds, Dave

        Comment


        • #5
          Thanks guys! I searched high and low and just needed a push in the right direction. I'll have to study it for a while, but I can definitely see the code that does the job.

          Thanks again!

          Frank

          Comment


          • #6
            Hey Frank,
            I'm still no clear on what you want. Do you want the user to resize the application, and have the controls resize proportionally? Or do you want to do the resizing in the design phase, within PBForms?

            Another issue to remember, is that resizing the controls does not automatically resize the fonts the controls use. You could wind up a big control, but with the original font size - which might not be what you want.

            Can you give a little more description of what your needs are?

            Comment


            • #7
              Hi Frank;

              Another issue to remember, is that resizing the controls does not automatically resize the fonts the controls use. You could wind up a big control, but with the original font size - which might not be what you want.
              The corollary to Gary's statement; Is you could wind up with a small control whose font is too large to fit on the control.

              If you are trying to create a user re-sizable GUI, try creating the user controls as bitmaps. That way the control and its text are re-sized simultaenously and proportionately.

              Comment


              • #8
                extendet auto size

                Here is another solution to resize the dialog and the controls within the dialog. Also the fonts of the buttons will be resized.

                1. creating the controlls e.g.

                CONTROL ADD BUTTON, hDlg, %IDC_BUTTON1, "Button 1", 1,1,1,1
                CONTROL ADD BUTTON, hDlg, %IDC_BUTTON2, "Button 2", 1,1,1,1
                CONTROL ADD BUTTON, hDlg, %IDC_BUTTON3, "Button 3", 1,1,1,1
                CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX, "auto-size sample ", 1,1,1,1

                2. in CASE %WM_SIZE
                IF CB.WPARAM <> %SIZE_MINIMIZED THEN
                ResizeDialog ( CB.HNDL )
                END IF

                3. ResizeDialog

                ResizeControl (hDlg, %IDC_TEXTBOX,3, 4, 45,38, 2)
                ResizeControl (hDlg, %IDC_BUTTON1,85, 35, 10,6 , 1.1)
                ResizeControl (hDlg, %IDC_BUTTON2,85, 42, 10,6 , 1.3)
                ResizeControl (hDlg, %IDC_BUTTON3,85, 49, 10,6, 1.5 )

                4. The ResizeControl function

                SUB ResizeControl ( BYVAL hDlg AS DWORD, _
                control_id AS INTEGER, _
                control_col_upper_left_corner_in_percent AS INTEGER, _
                control_row_upper_left_corner_in_percent AS INTEGER, _
                control_width_factor_in_percent AS INTEGER, _
                control_height_factor_in_percent AS INTEGER, _
                new_font_size_factor AS DOUBLE )


                LOCAL new_fontSize AS INTEGER

                DIALOG GET SIZE hDlg TO global_var.dialog_window_new_width, global_var.dialog_window_new_height


                global_var.percent = ( global_var.dialog_window_new_height - global_var.dialog_window_init_height ) / _
                ( global_var.dialog_window_init_height / 100 )

                new_fontSize = global_var.fontSize + (( global_var.fontSize / 100 ) * global_var.percent )
                new_fontSize *= new_font_size_factor

                CONTROL SET LOC hDlg, control_id, _
                global_var.dialog_window_new_width - ( global_var.dialog_window_new_width / 100 ) * ( 100 - control_col_upper_left_corner_in_percent ), _
                global_var.dialog_window_new_height - ( global_var.dialog_window_new_height / 100 ) * ( 100 - control_row_upper_left_corner_in_percent )

                CONTROL SET SIZE hDlg, control_id, _
                global_var.dialog_window_new_width - ( global_var.dialog_window_new_width / 100 ) * ( 100 - control_width_factor_in_percent ), _
                global_var.dialog_window_new_height - ( global_var.dialog_window_new_height / 100 ) * ( 100 - control_height_factor_in_percent )


                FONT NEW "Times New Roman", new_fontSize, 0 TO global_var.hFont

                IF global_var.percent > 50 THEN
                FONT NEW "Lucida Console", 20, 0 TO global_var.gFont
                ELSE
                FONT NEW "Lucida Console", 10, 1 TO global_var.gFont
                END IF

                CONTROL SET FONT hDlg, control_id, global_var.hFont
                GRAPHIC SET FONT global_var.gFont

                END SUB


                I put the whole sample in the source code section here http://www.powerbasic.com/support/pb...ad.php?t=50020
                Last edited by Ingo Maurischat; 1 Apr 2012, 11:15 PM.

                Comment


                • #9
                  Hi Ingo,
                  Thanks for the code you posted.

                  Just in case you weren't aware, the "#" symbol on the forum page when in reply edit mode will paste code tags into the edit field around any selected text. That will give you this look on the post, which is easier for us to read:
                  Code:
                  Test Code Line

                  Comment


                  • #10
                    Great code guys.

                    If anyone is interested, (probably not) but I copied the example also into my 6.0 version and made it pretty much compatible with that too.
                    Client Writeup for the CPA

                    buffs.proboards2.com

                    Links Page

                    Comment

                    Working...
                    X