0
我有一個System :: Windows :: Forms ::窗體,我試圖將背景設置爲透明。 此表單包含其他組件並具有背景圖像。在系統上的透明背景::窗口::窗體::形式
我嘗試了很多我在互聯網上看到的解決方案,但沒有任何工作。
- 將窗體透明度設置爲0 - >使整個窗體變得透明。
- 使用顏色::透明 - >不似乎工作
- 使用TransparencyKey - >似乎並不工作太...
- 覆蓋OnPaintBackground或OnPaint事件 - >事件並不似乎是叫...
圖示碼:
public ref class Form : public System::Windows::Forms::Form
{
public: Form(void) {
InitializeComponent();
}
public: void InitializeComponent(void)
{
SetStyle(ControlStyles::SupportsTransparentBackColor, true);
this->TransparencyKey = System::Drawing::Color::Fuchsia;
this->BackColor = System::Drawing::Color::Fuchsia;
// or ...
this->BackColor = System::Drawing::Color::Transparent;
}
protected: virtual void OnPaint(PaintEventArgs e)override {}
protected: virtual void OnPaintBackground(PaintEventArgs e)override {}
}
感謝您的幫助。 Cyrbil
編輯:
問題解決了,第一次了超越,它是:
protected: virtual void OnPaint(PaintEventArgs^ e)override {}
protected: virtual void OnPaintBackground(PaintEventArgs^ e)override {}
我只是忘了^。 然後,我不知道爲什麼,但我開始了一個新的項目,並嘗試其他方法,它工作正常。所以從現在起我用這個新項目和一切都很好。我想這只是Visual C++誰有一些隨機問題。
不*編輯InitializeComponent(),它是由設計者自動生成的。在設計器重新生成代碼時,您在那裏寫的任何內容都會隨機消失。在調用InitializeComponent()之後,將代碼移至構造函數**。 – 2012-08-02 17:46:04