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
Solved

Switching BorderStyle

Posted on 2003-10-30
7
297 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Simple Delphi Question 9 95
Find and Replace Stream with 0s 8 69
How to build JSON File in Delphi 6 3 44
Delphi problems to abort a printjob 9 24
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

791 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