2012-03-18 3 views
2

Panel 컨트롤이 있고 그 위에 몇 개의 선과 원을 그려야합니다. 패널이 손상되지 않은 이유는 무엇입니까?C++/CLI이 코드가 줄을 그리지 않는 이유는 무엇입니까?

Graphics^graphics = panel->CreateGraphics(); 
Pen^ penCurrent = gcnew Pen(Color::Red); 
Point p1(10,10); 
Point p2(20,20); 
graphics->DrawLine(penCurrent,p1,p2); 
//panel->Invalidate(); //tried this to refresh too 

답변

1
Graphics^graphics = panel->CreateGraphics(); 
Pen^ penCurrent = gcnew Pen(Color::Red); 
Point p1(10,10); 
Point p2(20,20); 
graphics->DrawLine(penCurrent,p1,p2); 

delete graphics; 

다음 전체 예제는 작업과 그릴 라인을

#include "windows.h" 

    #using <mscorlib.dll> 
    #using <System.dll> 
    #using <System.Windows.Forms.dll> 
    #using <System.Drawing.dll> 

    using namespace System::Windows::Forms; 
    using namespace System; 
    using namespace System::Drawing; 


    ref class MyForm : public Form 
    { 

     public: 

     MyForm() 
     { 

      Text = "Hello, Windows Forms!"; 

      auto button = gcnew Button(); 
      button->Text = "Click Me!"; 

      button->Click += gcnew EventHandler(this, &MyForm::button_click); 

      this->Controls->Add(button); 
     } 



     void button_click(Object^ sender, EventArgs^ e) 
     { 

      auto g = this->CreateGraphics(); 

      g->DrawLine(Pens::Black, Point(10, 10), Point(50, 50)); 

      delete g; 
     } 

    }; 


    int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) 
    { 
     Application::Run(gcnew MyForm); 
    } 
+0

오류 오류 C2039입니다 : '폐기'가 : –

+1

':: :: 그래픽 그리기 시스템'을의 구성원이 아닌 좋아, 작품을 삭제하지만 패널에는 아무 것도 없습니다. 패널에 무언가를 그릴 수있는 다른 방법이 있습니까? 이전 코드에서 잘못되었을 수 있습니다 .. –

관련 문제