Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
356 views
in Technique[技术] by (71.8m points)

pascalscript - How do I change the color of my progress bar in Inno Setup?

I create a progress bar using TNewProgressBar.
The default color of the progress bar is green.
I would like to change the color to blue.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You cannot.


The progress bar is styled by the current Windows theme. In the default Windows theme, the progress bar is green (or yellow or red, if the progress bar is in paused or error state, see TNewProgressBar.State).

You would have to completely reimplement the drawing of the progress bar or disable visual themes of whole installer.
See How to change the color of progressbar in C# .NET 3.5?

But the Inno Setup API does not allow you to reimplement the drawing. And you probably do not want to disable the visual themes.


If you really need the blue color, you may consider implementing the progress bar yourself using TBitmapImage.Bitmap.Canvas (using methods like .Rectangle).

A simple example:

var
  ProgressImage: TBitmapImage;

procedure InitializeWizard();
begin
  ProgressImage := TBitmapImage.Create(WizardForm);
  ProgressImage.Parent := WizardForm;
  ProgressImage.Left := ScaleX(10);
  ProgressImage.Top := WizardForm.ClientHeight - ScaleY(34);
  ProgressImage.Width := ScaleX(200);
  ProgressImage.Height := ScaleY(20);
  ProgressImage.BackColor := clWhite;
  ProgressImage.Bitmap.Width := ProgressImage.Width;
  ProgressImage.Bitmap.Height := ProgressImage.Height;
end;

procedure DrawProgress(Image: TBitmapImage; Progress: Integer);
var
  Canvas: TCanvas;
  Width: Integer;
begin
  Log(Format('Drawing progress %d', [Progress]));

  Canvas := Image.Bitmap.Canvas;

  Canvas.Pen.Style := psClear;

  Width := Image.Bitmap.Width * Progress / 100
  Log(Format('Bar size: %d x %d', [Width, Image.Bitmap.Height]));

  Canvas.Brush.Color := clHighlight;
  Canvas.Rectangle(1, 1, Width, Image.Bitmap.Height);

  Canvas.Brush.Color := clBtnFace;
  Canvas.Rectangle(Width - 1, 1, Image.Bitmap.Width, Image.Bitmap.Height);

  Canvas.Pen.Style := psSolid;
  Canvas.Pen.Mode := pmCopy;
  Canvas.Pen.Color := clBlack;
  Canvas.Brush.Style := bsClear;
  Canvas.Rectangle(1, 1, Image.Bitmap.Width, Image.Bitmap.Height);
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  Log(Format('CurPageChanged %d', [CurPageID]));
  DrawProgress(ProgressImage, (CurPageID * 100 / wpFinished));
end;

Drawn progress bar


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...