Easy way to show tab activity for TTabSheet

In principle, I need an activity indicator that immediately shows that an active calculation is being performed on this tab. I'm looking for something very simple, like displaying a gif on a tab or displaying a sequence of lines that change with a timer. I do not want a complex solution or a solution requiring new components.

I already have an implementation, but I have a problem with this that I am asking for a more specific solution here: How to show a backslash in a Japanese locale

In the event that there is no solution to another problem or that there is a significantly better way to do this, I ask a more general question. In any case, I'm sure there will be others who could use a good way to do this.

+4
source share
2 answers

Update:

The easiest way is probably this:

  • Add a TImageList to your form.
  • Add animation images to the image list.
  • Set the cMaxImageIndex constant to the last index of the animated list.
  • Connect ImageList to TPageControl .
  • Declare a NextImageIndex function.
  • Activate the timer if necessary.
  • In the timer event, set the tabsheet ImageIndex property.

See code:

 Const cMaxImageIndex = 5; procedure TForm1.FormCreate(Sender: TObject); begin FImageIndex := 0; end; function TForm1.NextImageIndex: Integer; begin Inc(FImageIndex); if (FImageIndex > cMaxImageIndex) then FImageIndex:= 0; Result := FImageIndex; end; procedure TForm1.Timer1Timer(Sender: TObject); begin PageControl1.Pages[0].ImageIndex := NextImageIndex; end; 

Note Before activating the timer, set FImageIndex to zero, and when the job is complete, you can also have some logic to have a default image for the tab.

+3
source

Another approach would be to use the PageControl or TabControl OnDrawTab event. Again, you will need a mechanism to start the redraw, but you can either draw the image directly on the tab canvas, or switch the asterisk, or cycle through a series of points. This approach gives you more flexibility. Here's the OnTabDraw event, which does nothing more than draw tabs with a static gradient; You can use it as a starting point.

 procedure TabDraw(Control: TCustomTabControl; TabIndex: Integer; const Rect: TRect; Active: Boolean); const TCM_GETITEMRECT = $130A; type TRIVERTEX = packed record X, Y: DWORD; Red, Green, Blue, Alpha: Word; end; var vert: array[0..1] of TRIVERTEX; gRect: GRADIENT_RECT; iHeight, iWidth: Integer; begin with FTabControl.Canvas do begin if Active then begin Brush.Color := TAB_ACTIVECOLOUR; FillRect(Rect); end else begin vert[0] .x := Rect.Left; vert[0] .y := Rect.Top; vert[0] .Red := $ab00; vert[0] .Green := $ab00; vert[0] .Blue := $ab00; vert[0] .Alpha := $ab00; vert[1] .x := Rect.Right; vert[1] .y := Rect.Bottom; vert[1] .Red := $ef00; vert[1] .Green := $ef00; vert[1] .Blue := $fe00; vert[1] .Alpha := $0000; gRect.UpperLeft := 0; gRect.LowerRight := 1; GradientFill(FTabControl.Canvas.Handle, @vert, 2, @gRect, 1, GRADIENT_FILL_RECT_V); end; iHeight := (Rect.Bottom - Rect.Top) - TextHeight(FTabControl.Tabs[TabIndex]); if not Active then Inc(iHeight, 4); iWidth := (Rect.Right - Rect.Left) - TextWidth(FTabControl.Tabs[TabIndex]); Brush.Style := bsClear; TextOut(Rect.Left + (iWidth div 2), Rect.Top + (iHeight div 2), FTabControl.Tabs[TabIndex]); end; end; 
+1
source

Source: https://habr.com/ru/post/1394291/


All Articles