Solved

Switching BorderStyle

Posted on 2003-10-30
7
294 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

786 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