怎样将这个delphi 窗体颜色效果变成控件的显示
展开全部
不传入paintbox的句柄,直接操作paintbox控件就可以了。我修改了一下,其中方法的句柄无用:(TGradientDirection对象不知道是什么,也去掉了)
procedure TForm1.FillGradient(DC: HDC; ARect: TRect;StartColor, EndColor: TColor);
var
StartRGB,EndRGB: array [0..2] of Byte;
RGBKoef: array [0..2] of Double;
Brush: HBRUSH;
ColorCount: Integer;
AreaWidth, AreaHeight, I: Integer;
ColorRect: TRect;
RectOffset: Double;
IntR,IntG,IntB :Integer;
begin
RectOffset := 0;
StartColor := ColorToRGB(StartColor);
EndColor := ColorToRGB(EndColor);
StartRGB[0] := GetRValue(StartColor);
StartRGB[1] := GetGValue(StartColor);
StartRGB[2] := GetBValue(StartColor);
EndRGB[0] := GetRValue(EndColor);
EndRGB[1] := GetGValue(EndColor);
EndRGB[2] := GetBValue(EndColor);
IntR :=(EndRGB[0] - StartRGB[0]);
IntG :=(EndRGB[1] - StartRGB[1]);
IntB :=(EndRGB[2] - StartRGB[2]);
ColorCount := max(abs(IntR), max(abs(IntG), abs(IntB)));
RGBKoef[0] := IntR / ColorCount;
RGBKoef[1] := IntG / ColorCount;
RGBKoef[2] := IntB / ColorCount;
AreaWidth := ARect.Right - ARect.Left;
AreaHeight := ARect.Bottom - ARect.Top;
// case ADirection of
// gdHorizontal:
RectOffset := AreaWidth / ColorCount;
// gdVertical:
// RectOffset := AreaHeight / ColorCount;
// end;
for I := 0 to ColorCount - 1 do
begin
Brush := CreateSolidBrush(RGB(
StartRGB[0] + Round((I + 1) * RGBKoef[0]),
StartRGB[1] + Round((I + 1) * RGBKoef[1]),
StartRGB[2] + Round((I + 1) * RGBKoef[2])));
SetRect(ColorRect, Round(RectOffset * I), 0, Round(RectOffset * (I + 1)), AreaHeight);
OffsetRect(ColorRect, ARect.Left, ARect.Top);
PaintBox1.Canvas.Brush.Handle := Brush;
PaintBox1.Canvas.FillRect(ColorRect);
DeleteObject(Brush);
end;
end;
调用:
FillGradient(GetDC(PaintBox1.Canvas.Handle),PaintBox1.ClientRect,clyellow,clblue);
procedure TForm1.FillGradient(DC: HDC; ARect: TRect;StartColor, EndColor: TColor);
var
StartRGB,EndRGB: array [0..2] of Byte;
RGBKoef: array [0..2] of Double;
Brush: HBRUSH;
ColorCount: Integer;
AreaWidth, AreaHeight, I: Integer;
ColorRect: TRect;
RectOffset: Double;
IntR,IntG,IntB :Integer;
begin
RectOffset := 0;
StartColor := ColorToRGB(StartColor);
EndColor := ColorToRGB(EndColor);
StartRGB[0] := GetRValue(StartColor);
StartRGB[1] := GetGValue(StartColor);
StartRGB[2] := GetBValue(StartColor);
EndRGB[0] := GetRValue(EndColor);
EndRGB[1] := GetGValue(EndColor);
EndRGB[2] := GetBValue(EndColor);
IntR :=(EndRGB[0] - StartRGB[0]);
IntG :=(EndRGB[1] - StartRGB[1]);
IntB :=(EndRGB[2] - StartRGB[2]);
ColorCount := max(abs(IntR), max(abs(IntG), abs(IntB)));
RGBKoef[0] := IntR / ColorCount;
RGBKoef[1] := IntG / ColorCount;
RGBKoef[2] := IntB / ColorCount;
AreaWidth := ARect.Right - ARect.Left;
AreaHeight := ARect.Bottom - ARect.Top;
// case ADirection of
// gdHorizontal:
RectOffset := AreaWidth / ColorCount;
// gdVertical:
// RectOffset := AreaHeight / ColorCount;
// end;
for I := 0 to ColorCount - 1 do
begin
Brush := CreateSolidBrush(RGB(
StartRGB[0] + Round((I + 1) * RGBKoef[0]),
StartRGB[1] + Round((I + 1) * RGBKoef[1]),
StartRGB[2] + Round((I + 1) * RGBKoef[2])));
SetRect(ColorRect, Round(RectOffset * I), 0, Round(RectOffset * (I + 1)), AreaHeight);
OffsetRect(ColorRect, ARect.Left, ARect.Top);
PaintBox1.Canvas.Brush.Handle := Brush;
PaintBox1.Canvas.FillRect(ColorRect);
DeleteObject(Brush);
end;
end;
调用:
FillGradient(GetDC(PaintBox1.Canvas.Handle),PaintBox1.ClientRect,clyellow,clblue);
2017-11-15 · 知道合伙人互联网行家
关注
展开全部
不传入paintbox的句柄,直接操作paintbox控件就可以了。我修改了一下,其中方法的句柄无用:(TGradientDirection对象不知道是什么,也去掉了)
procedure TForm1.FillGradient(DC: HDC; ARect: TRect;StartColor, EndColor: TColor);
var
StartRGB,EndRGB: array [0..2] of Byte;
RGBKoef: array [0..2] of Double;
Brush: HBRUSH;
ColorCount: Integer;
AreaWidth, AreaHeight, I: Integer;
ColorRect: TRect;
RectOffset: Double;
IntR,IntG,IntB :Integer;
begin
RectOffset := 0;
StartColor := ColorToRGB(StartColor);
EndColor := ColorToRGB(EndColor);
StartRGB[0] := GetRValue(StartColor);
StartRGB[1] := GetGValue(StartColor);
StartRGB[2] := GetBValue(StartColor);
EndRGB[0] := GetRValue(EndColor);
EndRGB[1] := GetGValue(EndColor);
EndRGB[2] := GetBValue(EndColor);
IntR :=(EndRGB[0] - StartRGB[0]);
IntG :=(EndRGB[1] - StartRGB[1]);
IntB :=(EndRGB[2] - StartRGB[2]);
ColorCount := max(abs(IntR), max(abs(IntG), abs(IntB)));
RGBKoef[0] := IntR / ColorCount;
RGBKoef[1] := IntG / ColorCount;
RGBKoef[2] := IntB / ColorCount;
AreaWidth := ARect.Right - ARect.Left;
AreaHeight := ARect.Bottom - ARect.Top;
// case ADirection of
// gdHorizontal:
RectOffset := AreaWidth / ColorCount;
// gdVertical:
// RectOffset := AreaHeight / ColorCount;
// end;
for I := 0 to ColorCount - 1 do
begin
Brush := CreateSolidBrush(RGB(
StartRGB[0] + Round((I + 1) * RGBKoef[0]),
StartRGB[1] + Round((I + 1) * RGBKoef[1]),
StartRGB[2] + Round((I + 1) * RGBKoef[2])));
SetRect(ColorRect, Round(RectOffset * I), 0, Round(RectOffset * (I + 1)), AreaHeight);
OffsetRect(ColorRect, ARect.Left, ARect.Top);
PaintBox1.Canvas.Brush.Handle := Brush;
PaintBox1.Canvas.FillRect(ColorRect);
DeleteObject(Brush);
end;
end;
调用:
FillGradient(GetDC(PaintBox1.Canvas.Handle),PaintBox1.ClientRect,clyellow,clblue);
procedure TForm1.FillGradient(DC: HDC; ARect: TRect;StartColor, EndColor: TColor);
var
StartRGB,EndRGB: array [0..2] of Byte;
RGBKoef: array [0..2] of Double;
Brush: HBRUSH;
ColorCount: Integer;
AreaWidth, AreaHeight, I: Integer;
ColorRect: TRect;
RectOffset: Double;
IntR,IntG,IntB :Integer;
begin
RectOffset := 0;
StartColor := ColorToRGB(StartColor);
EndColor := ColorToRGB(EndColor);
StartRGB[0] := GetRValue(StartColor);
StartRGB[1] := GetGValue(StartColor);
StartRGB[2] := GetBValue(StartColor);
EndRGB[0] := GetRValue(EndColor);
EndRGB[1] := GetGValue(EndColor);
EndRGB[2] := GetBValue(EndColor);
IntR :=(EndRGB[0] - StartRGB[0]);
IntG :=(EndRGB[1] - StartRGB[1]);
IntB :=(EndRGB[2] - StartRGB[2]);
ColorCount := max(abs(IntR), max(abs(IntG), abs(IntB)));
RGBKoef[0] := IntR / ColorCount;
RGBKoef[1] := IntG / ColorCount;
RGBKoef[2] := IntB / ColorCount;
AreaWidth := ARect.Right - ARect.Left;
AreaHeight := ARect.Bottom - ARect.Top;
// case ADirection of
// gdHorizontal:
RectOffset := AreaWidth / ColorCount;
// gdVertical:
// RectOffset := AreaHeight / ColorCount;
// end;
for I := 0 to ColorCount - 1 do
begin
Brush := CreateSolidBrush(RGB(
StartRGB[0] + Round((I + 1) * RGBKoef[0]),
StartRGB[1] + Round((I + 1) * RGBKoef[1]),
StartRGB[2] + Round((I + 1) * RGBKoef[2])));
SetRect(ColorRect, Round(RectOffset * I), 0, Round(RectOffset * (I + 1)), AreaHeight);
OffsetRect(ColorRect, ARect.Left, ARect.Top);
PaintBox1.Canvas.Brush.Handle := Brush;
PaintBox1.Canvas.FillRect(ColorRect);
DeleteObject(Brush);
end;
end;
调用:
FillGradient(GetDC(PaintBox1.Canvas.Handle),PaintBox1.ClientRect,clyellow,clblue);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询