Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Switching BorderStyle

Posted on 2003-10-30
7
Medium Priority
?
301 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

609 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