[英]How to make colordialog appear?
I am simply trying to make a colordialog appear, using the following code as a test out/practise assignment.我只是想让一个颜色对话框出现,使用下面的代码作为测试/练习作业。
{
Point puntA = new Point(10, 300);
Point puntB = new Point(90, 200);
Pen tekenpotlood = new Pen(colorDialog1.Color , 4);
Graphics papier = pictureBox1.CreateGraphics();
papier.DrawLine(tekenpotlood, puntA, puntB);
}
I have dragged a colordialog onto the form, I have also added the code menntioned in the textbook (with or without erasing colordialog)我已经将一个颜色对话框拖到窗体上,我还添加了教科书中提到的代码(有或没有擦除颜色对话框)
any help is appreaciated with this problem..对这个问题有任何帮助。
Thanks a lot for the answer, Classes is the next chapter of the course, but i got it to work, with some changes.非常感谢您的回答,课程是课程的下一章,但我让它开始工作,并进行了一些更改。
here is the code now functioning:这是现在运行的代码:
public partial class Form1 : Form
{
ColorDialog colorDialog;
public Form1()
{
colorDialog = new ColorDialog();
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Pen pen = new Pen(colorDialog.Color, 4);
Point puntA = new Point(10, 300);
Point puntB = new Point(90, 200);
if (colorDialog.ShowDialog() == DialogResult.OK)
{
Graphics papier = pictureBox1.CreateGraphics();
papier.DrawLine(pen, puntA, puntB);
}
else
{
// The user cancelled the dialog
}
}
}
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.