在表单app中更改笔的颜色 - 画像

时间:2016-03-30 20:19:52

标签: winforms c++-cli colordialog

我制作的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)

}

1 个答案:

答案 0 :(得分:0)

我认为你需要调用ColorDialog :: ShowDialog。 MSDN有一个示例here