How to change the form buttons (minimize, maximize and close)

Asked

Viewed 3,038 times

4

I have a project in Delphi 2010 where you would like to change the buttons icons Minimize, Maximize, Close-up that are represented in the image below:

inserir a descrição da imagem aqui

The icons I want to use were created by me, so I don’t want to change by options that already come with the Delphi, there is some way to do this, beyond the creation of a Panel in the Form with align to top with the buttons and passing the BorderStyle to bsNone?

If anyone can contribute anything thank you.

  • Search for skins in Delphi :)

  • Your button is a Tbitbtn ? If it is just put the image in the property Glyph.

  • the buttons in question are those of the form

  • I’m not sure if it’s introduced in Delphi 2010, but in XE you can customize a style, including the buttons form, see: http://community.embarcadero.com/blogs/entry/customizing-and-creating-vcl-styles-671

  • Aa, I understand your question. This @stderr example works. I’ve already had to do this once.

  • @stderr This configuration type is not available for Delphi 2010, any suggestions more?

  • @Karanpereira what you mean by this can be more explicit?

  • takes a look at your Delphi installation folder, inside the bin folder, must have an executable called Bitmapstyledesigner.exe

  • @Victorzanella knows where I can find this designide230.bpl file, when I run Bitmapstyledesigner.exe he says he has that missing file

  • Weird, bpls 23 are from Delphi 10 Seattle. And you said you have the 2010 version installed.

  • already had the two versions on the pc may have been that that screwed the . exe I’ll see if arrange to run it

  • Please do not vandalize your posts. It is inappropriate because it means that future readers will not get help from the answers.

Show 7 more comments

1 answer

2


If you can’t edit Style using BitmapStyleDesigner, there is a way (Technical arrangement) to make.

You should add a TPanel with Height of +/- 32 (at your discretion) with Align = alTop.

In this Panel you will add the buttons you want (I recommend Tspeedbutton) with Align = alRight, putting the buttons always arranged on the right if hide any or resize the window they will automatically align, similar to the original.

Now define the BordeStyle of the Form as bsNone.

To close the button use the Close

For the Minimize Button use the Application.Minimize

For the Restore/Minimize:

  if (Nome_Form.WindowState = wsMaximized) then
  begin
    Nome_Form.WindowState := wsNormal;
    {altere a imagem do botão aqui para a que desejar}
  end
  else
  begin
    Nome_Form.WindowState := wsMaximized;
    {altere a imagem do botão aqui para a que desejar}
  end;

Now just add the additional buttons you want,

Laborious, but if it is the last option you will notice that the result is TOP.

Edit 01: Moving the Form:

In the Onmousedown Panel Event (which is now your Title bar):

begin
  if (Button = mbLeft) then
  begin
    ReleaseCapture;
    Perform(WM_SYSCOMMAND,$F012,0);
  end;

Edit 02: Resizing the Form:

Declare in the Private: procedure WMNCHitTest(var Msg: TWMNCHitTest); message WM_NCHITTEST;

procedure Nome_Form.WMNCHitTest(var Msg: TWMNCHitTest);
var
  ScreenPt: TPoint;
begin
  //inherited;
  ScreenPt := ScreenToClient(Point(Msg.Xpos, Msg.Ypos));
  if (ScreenPt.x < 5) then
    Msg.Result := HTLEFT
    // top side
  else if (ScreenPt.y < 5) then
    Msg.Result := HTTOP
    // right side
  else if (ScreenPt.x >= Width - 5) then
    Msg.Result := HTRIGHT
    // bottom side
  else if (ScreenPt.y >= Height - 5) then
    Msg.Result := HTBOTTOM
    // top left corner
  else if (ScreenPt.x < 5) and (ScreenPt.y < 5) then
    Msg.Result := HTTOPLEFT
    // bottom left corner
  else if (ScreenPt.x < 5) and (ScreenPt.y >= Height - 5) then
    Msg.Result := HTBOTTOMLEFT
    // top right corner
  else if (ScreenPt.x >= Width - 5) and (ScreenPt.y < 5) then
    Msg.Result := HTTOPRIGHT
    // bottom right corner
  else if (ScreenPt.x >= Width - 5) and (ScreenPt.y >= Height - 5) then
    Msg.Result := HTBOTTOMRIGHT
end;

Note: The Statement of the procedure that resizes should be like this, different from the body of the procedure, works as if sending a SendMessage to the Api windows!

That way until the Mouse Cursor will change shape when approaching the form border!

Edit 03: Container New

Now as the Form has no edge, we need to create a new Container for the components that need to be aligned using for example alClient, alLeft etc...

In the OnResize of Form:

  Panel_Principal.Left   := 5;
  Panel_Principal.Top    := 5; {observar o outro panel que é a barra de Título}
  Panel_Principal.Width  := Nome_Form.Width - 10;
  Panel_Principal.Height := Nome_Form.Height - 10;

This way the Main Panel_and the Form will create the border effect.

Important: In order not to have all this trouble in all the Foms, you must use this as a Model and the others to use as Inheritance. However, for each new form on OnResize you should re-program the same OnResize.

  • In that case, what would the question of moving the form look like? Would it be necessary to tinker with the appearance of the button also to avoid the rounded edges of the Speedbutton ? How to enable form resizing ? These are options we missed when marking the form as bsNone. I believe the idea is valid, but would have much more work than just include the buttons.

  • 1

    The Speedbutton owns the Flat property, Enabled it gets Flat! About Move the form I’m already editing to add, when when resizing I have at home the code ready! Get there I put here. The ideal would be to make these changes in a form and use it as Inheritance, so the others already have the same pattern, only need to do once!

  • Cool, I’ll be waiting. Ever thought of providing a lib for this ?

  • @Júniormoreira thanks for the tip but as mentioned by Victor, in doing so I will lose many options which would be very useful to me, if I can complete the code then I would appreciate

  • Yes, the resize part when I get home I do this edit. Move Form is already in the answer!

  • 1

    @Juniorate I will then save by new edition of the answer

  • @Júniormoreira worked everything perfect, although it is not what I wanted, I would like to get another answer, but thank you for the effort and once again thank you

  • Quiet, appearing some news We updated here!

  • @I’m with a strees the resize does not work in the areas where I have components aligned the "edges" of the form any solution for this? By the way, is it possible for the form to have visible borders? besides all that I still have another question and possible to make a form this way and save, then start a new project and instead of the form of the Delphi I change the saved by this?

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.