我在Windows XP下使用Delphi7。我该如何向Delphi TOpenPictureDialog组件添加“删除”工具按钮?有什么方法可以使对话框进入设计器以添加按钮及其行为?
最佳答案
您可以在TOpenPictureDialog
中添加一个新按钮,但不能使对话框进入设计器,必须在运行时执行。
检查这个样本
procedure TForm1.FormCreate(Sender: TObject);
var
FDeleteButton : TSpeedButton;
FPreviewButton : TSpeedButton;
begin
FPreviewButton := TSpeedButton(OpenPictureDialog1.FindComponent('PreviewButton'));
FDeleteButton := TSpeedButton.Create(OpenPictureDialog1);
FDeleteButton.SetBounds(107, 1, 23, 22);
FDeleteButton.Parent := FPreviewButton.Parent;
FDeleteButton.NumGlyphs:=2;
FDeleteButton.Glyph.LoadFromResourceName(HInstance, 'BBABORT');
FDeleteButton.Name := 'DeleteButton';
FDeleteButton.OnClick := DeleteBtnClick;
end;
procedure TForm1.DeleteBtnClick(Sender: TObject);
begin
//here you must implement the delete logic
ShowMessage('Hello from delete button');
end;
结果是