Bitmap bt = new Bitmap(@"c:\1.jpg"); private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { Graphics g = pictureBox1.CreateGraphics(); g.DrawImage(bt, e.Location); g.Dispose(); }
但是~~! private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { Color color; Graphics paper = pictureBoxshow.CreateGraphics(); if (radioButtonCircle.Checked) { r = radioButtonCircle; string circle = radioButtonCircle.Text; if (radioButtonRed.Checked) { color = Color.Red; } else if (radioButtonGreen.Checked) { color = Color.Green; } else { color = Color.Blue; } if (radioButtonother.Checked) { if (colorDialog1.ShowDialog() == DialogResult.OK) { color = colorDialog1.Color; } } } else if (radioButtonsquare.Checked) { r = radioButtonsquare; string square = radioButtonsquare.Text; if (radioButtonRed.Checked) { color = Color.Red; } else if (radioButtonGreen.Checked) { color = Color.Green; } else { color = Color.Blue; } if (radioButtonother.Checked) { if (colorDialog1.ShowDialog() == DialogResult.OK) { color = colorDialog1.Color; } } } else { r = radioButtontriangle; string triangle = radioButtontriangle.Text; if (radioButtonRed.Checked) { color = Color.Red; } else if (radioButtonGreen.Checked) { color = Color.Green; } else { color = Color.Blue; } if (radioButtonother.Checked) { if (colorDialog1.ShowDialog() == DialogResult.OK) { color = colorDialog1.Color; } } paper.Dispose(); int a = Convert.ToInt32(paper.DpiX); int b = Convert.ToInt32(paper.DpiY); Shape shapeselect = new Shape(a, b, trackBarsize.Value, trackBarsize.Value, color); shapeselect.Draw(paper, r.Text);仍然不可实现阿??为什么呢??
也就是说,我还需要加一个rivate void pictureBox1_Click(object sender, EventArgs e) ??? 把int a = Convert.ToInt32(paper.DpiX); int b = Convert.ToInt32(paper.DpiY) 换成了 int a = Convert.ToInt32(e.X); int b = Convert.ToInt32(e.Y ); 为什么还不行呢???(太谢谢你了)
朋友们帮帮忙吧,我明天要把project呈上的5555555555555555
paper.Dispose(); //这行应该在后面吧? int a = Convert.ToInt32(paper.DpiX); int b = Convert.ToInt32(paper.DpiY); Shape shapeselect = new Shape(a, b, trackBarsize.Value, trackBarsize.Value, color); shapeselect.Draw(paper, r.Text);//shapeselect没有显示吧
private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { Color color; Graphics paper = pictureBoxshow.CreateGraphics(); if (radioButtonCircle.Checked) { r = radioButtonCircle; string circle = radioButtonCircle.Text; if (radioButtonRed.Checked) { color = Color.Red; } else if (radioButtonGreen.Checked) { color = Color.Green; } else { color = Color.Blue; } if (radioButtonother.Checked) { if (colorDialog1.ShowDialog() == DialogResult.OK) { color = colorDialog1.Color; } } } else if (radioButtonsquare.Checked) { r = radioButtonsquare; string square = radioButtonsquare.Text; if (radioButtonRed.Checked) { color = Color.Red; } else if (radioButtonGreen.Checked) { color = Color.Green; } else { color = Color.Blue; } if (radioButtonother.Checked) { if (colorDialog1.ShowDialog() == DialogResult.OK) { color = colorDialog1.Color; } } } else { r = radioButtontriangle; string triangle = radioButtontriangle.Text; if (radioButtonRed.Checked) { color = Color.Red; } else if (radioButtonGreen.Checked) { color = Color.Green; } else { color = Color.Blue; } if (radioButtonother.Checked) { if (colorDialog1.ShowDialog() == DialogResult.OK) { color = colorDialog1.Color; } }
int a = Convert.ToInt32(e.X); int b = Convert.ToInt32(e.Y ); Shape shapeselect = new Shape(a,b, trackBarsize.Value, trackBarsize.Value, color); shapeselect.Draw(paper, r.Text); paper.Dispose(); 我移到后面了,可是,picturebox照样雷打不动的不给我在鼠标点位置显示shape ~~!
就我前面那一大串的if statement的情况,在后面写code去画shape不应该这样写吗??
Shape shapeselect = new Shape(a, b, trackBarsize.Value, trackBarsize.Value, color); 是wpf程序?
Shape shapeselect = new Shape(a,b, trackBarsize.Value, trackBarsize.Value, color); shapeselect.Draw(paper, r.Text); 替换成 paper.DrawString(new Pen(r.Text, new Font("Arial", 16), new SolidBrush(color), new PointF(a, b));
Error 1 'System.Drawing.Pen' does not contain a constructor that takes '4' arguments \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 34 WindowsFormsApplication2 Error 2 No overload for method 'DrawString' takes '1' arguments \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 17 WindowsFormsApplication2
paper.DrawString(new Pen(r.Text), new Font("Arial", 16), new SolidBrush(color), new PointF(a, b));
Error 1 Unexpected character ')' \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 48 WindowsFormsApplication2 Error 2 The best overloaded method match for 'System.Drawing.Pen.Pen(System.Drawing.Brush)' has some invalid arguments \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 34 WindowsFormsApplication2 Error 3 Argument '1': cannot convert from 'string' to 'System.Drawing.Brush' \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 42 WindowsFormsApplication2 Error 4 No overload for method 'DrawString' takes '1' arguments \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 17 WindowsFormsApplication2 Error 5 Only assignment, call, increment, decrement, and new object expressions can be used as a statement \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 44 WindowsFormsApplication2 Error 6 Only assignment, call, increment, decrement, and new object expressions can be used as a statement \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 48 WindowsFormsApplication2 Error 7 Only assignment, call, increment, decrement, and new object expressions can be used as a statement \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 71 WindowsFormsApplication2 Error 8 Only assignment, call, increment, decrement, and new object expressions can be used as a statement \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 94 WindowsFormsApplication2 Error 9 Only assignment, call, increment, decrement, and new object expressions can be used as a statement \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 112 WindowsFormsApplication2 Error 10 Invalid expression term '' \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 48 WindowsFormsApplication2 Error 11 ) expected \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 48 WindowsFormsApplication2 Error 12 Invalid expression term ',' \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 49 WindowsFormsApplication2 Error 13 ; expected \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 49 WindowsFormsApplication2 Error 14 ; expected \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 51 WindowsFormsApplication2 Error 15 Invalid expression term ',' \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 72 WindowsFormsApplication2 Error 16 ; expected \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 72 WindowsFormsApplication2 Error 17 ; expected \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 74 WindowsFormsApplication2 Error 18 Invalid expression term ',' \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 95 WindowsFormsApplication2 Error 19 ; expected \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 95 WindowsFormsApplication2 Error 20 ; expected \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 97 WindowsFormsApplication2 Error 21 Invalid expression term ')' \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 113 WindowsFormsApplication2 Error 22 ; expected \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 113 WindowsFormsApplication2
这是我做的例子,在Form1中拖入一个pictureBox,并指定其MouseDown事件处理程序: public partial class Form1 : Form { Bitmap bt = new Bitmap(@"c:\1.jpg"); public Form1() { InitializeComponent(); } private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { Graphics g = pictureBox1.CreateGraphics(); int a = 100, b = 10; g.DrawString(Text, new Font("Arial", 16), new SolidBrush(Color.FromArgb(0, 255, 0)), new PointF(e.X, e.Y));//写字 //g.DrawImage(bt, e.Location);//画图 g.Dispose(); } }
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
Graphics g = pictureBox1.CreateGraphics();
g.DrawImage(bt, e.Location);
g.Dispose(); }
{
Color color;
Graphics paper = pictureBoxshow.CreateGraphics(); if (radioButtonCircle.Checked)
{
r = radioButtonCircle;
string circle = radioButtonCircle.Text;
if (radioButtonRed.Checked)
{
color = Color.Red;
}
else if (radioButtonGreen.Checked)
{
color = Color.Green;
}
else
{
color = Color.Blue;
}
if (radioButtonother.Checked)
{ if (colorDialog1.ShowDialog() == DialogResult.OK)
{
color = colorDialog1.Color;
} }
}
else if (radioButtonsquare.Checked)
{
r = radioButtonsquare;
string square = radioButtonsquare.Text;
if (radioButtonRed.Checked)
{
color = Color.Red;
}
else if (radioButtonGreen.Checked)
{
color = Color.Green;
}
else
{
color = Color.Blue;
}
if (radioButtonother.Checked)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
color = colorDialog1.Color;
}
} }
else
{
r = radioButtontriangle;
string triangle = radioButtontriangle.Text;
if (radioButtonRed.Checked)
{
color = Color.Red; }
else if (radioButtonGreen.Checked)
{
color = Color.Green;
}
else
{
color = Color.Blue;
}
if (radioButtonother.Checked)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
color = colorDialog1.Color;
} }
paper.Dispose();
int a = Convert.ToInt32(paper.DpiX);
int b = Convert.ToInt32(paper.DpiY);
Shape shapeselect = new Shape(a, b, trackBarsize.Value, trackBarsize.Value, color);
shapeselect.Draw(paper, r.Text);仍然不可实现阿??为什么呢??
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
MouseEventArgs e中包含坐标信息。
把int a = Convert.ToInt32(paper.DpiX);
int b = Convert.ToInt32(paper.DpiY)
换成了 int a = Convert.ToInt32(e.X);
int b = Convert.ToInt32(e.Y );
为什么还不行呢???(太谢谢你了)
int a = Convert.ToInt32(paper.DpiX);
int b = Convert.ToInt32(paper.DpiY);
Shape shapeselect = new Shape(a, b, trackBarsize.Value, trackBarsize.Value, color);
shapeselect.Draw(paper, r.Text);//shapeselect没有显示吧
private void pictureBox1_Click(object sender, EventArgs e)这行不需要。
{
Color color;
Graphics paper = pictureBoxshow.CreateGraphics(); if (radioButtonCircle.Checked)
{
r = radioButtonCircle;
string circle = radioButtonCircle.Text;
if (radioButtonRed.Checked)
{
color = Color.Red;
}
else if (radioButtonGreen.Checked)
{
color = Color.Green;
}
else
{
color = Color.Blue;
}
if (radioButtonother.Checked)
{ if (colorDialog1.ShowDialog() == DialogResult.OK)
{
color = colorDialog1.Color;
} }
}
else if (radioButtonsquare.Checked)
{
r = radioButtonsquare;
string square = radioButtonsquare.Text;
if (radioButtonRed.Checked)
{
color = Color.Red;
}
else if (radioButtonGreen.Checked)
{
color = Color.Green;
}
else
{
color = Color.Blue;
}
if (radioButtonother.Checked)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
color = colorDialog1.Color;
}
} }
else
{
r = radioButtontriangle;
string triangle = radioButtontriangle.Text;
if (radioButtonRed.Checked)
{
color = Color.Red; }
else if (radioButtonGreen.Checked)
{
color = Color.Green;
}
else
{
color = Color.Blue;
}
if (radioButtonother.Checked)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
color = colorDialog1.Color;
} }
int a = Convert.ToInt32(e.X);
int b = Convert.ToInt32(e.Y );
Shape shapeselect = new Shape(a,b, trackBarsize.Value, trackBarsize.Value, color);
shapeselect.Draw(paper, r.Text);
paper.Dispose();
我移到后面了,可是,picturebox照样雷打不动的不给我在鼠标点位置显示shape ~~!
是wpf程序?
shapeselect.Draw(paper, r.Text);
替换成
paper.DrawString(new Pen(r.Text, new Font("Arial", 16), new SolidBrush(color), new PointF(a, b));
Error 2 No overload for method 'DrawString' takes '1' arguments \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 17 WindowsFormsApplication2
Error 2 The best overloaded method match for 'System.Drawing.Pen.Pen(System.Drawing.Brush)' has some invalid arguments \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 34 WindowsFormsApplication2
Error 3 Argument '1': cannot convert from 'string' to 'System.Drawing.Brush' \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 42 WindowsFormsApplication2
Error 4 No overload for method 'DrawString' takes '1' arguments \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 17 WindowsFormsApplication2
Error 5 Only assignment, call, increment, decrement, and new object expressions can be used as a statement \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 44 WindowsFormsApplication2
Error 6 Only assignment, call, increment, decrement, and new object expressions can be used as a statement \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 48 WindowsFormsApplication2
Error 7 Only assignment, call, increment, decrement, and new object expressions can be used as a statement \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 71 WindowsFormsApplication2
Error 8 Only assignment, call, increment, decrement, and new object expressions can be used as a statement \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 94 WindowsFormsApplication2
Error 9 Only assignment, call, increment, decrement, and new object expressions can be used as a statement \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 112 WindowsFormsApplication2
Error 10 Invalid expression term '' \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 48 WindowsFormsApplication2
Error 11 ) expected \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 48 WindowsFormsApplication2
Error 12 Invalid expression term ',' \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 49 WindowsFormsApplication2
Error 13 ; expected \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 49 WindowsFormsApplication2
Error 14 ; expected \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 51 WindowsFormsApplication2
Error 15 Invalid expression term ',' \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 72 WindowsFormsApplication2
Error 16 ; expected \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 72 WindowsFormsApplication2
Error 17 ; expected \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 74 WindowsFormsApplication2
Error 18 Invalid expression term ',' \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 95 WindowsFormsApplication2
Error 19 ; expected \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 95 WindowsFormsApplication2
Error 20 ; expected \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 97 WindowsFormsApplication2
Error 21 Invalid expression term ')' \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 113 WindowsFormsApplication2
Error 22 ; expected \\oslo.scms.waikato.ac.nz\home\fz48\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 424 113 WindowsFormsApplication2
public partial class Form1 : Form
{
Bitmap bt = new Bitmap(@"c:\1.jpg");
public Form1()
{
InitializeComponent();
} private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
Graphics g = pictureBox1.CreateGraphics();
int a = 100, b = 10;
g.DrawString(Text, new Font("Arial", 16), new SolidBrush(Color.FromArgb(0, 255, 0)), new PointF(e.X, e.Y));//写字
//g.DrawImage(bt, e.Location);//画图
g.Dispose();
}
}
而且 我的r= radiobutton 称之为 "cicle"
所以,r.text=circle,
所以会判别shape=circle执行画圆
shapeselect.Draw里面怎么写的?
shape.Draw(paper, r.Text);这个市我的随即draw
{
Shape shape = new Shape(MousePosition .X - pictureBoxshow.Width, MousePosition .Y - pictureBoxshow .Height , trackBarsize.Value, trackBarsize.Value, color);
shape.Draw(paper, r.Text);我通过这个 倒是可以在picturebox画图了,但是。图的位置总有偏差。。如果我写成Shape shape = new Shape(MousePosition .X , MousePosition .Y , trackBarsize.Value, trackBarsize.Value, color);就 什么都划不出来了。。
Shape shape = new Shape(e.X, e.Y, trackBarsize.Value, trackBarsize.Value, color);
shape.Draw(paper, r.Text);
就这么一句话+
private void pictureBoxshow_MouseClick(object sender, MouseEventArgs e)
我从早上8点到实验室一直折腾到下午5点。。太感谢了!!!!!!!!!!0210549147我的qq 太谢谢大哥了!!!!!!看来这个课程不会挂掉了~~这个课程的fail率至少60%。