Solved

TSpeedButton

Posted on 1998-09-22
9
560 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 2

Expert Comment

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

A.
0
 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

770 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