Shape a form to a bitmap

January 23, 2020 0

Shape a form to a bitmap unit Unit1; interface uses Windows, Classes, SysUtils, Graphics, Forms; type TRGBArray = array[0..32767] of TRGBTriple; PRGBArray = ^TRGBArray; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private […]

Prevent Windows from minimizing a Form

January 23, 2020 0

Prevent Windows from minimizing a Form The Windows Taskbar function “Minimize all Windows” minimizes all Windows even if they don’t have a minimize button. The following code will prevent a form from minimizing through windows. […]

Export a TListView to a TStringGrid

January 23, 2020 0

Export a TListView to a TStringGrid procedure ListView2StringGrid(Listview: TListView; StringGrid: TStringGrid); const MAX_SUBITEMS = 5; var i, j: Integer; begin with ListView do for i := 0 to Items.Count – 1 do begin {Get Item […]

Close a form animated

January 23, 2020 0

Close a form animated var tutup: Boolean; i: Integer; procedure TForm1.Timer1Timer(Sender: TObject); var reg1, reg2: hrgn; begin if tutup = True then begin i := i + 10; reg1 := CreateRoundRectRgn(0 + i, 0 + […]

Position an InputQuery centered over a form

January 23, 2020 0

I borrowed the code from InputQuery and added the stuff to center the InputQuery form on top of another form instead of positioning it in the middle of the screen. function GetAveCharSize(Canvas: TCanvas): TPoint; var […]

Reduce a form by right-clicking on the titlebar

January 23, 2020 0

Reduce a form by right-clicking on the titlebar type TForm1 = class(TForm) private { Private-Deklarationen } FOldHeight: Integer; procedure WMNCRButtonDown(var Msg: TWMNCRButtonDown); message WM_NCRBUTTONDOWN; public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.DFM} […]

Making the Enter Key act like Tab

January 23, 2020 0

This code gives the key the same habbit as the key to change focus between Controls. Form1.KeyPreview := True ! procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char); begin if Key = #13 then begin Key := […]

Make an animated application icon

January 23, 2020 0

Make an animated application icon var icon1: Boolean; {….} procedure TForm1.Timer1Timer(Sender: TObject); begin icon1 := not Icon1; case Icon1 of True: Application.icon := Image1.Picture.Icon; False: Application.icon := Image2.Picture.Icon; end; end; procedure TForm1.FormCreate(Sender: TObject); begin icon1 […]

Show multiline Text in a TCombobox

January 23, 2020 0

Show multiline Text in a TCombobox unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) ComboBox1: TComboBox; procedure FormCreate(Sender: TObject); procedure ComboBox1MeasureItem(Control: TWinControl; Index: Integer; var Height: […]

Create a form with rounded corners

January 23, 2020 0

The CreateRoundRectRgn function creates a rectangular region with rounded corners procedure TForm1.FormCreate(Sender: TObject); var rgn: HRGN; begin Form1.Borderstyle := bsNone; rgn := CreateRoundRectRgn(0,// x-coordinate of the region’s upper-left corner 0, // y-coordinate of the region’s […]

Close a TCommonDialog automatically

January 23, 2020 0

It is possible to close a common dialog shown by TCommonDialog.Execute (or its overriddens) method while it is visible and application handles messages. The solution is: SendMessage(GetParent(OpenDialog1.Handle), WM_SYSCOMMAND, SC_CLOSE, 0);

Show forms on a TScrollBox

January 23, 2020 0

Show forms on a TScrollBox Before you show the Form you must simply set the parent property of the form: procedure TForm1.Button1Click(Sender: TObject); begin Form2.Parent := ScrollBox1; Form2.Show; end;

Add several forms to Taskbar/Task Manager

January 23, 2020 0

Add several forms to Taskbar/Task Manager By default, when you create the application in Delphi, in Windows Task Manager will be included a main form handle only. If you want to add the additional form, […]

Use the AnimateWindow function

January 23, 2020 0

Use the AnimateWindow function The AnimateWindow function enables you to produce special effects when showing or hiding windows. procedure TForm1.Button1Click(Sender: TObject); begin Form2.BringToFront; AnimateWindow(Form2.Handle, 3000, AW_BLEND); Form2.Show; {The 3. parameter can be one or more […]

Close a MDIChild form

January 23, 2020 0

Have you noticed that when you try to close a MDIChild form the form minimizes but doesn’t disappear from your Main form client area? With this tip you can learn how to really close the […]

Scale a form manually

January 23, 2020 0

The first parameter of ScaleBy is the multiplier, the second the divisor. The example scale the form to 150% procedure TForm1.Button1Click(Sender: TObject); begin ScaleBy(150, 100); end;

Make a form not resizable but moveable

January 23, 2020 0

Make a form not resizable but moveable private procedure WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo); message WM_GETMINMAXINFO; end; {…} implementation procedure TForm1.WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo); begin inherited; with Msg.MinMaxInfo^ do begin ptMinTrackSize.x := Form1.Width; ptMaxTrackSize.x := Form1.Width; ptMinTrackSize.y := […]

Shade components

January 23, 2020 0

Shade components procedure ShadeIt(f: TForm; c: TControl; Width: Integer; Color: TColor); var rect: TRect; old: TColor; begin if (c.Visible) then begin rect := c.BoundsRect; rect.Left := rect.Left + Width; rect.Top := rect.Top + Width; rect.Right […]

Draw a color outline around TForm

January 23, 2020 0

Create a message handler for the Windows Message WM_NCPAINT message. The following example paints a 1 pixel red border around the frame of the form. unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, […]

Show hints in the Statusbar

January 23, 2020 0

Show hints in the Statusbar private procedure MyHint(Sender: TObject); end; implementation {….} procedure TForm1.FormCreate(Sender: TObject); begin Application.OnHint := MyHint; ShowHint := True; Button1.Hint := ‘normal yellow hint|Text in Statusbar’; Button2.Hint := ‘only yellow hint|’; Button3.Hint […]

Make a Form semi-/ transparent

January 23, 2020 0

Make your forms 25%, 50% Transparent… TMyForm = class (TForm); TrackBar1: TTrackBar; //.. private FColorKey: TCOLOR; end; const // Use crKey as the transparency color. LWA_COLORKEY = 1; // Use bAlpha to determine the opacity […]

Read data from another MDIChild form

January 23, 2020 0

Read data from another MDIChild form type TMDIChildForm = class(TForm) Edit1: TEdit; private { Private declarations } procedure ReadDataFromOtherMDIChildForm; end; var MDIChildForm: TMDIChildForm; implementation {$R *.DFM} uses MainForm; // Property FormStyle of this form is […]

Check if a PopUp Menu is open

January 23, 2020 0

Check if a PopUp Menu is open Using the WM_MENUSELECT message of the form won’t work to check if the popup is open. Simply because the parent of the popup is not the form (check […]

Check if a TMainMenu is dropped down or not

January 23, 2020 0

Check if a TMainMenu is dropped down or not type TForm1 = class(TForm) // … private IsMenuOpen: Boolean; procedure WMMENUSELECT(var message: TWMMENUSELECT); message WM_MENUSELECT; end; implementation procedure TForm1.WMMENUSELECT(var message: TWMMENUSELECT); begin inherited; IsMenuOpen := not […]

Create a transparent TForm

January 23, 2020 0

Create a transparent TForm private { Private declarations } FullRgn, ClientRgn, CtlRgn: THandle; procedure MakeTransparent; procedure UndoTransparent; end; {…} implementation {…} procedure TForm1.MakeTransparent; var AControl: TControl; A, Margin, X, Y, CtlX, CtlY: Integer; begin Margin […]

Correct a BiDi bug in Delphi

January 23, 2020 0

Correct a BiDi bug in Delphi When you set the BiDiMode in you form to bdRightToLeft, you do only HALF mirroring. Since Win98 (Hebrew/Arabic version) mirror it’s envirement completly (the Minimize, Close, Maxmize buttons are […]

Create a sizable and none border style form

January 23, 2020 0

With this code you can create none border style (BorderStyle = bsNone) but sizeable windows (forms) First you must set BorderStyle := bsNone of your Form in Object Browser. There is your small but forced […]

Change a Hint’s Font

January 23, 2020 0

When the application displays a Help Hint, it creates an instance of HintWindowClass to represent the window used for displaying the hint. Applications can customize this window by creating a descendant of THintWindow and assigning […]

Get the active TWinControl under the mouse cursor

January 23, 2020 0

Get the active TWinControl under the mouse cursor You may call this function in a global event procedure, linking as many components events to it as you need. function FindControlAtPos: TWinControl; var Pt: TPoint; begin […]

Disable a MenuItem without greying it

January 23, 2020 0

Disable a MenuItem without greying it procedure TForm1.Button1Click(Sender: TObject); var M: TMenu; begin M := Application.MainForm.Menu; // The first Item will be disabled EnableMenuItem(M.Handle, M.Items[0].Command, MF_BYCOMMAND or MF_DISABLED); end;

Disable a form movement

January 23, 2020 0

Disable a form movement {….} private procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST; {….} procedure TForm1.WMNCHitTest(var Message: TWMNCHitTest); begin inherited; with Message do begin if Result = HTCAPTION then Result := HTNOWHERE; end; end;

Determine whether a window is ‘topmost’

January 23, 2020 0

Determine whether a window is ‘topmost’ function IsWindowTopMost(hWindow: HWND): Boolean; begin Result := (GetWindowLong(hWindow, GWL_EXSTYLE) and WS_EX_TOPMOST) 0 end; procedure TForm1.Button1Click(Sender: TObject); begin if isWindowTopMost(FindWindow(‘notepad’, nil)) then Label1.Caption := ‘Window ist topmost’ else Label1.Caption := […]

Show a second form with a active title bar

January 23, 2020 0

Show a second form with a active title bar To show a from/window with an active titlebar, send a WM_NCACTIVATE message to it. procedure TForm2.FormActivate(Sender: TObject); begin SendMessage(Application.MainForm.Handle, WM_NCACTIVATE, Boolean(True), 0); end;

1 2 3 9