Вверх ↑
Ответов: 5227
Рейтинг: 587
#1: 2022-01-25 15:50:49 ЛС | профиль | цитата
nesco, в GDI+ нет RoundRectangle к сожалению, но есть FillPath и DrawPath
мне конечно неизвестно что ты колдуешь но отпрвной точкой для создания GDI+ контролов был именно этот код, можешь сравнить с руш в котором сам чёрт ногу сломит
Практически заготовка для градиентной панели. (градиентная панель есть и в KOL, просто поверте у меня старый комп, но это очень плохой выбор)

Add(MainForm,2953706,63,56)
{
Width=410
Height=187
}
Add(InlineCode,9888594,168,126)
{
WorkPoints=#20:doDrawRoundRectangle|
DataPoints=#4:Ctrl|
Code=#15:unit HiAsmUnit;|0:|9:interface|0:|45:uses kol,Windows,Share,Debug,GDIPOBJ,GDIPAPI;|0:|4:type|28: THiAsmClass = class(TDebug)|10: private|0:|9: public|21: Ctrl: THI_Event;|62: procedure doDrawRoundRectangle(var dt: TData; idx: word);|5: end;|1: |85:function CreateRoundRectangle(rectangle: TGPRect; radius: integer): TGPGraphicsPath; |0:|14:implementation|0:|66:function IntToGPColor(Value: TColor; Alpha: byte = 255): TGPColor;|3:var|47: ArrARGB: array [0..2] of byte absolute Value;|5:begin|70: Result := GDIPAPI.MakeColor(Alpha,ArrARGB[0],ArrARGB[1],ArrARGB[2]);|4:end;|0:|43:procedure THiAsmClass.doDrawRoundRectangle;|3:var|20: Control: PControl;|11: R: TRect;|24: Graphics: TGPGraphics;|24: Path: TGPGraphicsPath;|18: GPRect: TGPRect;|18: Brush: TGPBrush;|15: Pen: TGPPen; |36: Color1,Color2,PenColor: TGPColor; |5:begin|34: Control := ReadControl(Ctrl,'');|26: R := Control.ClientRect;|30: Dec(R.Bottom); Dec(R.Right);|56: Graphics := TGPGraphics.Create(Control.Canvas.Handle);|52: Graphics.SetSmoothingMode(SmoothingModeAntiAlias);|32: GPRect := GDIPAPI.MakeRect(R);|42: Path := CreateRoundRectangle(GPRect,20);|34: Color1 := IntToGPColor(clWhite);|38: Color2 := IntToGPColor(clSkyBlue); |93: Brush := TGPLinearGradientBrush.Create(GPRect, Color1, Color2, LinearGradientModeVertical);|33: Graphics.FillPath(Brush, Path);|36: PenColor := IntToGPColor($FFAD5B);|35: Pen := TGPPen.Create(PenColor); |30: Graphics.DrawPath(Pen,Path);|2: |39: // можно и GDI совместно использовать|45: Control.Canvas.Brush.BrushStyle := bsClear;|43: //Control.Canvas.DrawText('Caption',R,0);|42: Control.Canvas.TextOut(10,10,'Caption');|2: |11: Pen.Free;|13: Brush.Free;|12: Path.Free;|19: Graphics.Free; |4:end;|77:// https://stackoverflow.com/questions/8738635/delphi-roundrect-with-gradient|49:function CreateRoundRectangle(rectangle: TGPRect;|36: radius: integer): TGPGraphicsPath;|3:var|24: path: TGPGraphicsPath;|21: l,t,w,h,d: integer;|5:begin|33: path := TGPGraphicsPath.Create;|19: l := rectangle.X;|19: t := rectangle.y;|23: w := rectangle.Width;|24: h := rectangle.Height;|35: d := radius div 2; // divide by 2|0:|66: // the lines beween the arcs are automatically added by the path|46: path.AddArc(l, t, d, d, 180, 90); // topleft|55: path.AddArc(l + w - d, t, d, d, 270, 90); // topright|64: path.AddArc(l + w - d, t + h - d, d, d, 0, 90); // bottomright|56: path.AddArc(l, t + h - d, d, d, 90, 90); // bottomleft|21: path.CloseFigure();|17: Result := path;|4:end;|0:|4:end.|
link(Ctrl,6406300:PHandle,[])
}
Add(PaintBox,6406300,161,56)
{
Left=50
Top=35
Width=110
Height=70
Font=[Tahoma,8,0,128,0]
Point(PHandle)
Point(onPaint)
link(onPaint,9888594:doDrawRoundRectangle,[(205,69)(205,101)(156,101)(156,132)])
}


--- Добавлено в 2022-01-25 15:56:19

IntToGPColor может конечно не так обозвал но это моя прелесть , ну если кто сделает короче то снимаю шляпу...
карма: 4
Мой форум - http://hiasm.bbtalk.me/ схемы, компоненты...
0
Редактировалось 1 раз(а), последний 2022-01-25 15:56:19