PDA

View Full Version : سوال در مورد ToolBar



سیروس مقصودی
چهارشنبه 01 آبان 1392, 13:44 عصر
با سلام

من چگونه میتوانم از طریق کد نویسی یک Button روی یک Toolbar ایجاد کنم . چون میخواهم کاربر طبق سلیقه خود و به هر تعدادی که Button میخواهد روی Toolbar قرار دهد و چگونه میتوانم از طریق کد نویسی عملکرد button را مشخص کنم . وقتی کاربر Button مورد نظر را فشار میدهد مثلا عمل Close انجام شود

با تشکر

یوسف زالی
چهارشنبه 01 آبان 1392, 15:23 عصر
سلام.
کلا در هر جایی که لازم دارید کنترلی درست کنید، چند تا قانون رو حتما باید رعایت کنید:
1- Owner رو به چیزی ست کنید که با از بین رفتنش کنترل شما رو هم از بین ببره
2- Parent باید رو چیزی ست بشه که لازم دارید در اون نمایش داده بشه
3- برای رویداد ها باید متدهای مناسب ایجاد کنید..

شما استارت بزن کمک می کنم.

SayeyeZohor
چهارشنبه 01 آبان 1392, 21:17 عصر
اين پروسيجر باتون رو بعد از باتون قبلي ايجاد مي كنه

//-- Here is a generic procedure that takes a toolbar, and adds a button to it, with a specified caption: --//
procedure AddButtonToToolbar1(var bar: TToolBar; caption: string);
var
newbtn: TToolButton;
lastbtnidx: integer;
begin
newbtn := TToolButton.Create(bar);
newbtn.Caption := caption;
lastbtnidx := bar.ButtonCount - 1;
if lastbtnidx > -1 then
newbtn.Left := bar.Buttons[lastbtnidx].Left + bar.Buttons[lastbtnidx].Width
else
newbtn.Left := 0;
newbtn.Parent := bar;
end;



procedure TForm1.Button1Click(Sender: TObject);
begin
//-- And here is example usage of that procedure: --//
ToolBar1.ShowCaptions := True; //by default, this is False
AddButtonToToolbar1(ToolBar1, IntToStr(ToolBar1.ButtonCount));
end;



اين پروسيجر باتون رو قبل از باتون قبلي ايجاد مي كنه

//-- Your question does also ask how to add a button to an arbitrary place on the TToolbar. This code is similar to before, but it also allows you to specify which index you want the new button to appear after. --//
procedure AddButtonToToolbar2(var bar: TToolBar; caption: string; addafteridx: integer = -1);
var
newbtn: TToolButton;
prevBtnIdx: integer;
begin
newbtn := TToolButton.Create(bar);
newbtn.Caption := caption;

//if they asked us to add it after a specific location, then do so
//otherwise, just add it to the end (after the last existing button)
if addafteridx = -1 then begin
prevBtnIdx := bar.ButtonCount - 1;
end
else begin
if bar.ButtonCount <= addafteridx then begin
//if the index they want to be *after* does not exist,
//just add to the end
prevBtnIdx := bar.ButtonCount - 1;
end
else begin
prevBtnIdx := addafteridx;
end;
end;

if prevBtnIdx > -1 then
newbtn.Left := bar.Buttons[prevBtnIdx].Left + bar.Buttons[prevBtnIdx].Width
else
newbtn.Left := 0;

newbtn.Parent := bar;
end;



procedure TForm1.Button1Click(Sender: TObject);
begin
//-- And here is example usage for this revised version: --//
//by default, "ShowCaptions" is false
ToolBar1.ShowCaptions := True;

//in this example, always add our new button immediately after the 0th button
AddButtonToToolbar2(ToolBar1, IntToStr(ToolBar1.ButtonCount), 0);
//
//
ToolBtn := TToolButton.Create(ToolBar1);
WITH ToolBtn DO
BEGIN
Left := 0;
Top := 0;
//Caption = 'ToolButton1';
ImageIndex := 0;
Tag := 0;
END;
end;




يوسف جان ارادت ..................... :تشویق: