ImageEn, unit imageenview

TImageEnView.OnButtonClick

TImageEnView.OnButtonClick


Declaration

property OnButtonClick: TIEVButtonClickEvent;


Description

Occurs when the user clicks on a button.



If you do not specify an OnButtonClick event or set Handled to false, then a default action will be occur depending on the button type.


Example

// EXAMPLE 1: Using buttons to navigate images in a TImageEnMView

// Select event of our TImageEnMView
procedure TForm1.ImageEnMView1ImageSelect(Sender: TObject; idx: Integer);
begin
  ImageEnView1.LockUpdate();

    // Show either Zoom In or Zoom Out depending on which is most relevant
    ImageEnView1.ShowButtons := [ iebtZoomIn, iebtZoomOut ];

    // Have previous image?
    if ImageEnMView1.SelectedImage > 0 then
      ImageEnView1.ShowButtons := ImageEnView1.ShowButtons + [ iebtPrevious ];

    // Have next image?
    if ImageEnMView1.SelectedImage < ImageEnMView1.ImageCount - 1 then
      ImageEnView1.ShowButtons := ImageEnView1.ShowButtons + [ iebtNext ];

  // Load Image
  if ImageEnMView1.SelectedFilename <> '' then
    ImageEnView1.IO.LoadFromFile( ImageEnMView1.SelectedFilename )
  else
    ImageEnView1.Blank;
  ImageEnView1.Fit( False );

  ImageEnView1.UnlockUpdate();
end;

// Button Click event of our TImageEnView
procedure TForm1.ImageEnView1ButtonClick(Sender: TObject; Button: TIEVButton;
    MouseButton: TMouseButton; Shift: TShiftState; var Handled: Boolean);
begin
  case Button of
    iebtPrevious : begin
                     if ssShift in Shift then
                       ImageEnMView1.Seek( ieioSeekFirst )
                     else
                       ImageEnMView1.Seek( ieioSeekPrior );
                     ImageEnMView1ImageSelect(nil, 0); // Update preview and buttons
                   end;
    iebtNext     : begin
                     if ssShift in Shift then
                       ImageEnMView1.Seek( ieioSeekLast )
                     else
                       ImageEnMView1.Seek( ieioSeekNext );
                     ImageEnMView1ImageSelect(nil, 0); // Update preview and buttons
                   end;
    iebtZoomIn   : begin
                     if ImageEnView1.Zoom < ImageEnView1.GetIdealZoom() then
                       ImageEnView1.Zoom := ImageEnView1.GetIdealZoom()
                     else
                     if ImageEnView1.Zoom < 100 then
                       ImageEnView1.Zoom := 100;
                   end;
    iebtZoomOut  : begin
                     if ImageEnView1.Zoom > ImageEnView1.GetIdealZoom() then
                       ImageEnView1.Zoom := ImageEnView1.GetIdealZoom()
                     else
                     if ImageEnView1.Zoom > 100 then
                       ImageEnView1.Zoom := 100;
                   end;
  end;
end;


// EXAMPLE 2: Using buttons to navigate pages of a multi-frame image, such as TIFF or GIF

procedure TMainForm.btnLoadClick(Sender: TObject);
begin
  if OpenImageEnDialog1.Execute then
  begin
    ImageEnView1.IO.Params.ImageIndex := 0;
    ImageEnView1.IO.LoadFromFile( OpenImageEnDialog1.FileName );
    UpdateStatus();
  end;
end;

procedure TMainForm.UpdateStatus();
var
  havePrev, haveNext: Boolean;
begin
  ImageEnView1.ButtonParams.Color := clSilver;
  ImageEnView1.ButtonParams.Size  := 30;

  havePrev := ( ImageEnView1.IO.Params.Filename <> '' ) and ( ImageEnView1.IO.Params.ImageIndex > 0 );
  haveNext := ( ImageEnView1.IO.Params.Filename <> '' ) and ( ImageEnView1.IO.Params.ImageIndex < ImageEnView1.IO.Params.ImageCount - 1 );

  if havePrev and haveNext then
    ImageEnView1.ShowButtons := [ iebtPrevious, iebtNext ]
  else
  if havePrev then
    ImageEnView1.ShowButtons := [ iebtPrevious ]
  else
  if haveNext then
    ImageEnView1.ShowButtons := [ iebtNext ]
  else
    ImageEnView1.ShowButtons := [];
end;

procedure TMainForm.ImageEnView1ButtonClick(Sender: TObject; Button: TIEVButton;
    MouseButton: TMouseButton; Shift: TShiftState; var Handled: Boolean);
begin
  Handled := False; // Let ImageEnView handle the navigation and zooming
  UpdateStatus();
end;