2017-10-18 95 views
0

我有兩個picurebox函數。我想用picturebox上的鼠標點擊繪製一些東西。C++在picturebox上用鼠標點擊繪製東西

private: System::Void pictureBox1_MouseClick(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) { 
     int Curx = e->X; 
     int Cury = e->Y; 
} 

private: System::Void pictureBox1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) { 
      e->Graphics->DrawEllipse(Pens::Blue, 200,200, 1, 1); 
} 

我想在另一個使用的一個功能。

+0

這不是C#代碼,請儘量避免放置多個編程語言標記。 –

+0

@SpencerWieczorek它看起來像使用.NET擴展的C++,使它成爲一個奇怪的鴨子。 –

+0

@MarkRansom它是,.NET標籤需要在那裏。 –

回答

2

在已定義的圖片框代碼的private部分添加兩個變量的位置,x和y爲:

private: System::Windows::Forms::PictureBox^ pictureBox1; 
int mousex; 
int mousey; 

設置你的MouseClick事件保存座標這些變量和力一個通過調用Refresh()重繪:

private: System::Void pictureBox1_MouseClick(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) 
{ 
    mousex = e->X; 
    mousey = e->Y; 
    pictureBox1->Refresh(); 
} 

Paint情況下,你已經保存在mousexmousey座標畫出你的橢圓:

private: System::Void pictureBox1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) 
{ 
    e->Graphics->DrawEllipse(Pens::Blue, mousex, mousey, 60, 60); 
} 

調整橢圓的寬度和高度,每個橢圓的寬度和高度可以根據您的選擇進行調整。