1

I'm trying to create a custom transparent wxTextCtrl by driving from it and drawing the text myself as follow:

BEGIN_EVENT_TABLE(TextLayer, wxTextCtrl)
    EVT_PAINT(TextLayer::OnPaint)
    EVT_ERASE_BACKGROUND(TextLayer::OnEraseBackground)
END_EVENT_TABLE()

void TextLayer::OnEraseBackground(wxEraseEvent& event) {}
void TextLayer::OnPaint(wxPaintEvent & evt)
{
    wxAutoBufferedPaintDC  dc(this);
    PrepareDC(dc);

    wxGraphicsContext *gc = wxGraphicsContext::Create( dc );

    if(gc)
    {
        dc.SetFont(GetFont());
        dc.SetTextForeground(GetForegroundColour());
        auto a = GetValue();
        dc.DrawText(GetValue(), 0, 0);
        delete gc;
    }
}

but it's not working , it's not transparent , how I'm supposed to do it correctly?

Abanoub
  • 3,623
  • 16
  • 66
  • 104
  • you will be better off creating some kind of a transparent panel, give it a focus, and then catch the EVT_KEY_DOWN/EVT_PAINT events. The reason being - I don't thin you can override native control painting. – Igor Aug 01 '16 at 18:28
  • call evt.Skip() in your TextLayer class as it seems that you are stopping the event right at your OnPaint function. – macroland Aug 02 '16 at 06:08

1 Answers1

2

Sorry, but you won't be able to make a native control transparent. You can have custom transparent controls with wxGTK (see the "erase" sample), but not the native ones.

VZ.
  • 21,740
  • 3
  • 39
  • 42