Search code examples
c++wxwidgets

wxWidgets: wxButton with label on top of bitmap


I would like to have a button with a text on top of the image that I can change. It does not seem like there are any label alignments that support this (only wxBU_LEFT | wxBU_TOP | wxBU_RIGHT | wxBU_BOTTOM).

The closest workaround that I have found is to resize the button so that the image does not get offset by having the label and then using spaces to pad the label onto the image. This seems to have some limitations: The label disappears (it's drawn under) if I change the foreground or background color. Also the button has to be initialized with a non empty string, i.e. " " instead of "" otherwise it will also be drawn under.

Is there any way I could do this and still be able to change the label or background color of the button?


Solution

  • By "on top" do you mean "above" or "over"? If it's the latter, you should create your own bitmap and draw the original bitmap and then your label on it using wxMemoryDC (if it's the former, this approach would also work, of course, but just using wxBU_TOP is much simpler).