How to remove the title bar from a form - delphi

Does anyone know how to create a Delphi form without a title bar? I have seen some some links/tips but its not exactly what I want and I couldn't do it myself.
This is what I am trying to achieve:

First, set BorderStyle to bsNone at design-time. Then declare the procedure CreateParams like so:
type
TForm1 = class(TForm)
private
protected
procedure CreateParams(var Params: TCreateParams); override; // ADD THIS LINE!
{ Private declarations }
public
{ Public declarations }
end;
and implement it like
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.Style := Params.Style or WS_THICKFRAME;
end;

Set BorderStyle to bsNone in Object Inspector

For better border style, you can add the WS_BORDER flag.
Like this:
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.Style := Params.Style or WS_BORDER or WS_THICKFRAME;
end;
Note than a soft line is drawn inside the border frame.

Related

How prevent href title attribute show over transparent Form?

I have these two code that makes a Form transparent.
Form1.AlphaBlend := True;
SetWindowLong(Form1.Handle, GWL_EXSTYLE, GetWindowLong(Form1.Handle,GWL_EXSTYLE) or WS_EX_TRANSPARENT or WS_EX_LAYERED);
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
protected
procedure CreateParams(var Params: TCreateParams); override;
end;
// AlphaBlend := True;
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle := Params.ExStyle or WS_EX_TOPMOST or WS_EX_TRANSPARENT;
Params.ExStyle := WS_EX_TRANSPARENT or WS_EX_TOPMOST;
end;
When mouse is over a link with a title attribute, this appear over transparent Form. How prevent this behavior?

How to create transparent control with TCustomTransparentControl?

I want to create a transparent panel that holds an PNG image that has transparency in it. I want to put this panel on top of other panels and see trough.
I have the code below but it won't accept controls. If I uncomment the commented lines the IDE raises an exception when I put the controls on the form.
unit TransparentPanel5;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Vcl.Controls, ExtCtrls;
type
TTransparentPanel5 = class(TCustomTransparentControl)
private
public
constructor Create(AOwner: TComponent); override;
procedure CreateParams(var Params: TCreateParams); override;
end;
procedure Register;
implementation
constructor TTransparentPanel5.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
//ControlStyle := ControlStyle - [csSetCaption]+ [csAcceptsControls];
end;
procedure TTransparentPanel5.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
// Params.ExStyle := Params.ExStyle + WS_EX_Transparent;
// ControlStyle := ControlStyle - [csOpaque] + [csAcceptsControls]
end;
procedure Register;
begin
RegisterComponents('His', [TTransparentPanel5]);
end;
end.
You've got two unrelated questions. I chose to answer the second one.
The IDE raise an AV because you fail to apply extended styles properly. You have to use or operator to set a bit. When you use + you add up the value of the style bit and end up with an entirely different meaning, in this case with some WS_EX_MDICHILD which causes the CreateWindowEx call to fail.
Should be like this:
procedure TTransparentPanel5.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle := Params.ExStyle or WS_EX_Transparent;
// ControlStyle := ControlStyle - [csOpaque] + [csAcceptsControls]
end;
Note that it won't have any effect since the TCustomTransparentControl already sets that extended style.

Delphi resizable bsDialog Form?

How can I make a Form (ShowModal) with BorderStyle bsDialog. but one that could still be resized and have the close button (without the Icon,Minimize, Maximize)?
I do not need it to show the size grip.
Here is my solution which seems to work OK:
type
TForm2 = class(TForm)
procedure FormCreate(Sender: TObject);
private
protected
procedure CreateWnd; override;
procedure CreateParams(var Params: TCreateParams); override;
public
end;
var
Form2: TForm2;
implementation
{$R *.DFM}
procedure TForm2.FormCreate(Sender: TObject);
begin
BorderIcons := [biSystemMenu];
BorderStyle := bsSizeable;
AutoScroll := False;
end;
procedure TForm2.CreateWnd;
begin
inherited;
SendMessage(Handle, WM_SETICON, 1, 0);
end;
procedure TForm2.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle := Params.ExStyle or WS_EX_DLGMODALFRAME or WS_EX_WINDOWEDGE;
end;
IMO, This cant be done with bsDialog but the above feels and looks just like a "bsDialog" which could be resized.
Set the BorderStyle to bsSizeToolWin.

How to set CreateParams after the constructor has run?

TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
end;
TForm2 = class(TForm)
private
FAppWindow: Boolean;
protected
procedure CreateParams(var Params: TCreateParams); override;
public
property AppWindow: Boolean read FAppWindow write FAppWindow;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Form2 := TForm2.Create(Self);
Form2.AppWindow := True;
Form2.Show;
end;
procedure TForm2.CreateParams(var Params: TCreateParams);
begin
inherited;
if FAppWindow then begin
Params.Style := Params.Style or WS_EX_APPWINDOW;
Params.WndParent := 0;
end;
end;
This doesn't work, because the window handle is created during the constructor of TForm, so CreateParams is run too early and FAppWindow is always False.
Writing a custom constructor also doesn't work since you have to eventually call the inherited constructor which creates the handle before you can save any data to the instance:
constructor TForm2.CreateAppWindow(AOwner: TComponent);
begin
inherited Create(AOwner);
FAppWindow := True;
end;
Is there a way to:
Delay the creation of the window handle?
Alter the window style after creation of the window handle?
Recreate the window handle after the constructor has run?
Some other option I haven't thought of, yet?
How can I change the style of a form from the "outside" of the class?
The simplest solution is to pass the parameter to the form in its constructor, rather than wait until it has finished being created.
That means you need to introduce a constructor for TForm2 that accepts as parameters whatever information you need to pass on in CreateParams.
Make a note of any state before you call the inherited constructor. Also, there's no need to set WS_EX_APPWINDOW when you are setting the owner to be zero.
The nice thing about Delphi is that a derived constructor DOES NOT have to call the inherited constructor as its first statement. So you can set your FAppWindow member first, THEN call the inherited constructor to stream the DFM and create the window, eg:
procedure TForm1.FormCreate(Sender: TObject);
begin
Form2 := TForm2.CreateAppWindow(Self);
Form2.Show;
end;
constructor TForm2.CreateAppWindow(AOwner: TComponent);
begin
FAppWindow := True;
inherited Create(AOwner);
end;
This seems to work to recreate the handle, I got the idea from the RecreateAsPopup VCL method:
procedure TForm2.SetAppWindow(const Value: Boolean);
begin
FAppWindow := Value;
if HandleAllocated then
RecreateWnd
else
UpdateControlState;
end;

Right to left text in delphi trayicon BaloonHint

Is there a way to align text right in the delphi trayicon BaloonHint?
You would need to use your own hint window
type
TRTLHint = class(THintWindow)
protected
procedure CreateParams(var Params: TCreateParams); override;
end;
procedure TRTLHint.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.ExStyle := Params.ExStyle or WS_EX_LAYOUTRTL;
end;
You can then use this TRTLHint in this way.

Resources