2012-03-18 2 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

':: ::グラフィックス描画システム' のメンバーではありませんいいえ、作品を削除しても、パネルには何も表示されません。パネルに何かを描く他の方法はありますか?私は前のコードで間違っているかもしれません.. –

関連する問題