Author Topic: Can a Screen Be Resized by Code?  (Read 27306 times)

0 Members and 1 Guest are viewing this topic.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Can a Screen Be Resized by Code?
« Reply #15 on: January 11, 2019, 05:38:18 am »
I've just tried adding code to this InForm project to allow the user to change window size for the larger screens.  Code that works in standard QB64 has no effect in InForm

Code: QB64: [Select]
  1.  
  2.     oldimage& = s&
  3.     SCREEN s&
  4.     _FREEIMAGE oldimage&

If the $RESIZE:ON is placed somewhere in the code, either at __UI_OnLoad or in the main loop, and the _RESIZE lines are placed in the main loop there is no resizing allowed: the cursor does not even change to a sizing arrow when at the window boundaries - this indicates that $RESIZE doesn't work in InForm.  Would there be an InForm equivalent to resizing code, or have I just misunderstood again?

FellippeHeitor

  • Guest
Re: Can a Screen Be Resized by Code?
« Reply #16 on: January 11, 2019, 05:55:52 am »
As with most libraries, the idea is that no "low level" manipulation will be done by the user.

What you were trying to do with $resize is automatically handled by InForm internally when you do this:

Alternatively you can set a form's CanResize property to true so the user can freely resize the form. That will trigger the __UI_FormResize event from which you can adapt your interface according to the resulting Control(__UI_FormID).Width and Control(__UI_FormID).Height.

Try creating a dummy empty form in the editor and just set the CanResize property to True as indicated above.

You will see InForm will automatically add $RESIZE to the .frm file and that the _RESIZE event will be automatically caught and generate a call to the __UI_FormResize event which will have filled the width and height properties of the Control(__UI_FormID) with the values of _RESIZEWIDTH and _RESIZEHEIGHT that you will use to reposition your controls accordingly.

FellippeHeitor

  • Guest
Re: Can a Screen Be Resized by Code?
« Reply #17 on: January 11, 2019, 06:04:08 am »
Just for curiosity's sake, here's how InForm deals with resizes in InForm.ui:

Code: QB64: [Select]
  1.     'Adjust the Resize Status of this form based on its CanResize property:
  2.     IF __UI_DesignMode = False THEN
  3.         IF Control(__UI_FormID).CanResize <> __UI_CurrentResizeStatus THEN
  4.             __UI_CurrentResizeStatus = Control(__UI_FormID).CanResize
  5.             IF __UI_CurrentResizeStatus THEN
  6.                 _RESIZE ON
  7.             ELSE
  8.                 _RESIZE OFF
  9.             END IF
  10.         END IF
  11.     END IF
  12.  
  13.     'Resize event:
  14.     '(Triggered either programatically or by directly resizing the form):
  15.     DIM CheckResize AS _BYTE
  16.     CheckResize = _RESIZE
  17.     IF (CheckResize AND Control(__UI_FormID).CanResize) OR (CheckResize AND __UI_DesignMode) OR __UI_CurrentBackColor <> Control(__UI_FormID).BackColor OR Control(__UI_FormID).Width <> _WIDTH(0) OR Control(__UI_FormID).Height <> _HEIGHT(0) THEN
  18.         _DELAY .1
  19.         IF CheckResize THEN
  20.             Control(__UI_FormID).Width = _RESIZEWIDTH
  21.             Control(__UI_FormID).Height = _RESIZEHEIGHT
  22.         END IF
  23.         IF Control(__UI_FormID).Width > 0 AND Control(__UI_FormID).Height > 0 THEN
  24.             __UI_CurrentBackColor = Control(__UI_FormID).BackColor
  25.  
  26.             __UI_HasResized = 2 'Indicate this process is in the middle
  27.  
  28.             OldScreen& = _DISPLAY
  29.             SCREEN _NEWIMAGE(Control(__UI_FormID).Width, Control(__UI_FormID).Height, 32)
  30.             _FREEIMAGE OldScreen&
  31.             'Recreate the main form's canvas
  32.             IF Control(__UI_FormID).Canvas <> 0 THEN _FREEIMAGE Control(__UI_FormID).Canvas
  33.             Control(__UI_FormID).Canvas = _NEWIMAGE(Control(__UI_FormID).Width, Control(__UI_FormID).Height, 32)
  34.             _DEST Control(__UI_FormID).Canvas
  35.             COLOR Control(__UI_FormID).ForeColor, Control(__UI_FormID).BackColor
  36.             CLS
  37.             IF __UI_HasMenuBar = True THEN
  38.                 'Add menubar div to main form's canvas
  39.                 _FONT Control(__UI_FormID).Font
  40.                 __UI_MenuBarOffsetV = falcon_uspacing& + (((_FONT = 8) * -1) * __UI_Font8Offset + ((_FONT = 16) * -1) * __UI_Font16Offset) + 5 + 2
  41.                 LINE (0, __UI_MenuBarOffsetV - 1)-STEP(Control(__UI_FormID).Width - 1, 0), Darken(Control(__UI_FormID).BackColor, 80)
  42.                 LINE (0, __UI_MenuBarOffsetV)-STEP(Control(__UI_FormID).Width - 1, 0), Darken(Control(__UI_FormID).BackColor, 120)
  43.                 __UI_RefreshMenuBar
  44.             ELSE
  45.                 __UI_MenuBarOffsetV = 0
  46.             END IF
  47.             _DEST 0
  48.  
  49.             IF LEN(__UI_CurrentTitle) THEN _TITLE __UI_CurrentTitle
  50.  
  51.             __UI_HasResized = True
  52.             __UI_HasInput = True
  53.         END IF
  54.     END IF
  55.  

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Can a Screen Be Resized by Code?
« Reply #18 on: January 11, 2019, 08:15:39 am »
Fellippe, I hadn't wanted to use the Global CanResize, but wanted to allow form resizing "on the fly", depending upon whether the screen was large (allow) or small (not allow).  When I changed the CanResize property in the UiEditor, it does allow resizing, but then the start form is diplayed with the wrong size, even though lines Control(__UI_FormID).Width = 310 and Control(__UI_FormID).Height = 360 are set at __UI_OnLoad.

So, I can either have the CanResize on from the start, and then the first screen comes out the wrong size, or I can have the screens my desired size but not resizable.

"On the fly" resizing with lines IF Level%% > 0 THEN Control(__UI_FormID).CanResize = True  and then Control(__UI_FormID).CanResize = False doesn't work, because the necessary code lines haven't been created.

I'll decide which of the two options I'll take.

FellippeHeitor

  • Guest
Re: Can a Screen Be Resized by Code?
« Reply #19 on: January 11, 2019, 08:32:08 am »
but then the start form is diplayed with the wrong size, even though lines Control(__UI_FormID).Width = 310 and Control(__UI_FormID).Height = 360 are set at __UI_OnLoad

Set the initial value at the .frm file instead.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Can a Screen Be Resized by Code?
« Reply #20 on: January 11, 2019, 11:15:31 am »
Fellippe, you may have noticed that I placed a query about resizing in the general section where I asked if $Resize plus _RESIZE (with suitable code), automatically resized everything inside the screen: I couldn't work out how this was being achieved.  I now see from your remarks here that the parameters  _RESIZEWIDTH and _RESIZEHEIGHT have to be used to adjust all _PUTIMAGE coordinate data (for images), adjusting the Mouse x- & y- accordingly and scaling Top, Left, Width and Height parameters for controls, otherwise only the window borders move during resizing.  I didn't believe that somehow the code knew which coordinates to adjust.  With just the CanResize parameter set to True, all that happens is that the window borders can be adjusted, as I would have expected. When I've properly mastered resizing, I'll revisit this.