我制作的Windows表单应用与Windows Paint类似。它只有一个图片框和4个按钮(更改颜色,选择橡皮擦,选择笔和清除)。我遇到了colorDialog的问题。它应该打开一个颜色菜单,就像在Paint中一样。
到目前为止,这是我的代码(没有换色代码)......我真的不知道该怎么做。有人可以帮忙吗? :)
private: System::Void MyForm_Load(System::Object sender, System::EventArgs e)
{
bitmap = new Image(pictureBox->Width, pictureBox->Height);
using ::(Graphics g = Graphics.FromImage(bitmap)) g.Clear(Color.White);
pictureBox->Image = bitmap;
}
private: System::Void pictureBox_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
oldPosition = e->Location;
}
private: System::Void pictureBox_MouseMove(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
//this.setBackgroundColor(Color.WHITE);
if (e->Button == System::Windows::Forms::MouseButtons::Left)
{
Image ^ iBitMapImage;
Graphics ^g = Graphics::FromImage(iBitMapImage);
g.DrawLine(SolidBrush(Color::Black), oldPosition, e->Location);
oldPosition = e->Location;
pictureBox->Image = bitmap;
}
}
private: System::Void Clear_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void Color_Click(System::Object^ sender, System::EventArgs^ e) {
//zmenit farbu pera
ColorDialog colorSelection;
return (colorSelection)
}