3

When their BorderStyle is set to bsNone, TForms usually won't show scrollbars even if the AutoScroll is True and some children controls positions exceed ClientWidth/ClientHeight values.

So, is there any method/hack to "force" TForm to show scrollbars (when needed) even if its BorderStyle is set to bsNone?

Luthfi
  • 432
  • 2
  • 5
  • 13

1 Answers1

9

Put a TScrollBox on the form, make it Align=Client, put all your controls on the scroll box.

I always use a TScrollBox because it's very flexible. You can add a top-aligned panel to the form (outside the scroll-box) and you've got a non-scrolled area. Having the whole form scroll is not always helpful and it almost never looks good.

Cosmin Prund
  • 25,498
  • 2
  • 60
  • 104
  • Even better: Put your (child) forms inside frames instead. Your mainform would then be an empty form with a TScrollbox (aligned to client) and any childform would then be loaded inside the scroll box. – Wim ten Brink Jun 27 '11 at 08:26
  • @Wim, I don't understand your advice. Who's talking about child forms? – Cosmin Prund Jun 27 '11 at 08:33
  • Even in a single-form project, using a frame for the mainform is practical. A frame can be put inside a scrollbox, a regular form or anything else that's preferred. It allows form re-use, thus a frame could at one point be inside a form and somewhere else in a scrollbox as part of a larger screen. Thus, even more flexible... – Wim ten Brink Jun 27 '11 at 09:46
  • @Cosmin: Thanks, but it's actually my current solution. The real problem is I need to flip between showing a TImage as "fullscreen" and "normal" view, and I want to save a little resource by avoiding the use of TScrollbars since the containing form is already able to show scrollbars. – Luthfi Jun 27 '11 at 10:02
  • @Wim, I still don't get it. I'd guess the *main* form is the least likely candidate for reuse because you'll only have *one*, so replacing the whole form with a frame that's then embedded in the initial form doesn't seem like a practical idea. I do support the use of Frames in general, but I simply don't understand how they're relevant to *this* question. – Cosmin Prund Jun 27 '11 at 10:04
  • @Wim ten Brink: yes, I want to embed a child form inside another form, but sometimes I want that child form becoming "free" (when showing in full screen mode). So I think using TFrame is unnecessary. – Luthfi Jun 27 '11 at 10:05
  • 1
    @DonnVall, keep your existing solution. You'll save practically *nothing* by not including a ScrollBox on your form. What resource are you hoping to save? – Cosmin Prund Jun 27 '11 at 10:09
  • @DonnVall, actually, by using frames you could use two forms: one mainform with borders and a second form without borders for full-screen viewing. You could then "move" the frame between forms. The regular form would be normal, the fullscreen form uses bsNone and has an additional scrollbox. – Wim ten Brink Jun 27 '11 at 11:18
  • @Cosmin: Lol, sure. There is no problem with current solution. I am just looking a feasible way to avoid the use of TScrollbar that seems redundant. It is just for optimization (since the current solution is fine), what I want to conserve is just that Window handle required by TScrollBar and perhaps some painting overhead. Nothing mission critical, just to see if I could avoid the TScrollBar in easy way. – Luthfi Jun 27 '11 at 11:37
  • @Wim ten Brink: in both modes (in fullscreen and normal) the "child" form's BorderStyle stays in bsNone. When normal mode it's embedded in a TTabSheet in the main form. In full screen mode I just let it free (I mean not attached to any parent as in: Form1.Parent := nil;). This way I could switch between normal and fullscreen simply by setting the form's Parent property. – Luthfi Jun 27 '11 at 11:42
  • @DonnVall, if it ain't broke, don't fix it. One window handle is really not worth it. – Cosmin Prund Jun 27 '11 at 11:47
  • In normal mode, the frame would be a child of TTabsheet. In fullscreen mode, it's a child of a borderless, simple and new form. You can actually move the frame from the tabsheet to the fullscreen form and back again, thus not needing too many handles. You'd just switch the parent from one form to the other... – Wim ten Brink Jun 27 '11 at 15:19