I dynamically add several TImage controls to a TPanel, and want to draw lines between them, but TPanel does not have Canvas.  You can draw on a TPaintBox, but I cannot use TImage smiles on it. Tell me how to get out of this simple situation.
            Asked
            
        
        
            Active
            
        
            Viewed 404 times
        
    0
            
            
        
        Remy Lebeau
        
- 555,201
 - 31
 - 458
 - 770
 
        Dan49
        
- 21
 - 2
 
- 
                    1What do you mean with "TImage smiles"? Do you load some "smileys" into images? Maybe you can do without `TImage`s, paint those "smileys" as bitmaps directly on the `TPaintBox`. Then it's easy to add the lines between. – Tom Brunberg Apr 01 '21 at 13:28
 - 
                    I want to use only TImage – Dan49 Apr 01 '21 at 13:32
 - 
                    By all means, if that's what you want. Then place them on a form directly and draw your lines on the form canvas. – Tom Brunberg Apr 01 '21 at 13:38
 - 
                    Possible duplicate of [How to draw on a TPanel](https://stackoverflow.com/questions/813693/). Personally, I would do what Tom suggested - use a `TPaintBox` and draw bitmaps and line on it as needed. What is wrong with doing that? – Remy Lebeau Apr 01 '21 at 19:57
 
1 Answers
1
            
            
        I have dealt with this issue
// before describing the form class in the h-file:
namespace CanvasPanel
{
    class TPanel : public Extctrls::TPanel
    {
    public:
        __property Canvas;
    };
}
#define TPanel CanvasPanel::TPanel
 
// next - the form class, and everything is unchanged...
class TForm1 : public TForm
        Dan49
        
- 21
 - 2
 
- 
                    `#define TPanel CanvasPanel::TPanel` should be replaced with `typedef CanvasPanel::TPanel TPanel;`, or `using TPanel = CanvasPanel::TPanel;` in C++11 onward. Either way, a DFM will not actually instantiate `CanvasPanel::TPanel` objects, though. It may be easier to just let the Form continue using `Extctrls::TPanel` normally, and then you can type-cast a ` Extctrls::TPanel*` to a `CanvasPanel::TPanel*` when you want to access the `Canvas` property, eg: `((CanvasPanel::TPanel*)Panel1)->Canvas->...`. – Remy Lebeau Apr 07 '21 at 23:33