Firemonkey TControl subclass cannot draw on component

前端 未结 1 1379
清歌不尽
清歌不尽 2020-12-21 08:36

I want to try to create a firemonkey visual component and I have seen online that TControl gives the basic needs. This is what I have done so far:



        
1条回答
  •  时光说笑
    2020-12-21 08:51

    Your control is painting on shared canvas. By the time it reaches your control's Paint method value of Canvas.Stroke.Kind is TBrushKind.None so if you don't assign some other value to it, it will not actually paint anything.

    You have to add

    Canvas.Stroke.Kind := TBrushKind.Solid;
    

    But, that will only paint horizontal line (you forgot to create points and make DrawLine call for vertical one) and it will not fill the background with white color.

    The simplest way to do so is with

    Canvas.ClearRect(ClipRect, TAlphaColorRec.White);
    

    In general common canvas values can (and will) be changed by other controls. Better way to deal with those is to mimic code from TShape providing your own TFill and TStroke fields and assigning those to canvas before painting. That way you can be sure that you will not miss setting some particular Stroke or Fill value that can be changed outside your control.

    0 讨论(0)
提交回复
热议问题