How do I create MSPaint-like toolbar buttons? lazarus / 10-Designer ---------------------------------------------------------------------- nsunny · 2010-12-16 15:34 How do I create MSPaint-like toolbar buttons? Hi everyone, I am a newbie in Lazarus/Freepascal. I am trying to make a paint program just like MS Paint, but got stuck on a simple matter. I did not find any suitable tool to make a toolbar. A typical toolbar should have several tool buttons which would be able to be selected like radio buttons. When selecting one button, the last selected button would be "unselected"/normal state. (http://b.imagehost.org/0633/ms-paint-tools.gif) How can I create this kind of buttons? ---------------------------------------------------------------------- Imants · 2010-12-16 15:43 You can do this with TSpeedButton. It has property GroupIndex and Down. bt1.GroupIndex := 1; bt2.GroupIndex := 1; bt3.GroupIndex := 1; bt4.GroupIndex := 1; bt2.Down := True; // After this bt2 will be down bt3.Down := True; // After this bt2 will be up an bt3 will be down ---------------------------------------------------------------------- typo · 2010-12-16 16:05 It seems that there is a problem with TSpeedButton's Down property which nsunny should report on BugTracker. ---------------------------------------------------------------------- Sora-Kun · 2010-12-16 18:03 Hi Dorp a Toolbar on your app then on that toolbar add many ToogleBox. That will work. and when each ToogleBox is selected make some code which deselects all the other (since only one tool have to be selected). Good luck on your project and please let us know if it's finished it's really interesting. LinkOS ---------------------------------------------------------------------- Imants · 2010-12-16 18:14 Quote from: typo on December 16, 2010, 05:05:22 pmIt seems that there is a problem with TSpeedButton's Down property which nsunny should report on BugTracker. If GroupIndex = 0 then Dow property don't work ---------------------------------------------------------------------- typo · 2010-12-16 18:17 QuoteIf GroupIndex = 0 then Dow property don't work You have reason. SpeedButton is better to use for it than ToggleBox. But PaintBox component seems to have problems. ---------------------------------------------------------------------- nsunny · 2010-12-17 07:36 QuoteGood luck on your project and please let us know if it's finished  it's really interesting.- Yes, of course i would let u know. I did not find any paint program written in freepascal/lazarus so i started to write my own. And this is helping me to learn lazarus more effectively. But I will need all your help for this... QuoteSpeedButton is better to use for it than ToggleBox.- I would have to agree with typo on this. I find it very easy. --------- I have another question. Do I have to write code for each speedbutton/tool separately? or is there any other system which would allow me to do all the stuff from one procedure? For example, currently I am using TRadioGroup as tool options. So I can use TRadioGroup.ItemIndex to select one tool: Code: [Select]procedure TForm1.RadioGroup1Click(Sender: TObject); begin   ToolIndex := RadioGroup1.ItemIndex; end; Is there such a way for speedbuttons? (In vb6 there is an index option for objects' names... anything similar in lazarus?) ---------------------------------------------------------------------- typo · 2010-12-17 14:37 You can use only one event handler to all SpeedButtons, as they have a Sender parameter. ---------------------------------------------------------------------- nsunny · 2010-12-18 18:21 QuoteYou can use only one event handler to all SpeedButtons, as they have a Sender parameter.@typo Can you tell me how to do this? I have created some tspeedbuttons named ToolBtn1, ToolBtn2, ToolBtn3 .... I want to set the "ToolIndex" variable according to which tool button clicked. I have set the Speedbutton.Tag property to appropriate index: Code: [Select]ToolBtn1.Tag := 0; ToolBtn2.Tag := 1; ToolBtn3.Tag := 2; .... .... I have tried to set "ToolIndex" in the following way: Code: [Select]procedure TForm1.ToolBtn1Click(Sender: TObject); begin   ToolIndex := Sender.Tag; end; (please notice the part Sender.Tag) It raises error: Quotezzz.pas(xxx,yyy) Error: identifier idents no member "tag" I have set the OnClick event of the tool buttons to "ToolBtn1Click", and not created new procedure for each one. ---------------------------------------------------------------------- typo · 2010-12-18 18:29 Code: [Select]// linked to all speedbuttons procedure TForm1.SpeedButton1Click(Sender: TObject); begin   if Sender = SpeedButton1 then     // code to the SpeedButton1   else if Sender = SpeedButton2 then     // code to the SpeedButton2   {...}   ; end; ---------------------------------------------------------------------- nsunny · 2010-12-18 18:36 Quote from: typo on December 18, 2010, 07:29:18 pmCode: [Select]// linked to all speedbuttons procedure TForm1.SpeedButton1Click(Sender: TObject); begin   if Sender = SpeedButton1 then     // code to the SpeedButton1   else if Sender = SpeedButton2 then     // code to the SpeedButton2   {...}   ; end; Thanks, well i have done it another way: Code: [Select]procedure TForm1.ToolBtn1Click(Sender: TObject); begin   ToolIndex := (Sender as TSpeedButton).Tag; end; And of course I have set appropriate tag for the buttons... Searched and found this article