2013-06-11 30 views
1

目前,我對Visual Studio中的Windows窗體應用程序,但每次我試着畫出一個形狀或符合油漆事件中,我得到這個錯誤:Paint事件的Visual Studio

C2228: 「.DrawString」的左邊必須有類/結構/聯合

下面是我的代碼,包括從頭文件中的痛苦事件:

using namespace System::Drawing; 
    void InitializeComponent(void) 
    { 
      this->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::Form1_Paint); 
    } 
    { 
    private: System::Void Form1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) { 
e.Graphics.DrawRectangle(blackPen, x, y, width, height); 
    } 
    }; 

任何幫助將不勝感激

+1

你不是在代碼片段調用'DrawString'。 –

+1

您需要學習正確的C++/CLI語法,它不是C#。 PaintEventArgs和Graphics是引用類型,您可以使用 - >箭頭來引用它們的成員。 –

回答

1

變化

e.Graphics.DrawRectangle(... 

e->Graphics->DrawRectangle(...