?
Solved

Switching BorderStyle

Posted on 2003-10-30
7
Medium Priority
?
300 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 800 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month11 days, 9 hours left to enroll

752 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