我使用TNewProgressBar
创建了一个进度条
进度条的默认颜色为绿色
我想将颜色改为蓝色。
答案 0 :(得分:4)
你不能。
进度条由当前Windows主题设置样式。在默认的Windows主题中,进度条为绿色(如果进度条处于暂停状态或错误状态,则为黄色或红色,请参阅TNewProgressBar.State
)。
您必须完全重新实现进度条的绘图或禁用整个安装程序的视觉主题 见How to change the color of progressbar in C# .NET 3.5?
但Inno Setup API不允许您重新实现绘图。而你可能不想禁用视觉主题。
如果您确实需要蓝色,可以考虑使用TBitmapImage.Bitmap.Canvas
自己实施进度条(使用.Rectangle
等方法)。
一个简单的例子:
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;