我有两个picurebox的功能。我想在图片框上用鼠标点击画一些东西。
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 :(得分: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
事件中,使用mousex
和mousey
中保存的坐标绘制椭圆:
private: System::Void pictureBox1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e)
{
e->Graphics->DrawEllipse(Pens::Blue, mousex, mousey, 60, 60);
}
调整椭圆的宽度和高度,目前每个都有60个。