Solved

TSpeedButton

Posted on 1998-09-22
9
554 Views
Last Modified: 2010-05-18
Is it possible to align text in TSpeedButton (.Caption) to the most left or right?
0
Comment
Question by:gljsentvid16
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 2

Expert Comment

by:333
ID: 1340624
Hi,
I'm not sure, that it's what you need, but...

Try to change TSpeedButton.Layout to blGlyphLeft or blGlyphRight and set TSpeedButton.Margin to i.e 1. If TSpeedButton.Margin=-1 (default), Text and Glyph are centered horizontaly and verticaly. When you change Margin to 1, then Text and Glyph are aligned depending on TSpeedButton.Layout.

A.
0
 

Author Comment

by:gljsentvid16
ID: 1340625
Hi!

 Nope, this just specifies, how the glyph and text are oriented. What I would like is to set the caption of the button to the most left or right corner of the button (like in Text editors such as MSWord where you can set align).

M.
0
 
LVL 2

Expert Comment

by:rene100
ID: 1340626
try it with TSpeedButton.layout:=[blGlyphRight] or [blGlyphLeft]

regards
rene
0
 
LVL 2

Expert Comment

by:333
ID: 1340627
Can't you make glyph, that covers whole button?

A.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:Matvey
ID: 1340628
Basically, you could play with it, like putting a button without text, and putting a label on it. SpeedButton has no defined way to do exactly what you want, though it's not hard to change it's sources at all. Also if you use the normal TButton instead, I bet you have a way to do this.
0
 

Author Comment

by:gljsentvid16
ID: 1340629
Hi!

  .layout[] will not do. If I wanted to create glyph, I would have to create .bmp image (from .caption), and glue it on - naah, too much to do. Putting label on it covers OnClick event, so this one won't do either. And yes, I need to use TSpeedButton, cos TButton is not .Flat and .Down . If you know how to change sources please, tell me :-).

   M.
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1340630
OK, I'll look and try to change them. Do you use bitmaps with your buttons? Because it's VERY simple if you don't use glyphs, otherwise it'll be harder.

Menwhile, you can try: put a label on the button, and in the label's OnMouseDown, OnMouseUp, OnMouseMove, send the same messages to the button beneath. Not MouseDown, MouseUp methods, but messages with SendMesages: WM_LBUTTONDOWN, WM_LBUTTONUP.

--Matvey
0
 

Author Comment

by:gljsentvid16
ID: 1340631
Matvey, I don't use glyphs so I'm glad it's easy :-)

M.
0
 
LVL 3

Accepted Solution

by:
Matvey earned 50 total points
ID: 1340632
Here we go. This works fine unless you want to use glyphs.

save this in a unit, and install as a component.
Have fun!
--Matvey
___________________________________________________________
unit btn_AL;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Buttons;

type
  TSpeedButton_AL = class(TSpeedButton)
  private
    FCaption: string;
    FAlignment: TAlignment;
  protected
    procedure Paint; override;
    procedure SetCaption(Value: string);
    procedure SetAlignment(Value: TAlignment);
  published
    property Caption: string read FCaption write SetCaption;
    property Alignment: TAlignment read FAlignment write SetAlignment;
  end;

procedure Register;

implementation

var
  Pattern: TBitmap = nil;

procedure CreateBrushPattern;
var
  X, Y: Integer;
begin
  Pattern := TBitmap.Create;
  Pattern.Width := 8;
  Pattern.Height := 8;
  with Pattern.Canvas do
  begin
    Brush.Style := bsSolid;
    Brush.Color := clBtnFace;
    FillRect(Rect(0, 0, Pattern.Width, Pattern.Height));
    for Y := 0 to 7 do
      for X := 0 to 7 do
        if (Y mod 2) = (X mod 2) then  { toggles between even/odd pixles }
          Pixels[X, Y] := clBtnHighlight;     { on even/odd rows }
  end;
end;

procedure TSpeedButton_AL.SetCaption(Value: string);
begin
  FCaption := Value;
  Paint;
end;

procedure TSpeedButton_AL.SetAlignment(Value: TAlignment);
begin
  FAlignment := Value;
  Paint;
end;

procedure TSpeedButton_AL.Paint;
const
  TextAlignments: array[TAlignment] of Integer =
         (DT_LEFT, DT_RIGHT, DT_CENTER);
var
  rText: TRect;
  P: TPoint;
begin
  inherited Paint;
  rText := Rect(1, 1, Width-1, Height-1);
  with Canvas do
  begin
    GetCursorPos(P);
    if (FState = bsExclusive) and
       (not Flat or not (FindDragTarget(P, True) = Self)) then begin
      if Pattern = nil then CreateBrushPattern;
      Canvas.Brush.Bitmap := Pattern;
    end
    else begin
      Brush.Style := bsSolid;
      Brush.Color := clBtnFace;
    end;
    FillRect(rText);

    Font := Self.Font;
    Brush.Style := bsClear;
    if (FState = bsDown) or (FState = bsExclusive) then begin
      inc(rText.Top);
      inc(rText.Left);
    end;
    if FState = bsDisabled then
    begin
      OffsetRect(rText, 1, 1);
      Font.Color := clBtnHighlight;
      DrawText(Handle, PChar(Caption), Length(Caption), rText,
             TextAlignments[Alignment] or DT_VCENTER or DT_SINGLELINE);
      OffsetRect(rText, -1, -1);
      Font.Color := clBtnShadow;
      DrawText(Handle, PChar(Caption), Length(Caption), rText,
             TextAlignments[Alignment] or DT_VCENTER or DT_SINGLELINE);
    end else
      DrawText(Handle, PChar(Caption), Length(Caption), rText,
             TextAlignments[Alignment] or DT_VCENTER or DT_SINGLELINE);
  end;

end;

procedure Register;
begin
  RegisterComponents('Samples', [TSpeedButton_AL]);
end;

end.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 94
IExtractImage Delphi 14 207
build html 5 client that connect to indy Tidtcpserver 3 357
Dev express lookupcombo 3 14
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now