Solved

Switching BorderStyle

Posted on 2003-10-30
7
290 Views
Last Modified: 2010-04-05
I like to switch the TForm.BorderStyle property from anything to bsNone and back. It appears that the controls on the form move up a little bit because of the missing border. Also the client area grows for the same reason. I like the controls to stay at the same screen coordinates and client area to stay the same size.

->
procedure ChangeBorderStyle(const form: TForm; const borderStyle: TBorderStyle);
begin
  ???
end;

My problems:
  - the amount I have to add/substract to TForm.Width and TForm.Height are different for different styles (bsSingle, bsSizable...)
  - if I switch forward and backward a couple of times my form was slightly growing in size (roundoff error?)

Thanks!
0
Comment
Question by:j42
  • 4
  • 3
7 Comments
 
LVL 2

Author Comment

by:j42
ID: 9650741
<grammer checker kicks in>

My problems:
 - the amount I have to add/substract to TForm.Width and TForm.Height is different for different styles (bsSingle, bsSizable...)
 - if I switch forward and backward a couple of times my form is slightly growing in size (roundoff error?)
0
 
LVL 8

Accepted Solution

by:
gmayo earned 200 total points
ID: 9651967
Seems to work quite well, although looks odd when maximised with a maximised window beneath it!

procedure TForm1.FormClick(Sender: TObject);
var
      sz : TPoint;
      oldpos, zpos, newpos : TPoint;
begin
      sz.X := ClientWidth;
      sz.Y := ClientHeight;
      zpos.X := 0;
      zpos.Y := 0;
      oldpos := ClientToScreen(zpos);
      if BorderStyle = bsNone then BorderStyle := bsSizeable else BorderStyle := bsNone;
      Application.ProcessMessages;
      newpos := ClientToScreen(zpos);
      Left := Left + oldpos.X - newpos.X;
      Top := Top + oldpos.Y - newpos.Y;
      ClientWidth := sz.X;
      ClientHeight := sz.Y;
end;

Geoff M.
0
 
LVL 8

Expert Comment

by:gmayo
ID: 9651975
PS - grammAr ;-)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Author Comment

by:j42
ID: 9656166
> PS - grammAr
Darn!
0
 
LVL 2

Author Comment

by:j42
ID: 9656362
This works like a treat (I don't know what that means, just read it somewhere else ;-).
I guess Application.ProcessMessages is the magic inside? If I remove my forms will start growing.
Thanks a lot.

PS. If I find the guy who disabled the spell checker...
0
 
LVL 8

Expert Comment

by:gmayo
ID: 9656590
I found that you don't actually need the ProcessMessages. I thought it might be needed originally so that it resizes itself properly, but it appears  to do that anyway.

Cheers for the points.

Geoff M.
0
 
LVL 2

Author Comment

by:j42
ID: 9656775
>  I found that you don't actually need the ProcessMessages
Yep, you are right. The error is a little bit more subtle:
If you use bsSizeable (instead of bsSingle) and there is a control near the right or bottom border there may appear some scrollbars and the ClientWidth and ClientHeight are larger than the Width and Height propertys -> everything is messed up.
I used a Sleep(500) in the OnPaint event of the form to debug.

Anyway thank you for beeing helpful.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now