How to make controls' background transparent? Topic is solved

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
netpole
In need of some credit
In need of some credit
Posts: 2
Joined: Fri May 01, 2009 2:59 am

How to make controls' background transparent?

Post 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.
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post 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
netpole
In need of some credit
In need of some credit
Posts: 2
Joined: Fri May 01, 2009 2:59 am

Post 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?
Post Reply