Solved

ButtonGroup ?

Posted on 2010-11-17
11
2,367 Views
Last Modified: 2012-08-13
I am  analyzing how to add button to the buttongroup.

I want to add  buttons to the buttongroup and  handle the click event of the button.
Of course there there must be an image on the button and  only the buttons that are applicable will be shown from left to right.
Should  I use a canvas or is there an more easy way
 
If you can explain how it works and have an example then I can quick start.
Thks in advance.
0
Comment
Question by:advance1
11 Comments
 
LVL 25

Expert Comment

by:epasquier
ID: 34161018
Set the Images property of TButtonGroup to an ImageList where you loaded the icons you want for your buttons.
To add buttons, select the Items property of the ButtonGroup in the Components TreeView, then click the add button to add elements (you can also do that by right-clicking on the TButtonImage)
For all items (buttons), edit the caption and the imageIndex (in the ImageList). You can set an onClick event for each
TButtonGroup.png
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 34161068

You can add the buttons at design time by clicking on the Items property of the ButtonGroup. You will get a dialog for adding the buttons. To add images, drop an imagelist component on the form and assign it to the images property of the ButtonGroup. Set button images by using the Image index property and the onclick event by assigning a procedure to the onclick property.

In the code snippet is an example of how to do this at runtime
unit Unit3;



interface



uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, ButtonGroup, StdCtrls, ImgList;



type

  TForm3 = class(TForm)

    ButtonGroup1: TButtonGroup;

    ImageList1: TImageList;

    Button1: TButton;

    procedure Button1Click(Sender: TObject);

  private

    procedure ButtonClick(Sender: TObject);

  public

    { Public declarations }

  end;



var

  Form3: TForm3;



implementation



{$R *.dfm}



procedure TForm3.Button1Click(Sender: TObject);

var

  Btn: TgrpButtonItem;

begin

  Btn := ButtonGroup1.Items.Add;

  Btn.Caption := 'Button ' + IntToStr(ButtonGroup1.Items.Count);

  Btn.ImageIndex := ButtonGroup1.Items.Count mod 2;

  Btn.OnClick := ButtonClick;

end;



procedure TForm3.ButtonClick(Sender: TObject);

begin

  ShowMessage('Button Clicked');

end;



end.

Open in new window

object Form3: TForm3

  Left = 0

  Top = 0

  Caption = 'Form3'

  ClientHeight = 202

  ClientWidth = 318

  Color = clBtnFace

  Font.Charset = DEFAULT_CHARSET

  Font.Color = clWindowText

  Font.Height = -11

  Font.Name = 'Tahoma'

  Font.Style = []

  OldCreateOrder = False

  PixelsPerInch = 96

  TextHeight = 13

  object ButtonGroup1: TButtonGroup

    Left = 24

    Top = 24

    Width = 265

    Height = 105

    ButtonWidth = 100

    Images = ImageList1

    Items = <>

    TabOrder = 0

  end

  object Button1: TButton

    Left = 24

    Top = 144

    Width = 75

    Height = 25

    Caption = 'Add'

    TabOrder = 1

    OnClick = Button1Click

  end

  object ImageList1: TImageList

    Left = 184

    Top = 80

    Bitmap = {

      494C010102000800300010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600

      0000000000003600000028000000400000001000000001002000000000000010

      00000000000000000000000000000000000000000000078DBE00078DBE00078D

      BE00078DBE00078DBE00078DBE00078DBE00078DBE00078DBE00078DBE00078D

      BE00078DBE00078DBE0000000000000000000000000000000000000000000000

      000000000000A56F6F00A56F6F00A56F6F00A56F6F00A56F6F00A56F6F00A56F

      6F00A56F6F00A56F6F00A56F6F00000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      000000000000000000000000000000000000B8898900B8898900B8898900B889

      8900B8898900B8898900B889890065CDF90065CDF80065CDF90065CDF80066CE

      F90039ADD800078DBE0000000000000000000000000000000000000000000000

      000000000000A56F6F00FEFEFC00FEFEFE00FEFEFC00FEFEFC00FEFEFC00FEFE

      FC00FEFEFC00FEFEFC00A56F6F00000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      000000000000000000000000000000000000B8898900FEFDFB00FEFDFB00FEFD

      FB00FEFDFB00FEFDFB004D8743000C8518000C8518000C85180051BDB6006ED4

      F9003EB1D90084D7EB00078DBE00000000000000000000000000000000000000

      000000000000A56F6F00FEFAF6009E6458009E6458009E6458009E6458009E64

      58009E645800FEFAF600A56F6F00000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      000000000000000000000000000000000000B8898900FEF9F400FEF9F400FEF9

      F400FEF9F400FEF9F400B889890067CED6000C851800139825000C8518004BB7

      9A0042B4D400AEF1F900078DBE00000000000000000000000000000000000000

      000000000000A56F6F00FEF6EF00FEF8F300FEF6EF00FEF6EF00FEF6EF00FEF6

      EF00FEF6EF00FEF6EF00A56F6F00000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      000000000000000000000000000000000000B8898900FEF6ED00FEF6ED00FEF6

      ED00FEF6ED00FEF6ED00B889890083E4FC0084E4FC000C85180026B73F000C85

      180036A8A100B3F4F900078DBE0000000000A56F6F00A56F6F00A56F6F00A56F

      6F00A56F6F00A56F6F00FEF3E7009E6458009E6458009E6458009E6458009E64

      58009E645800FEF3E700A56F6F00000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      000000000000000000000000000000000000B8898900FFF2E700FFF2E700FFF2

      E700FAE8DE00FAE8DE00B88989008DEBFD008DEBFD005DC0A7000C85180037C4

      58000C851800ACF0EB006DCAE000078DBE00A56F6F00FEFEFC00FEFEFE00FEFE

      FC00FEFEFC00A56F6F00FEEFE100FFF0E300FEEFE100FEEFE100FEEFE100FEEF

      E100FEEFE100FEEFE100A56F6F00000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      000000000000000000000000000000000000B8898900FFEFE000FFEFE000FFEF

      E000D09F9E00D0A09E00C5939300ACE4DA009FDBCA0082AB81000C8518004EDB

      78000C85180098BA9900A3BFAC00078DBE00A56F6F00FEFAF6009E6458009E64

      58009E645800A56F6F00FFEBDA009E6458009E6458009E6458009E6458009E64

      58009E645800FFEBDA00A56F6F00000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      000000000000000000000000000000000000B8898900FFEBD900FFEBD900F3D7

      C900D5ABA800D1C8C200CD999900078780000C8518000C85180047D06E0059E3

      880042C667000C8518000C851800078DBE00A56F6F00FEF6EF00FEF8F300FEF6

      EF00FEF6EF00A56F6F00FFE7D300FFE7D300FFE7D300FFE7D300FFE7D300E2C9

      BA00E0CABA00CBB5A700A56F6F00000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      000000000000000000000000000000000000B8898900FFE8D200FFE8D200F3D4

      C400D9AEAC00CD9999009AF6FE009BF5FE0063C5A4000C8518005DE88E0063EE

      98004CD075000C851800F0F1E700B8898900A56F6F00FEF3E7009E6458009E64

      58009E645800A56F6F00FFE5CC00FFE3CB00FFE5CC00FFE5CC00FFE5CC00B495

      9100B5969200BFA19C00BF818100000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      000000000000000000000000000000000000B8898900B8898900B8898900B889

      8900CD999900A1FAFE00A1FBFE00A0FAFE00A1FBFE00737E57000C85180046CB

      6E000C851800EFEDDF00FEF6ED00B8898900A56F6F00FEEFE100FFF0E300FEEF

      E100FEEFE100A56F6F00FFE1C500FFE1C500FFE1C500FFE1C500FADCC100B697

      9300FEFEFE00BF81810000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      00000000000000000000000000000000000000000000078DBE00FEFEFE00A5FE

      FF00A5FEFF00A5FEFF00078DBE00078DBE00078DBE00B889890084B47B000C85

      1800EDE8D700FAE8DE00FAE8DE00B8898900A56F6F00FFEBDA009E6458009E64

      58009E645800A56F6F00FFDEC100FFDEC100FFDEC100FFDEC100E2C1AD00C5A7

      A000BF8181000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000078DBE00078D

      BE00078DBE00078DBE00000000000000000000000000B8898900FFEFE000FFEF

      E000FFEFE000D09F9E00D0A09E00C5939300A56F6F00FFE7D300FFE7D300FFE7

      D300FFE7D300A56F6F00A56F6F00A56F6F00A56F6F00A56F6F00A56F6F00BF81

      8100000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      00000000000000000000000000000000000000000000B8898900FFEBD900FFEB

      D900F3D7C900D5ABA800D1C8C200CD999900A56F6F00FFE5CC00FFE3CB00FFE5

      CC00FFE5CC00FFE5CC00B4959100B5969200BFA19C00BF818100000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      00000000000000000000000000000000000000000000B8898900FFE8D200FFE8

      D200F3D4C400D9AEAC00CD99990000000000A56F6F00FFE1C500FFE1C500FFE1

      C500FFE1C500FADCC100B6979300FEFEFE00BF81810000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      00000000000000000000000000000000000000000000B8898900B8898900B889

      8900B8898900CD9999000000000000000000A56F6F00FFDEC100FFDEC100FFDE

      C100FFDEC100E2C1AD00C5A7A000BF8181000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      000000000000000000000000000000000000A56F6F00A56F6F00A56F6F00A56F

      6F00A56F6F00A56F6F00BF818100000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      0000000000000000000000000000000000000000000000000000000000000000

      000000000000000000000000000000000000424D3E000000000000003E000000

      2800000040000000100000000100010000000000800000000000000000000000

      000000000000000000000000FFFFFF008003F801000000000003F80100000000

      0001F801000000000001F8010000000000010001000000000000000100000000

      0000000100000000000000010000000000000001000000000000000300000000

      8000000700000000C380000F00000000FF80003F00000000FF81007F00000000

      FF8300FF00000000FFFF01FF0000000000000000000000000000000000000000

      000000000000}

  end

end

Open in new window

ButtonGroup.png
0
 
LVL 25

Accepted Solution

by:
epasquier earned 500 total points
ID: 34161101
You can also use the TButtonGroup onClick event, that is used for all buttons that do not have their own onClick event. See code sample
TButtonGroup.zip
0
 

Expert Comment

by:srividhyapavani
ID: 34162521
Check it........
Pic1.png
Pic2.png
Pic3.png
0
 

Author Comment

by:advance1
ID: 34184012
Again Thks, i will check it out
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:advance1
ID: 34205985
I need the programming solution.

In the buttonclick event I want to know which button is clicked, so i can give an appropriate  message?
How will iknow what button is clicked ?
Making different eventhandlers for each button is not an option, because I dont know which buttons are added.
0
 
LVL 25

Expert Comment

by:epasquier
ID: 34206281
I gave you a full code sample for that in post #34161101
0
 

Author Comment

by:advance1
ID: 34206580
ok i understand, you can see it on index,

I will try it out,
Thks for your reaction
0
 

Author Comment

by:advance1
ID: 34213734
 
It work for the buttons with no clickevents
 
Dont forget to clesr the previous items: <code> ButtonGroup1.Items.Clear; </code>

I want also set the background  color of the hint to clInfoBk, How can I do that ?
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 34434323
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

747 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

10 Experts available now in Live!

Get 1:1 Help Now