Page 1 of 1

How to make controls' background transparent?

Posted: Sat May 02, 2009 2:02 pm
by netpole
Anyone knows how to implement a transparent background?

Code: Select all

	panel3_ = new wxPanel(this);
	panel3_->SetSize(wxSize(200, 200));
	panel3_->Connect(wxID_ANY, wxEVT_ERASE_BACKGROUND, wxEraseEventHandler(
		DummyPanel::OnErase));

Code: Select all

void 
DummyPanel::OnErase(wxEraseEvent& e) {
	wxClientDC* client_dc = NULL;

	if (e.GetDC() == NULL) {
		client_dc = new wxClientDC(this->panel3_);
	}

	wxDC& dc = client_dc == NULL ? *e.GetDC() : *client_dc;
	dc.SetBrush(*wxTRANSPARENT_BRUSH);
	dc.DrawRectangle(this->GetRect());

	if (client_dc != NULL) {
		delete client_dc;
	}
}
I tried above code but it doesn't work correctly. I need your help. Thanks.

Posted: Sat May 02, 2009 3:47 pm
by Auria
Which platform? Can you show a screenshot? On my wxMac, I know components do have a transparent background, unless we don't mean the same thing

Posted: Sun May 03, 2009 1:26 am
by netpole
On wxMSW, wxAnimationCtrl doesn't have a transparent background though the bitmap shows on it is transparent. So I trid to extend it to meet my need. Currently, I make it by copying the region from parent's DC and draw it as background and it works. I wonder if there's a better way?