c#程序没有错误,为什么在picturebox中显示不出来画的东西啊,是鼠标事件没有发挥作用吗?
privatevoidpictureBox1_MouseDown(objectsender,MouseEventArgse){pictureBox1.Refresh();...
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
pictureBox1.Refresh();
Pen mypen = new Pen(Color.Red, 6);//画笔
Point pShebei = new Point(0, 0);
Graphics g = pictureBox1.CreateGraphics();//画图
Brush redBrush = Brushes.Red;
Font songti = new Font("宋体", 14);
startpoint.X = MousePosition.X - 270;
startpoint.Y = MousePosition.Y - 28;
int realheng = MousePosition.X - 270;
int realshu = MousePosition.Y - 28;
g.DrawString("" + "▼" + "", songti, redBrush, new Rectangle(new Point(startpoint.X - 4, startpoint.Y - 46), new Size(50, 50))); 展开
{
pictureBox1.Refresh();
Pen mypen = new Pen(Color.Red, 6);//画笔
Point pShebei = new Point(0, 0);
Graphics g = pictureBox1.CreateGraphics();//画图
Brush redBrush = Brushes.Red;
Font songti = new Font("宋体", 14);
startpoint.X = MousePosition.X - 270;
startpoint.Y = MousePosition.Y - 28;
int realheng = MousePosition.X - 270;
int realshu = MousePosition.Y - 28;
g.DrawString("" + "▼" + "", songti, redBrush, new Rectangle(new Point(startpoint.X - 4, startpoint.Y - 46), new Size(50, 50))); 展开
3个回答
展开全部
鼠标事件起作用了。你没有看到那个“▼”的原因是:当pictureBox1刷新时,将画出的内容又“清空”了。改成这样的试试:
//pictureBox1的Pain事件
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Pen mypen = new Pen(Color.Red, 6);//画笔
Point pShebei = new Point(0, 0);
//直接从事件参数e获取 Graphics
Graphics g = e.Graphics;
Brush redBrush = Brushes.Red;
Font songti = new Font("宋体", 14);
Point startpoint = new Point();
startpoint.X = p.X - 270;
startpoint.Y = p.Y - 28;
int realheng = p.X - 270;
int realshu = p.Y - 28;
g.DrawString("" + "▼" + "", songti, redBrush, new Rectangle(new Point(startpoint.X - 4, startpoint.Y - 46), new Size(50, 50)));
}
Point p = Point.Empty; //记录鼠标的位置
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
p = MousePosition;
//引发pictureBox1的Paint事件!
pictureBox1.Invalidate();
}
追问
能加个好友吗?交我编编程序啊,感觉毕不了业了。其实这个程序如果只有一个picturebox的时候可以画出来,但如果把picturebox放到tabcontrol或者旁边在picturebox左边加一个gradview又画不出来了 不知道什么情况
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
private Bitmap CreateImage()
{
Bitmap img=new Bitmap(this.pictureBox1.Width,this.pictureBox1.Height);
Graphics g = Graphics.FromImage(img);
Pen mypen = new Pen(Color.Red, 6);//画笔
Brush redBrush = Brushes.Red;
Font songti = new Font("宋体", 14);
Point mousepoint= MousePosition;
Point startpoint = new Point(0,0);
Point contorlpoint = PointToScreen(this.pictureBox1.Location);
startpoint.X = mousepoint.X - contorlpoint.X-14;
startpoint.Y = mousepoint.Y - contorlpoint.Y-7;
g.DrawString("" + "▼" + "", songti, redBrush, new Rectangle(startpoint, new Size(50, 50)));
return img;
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
this.pictureBox1.Image = CreateImage();
this.pictureBox1.Refresh();
}
{
Bitmap img=new Bitmap(this.pictureBox1.Width,this.pictureBox1.Height);
Graphics g = Graphics.FromImage(img);
Pen mypen = new Pen(Color.Red, 6);//画笔
Brush redBrush = Brushes.Red;
Font songti = new Font("宋体", 14);
Point mousepoint= MousePosition;
Point startpoint = new Point(0,0);
Point contorlpoint = PointToScreen(this.pictureBox1.Location);
startpoint.X = mousepoint.X - contorlpoint.X-14;
startpoint.Y = mousepoint.Y - contorlpoint.Y-7;
g.DrawString("" + "▼" + "", songti, redBrush, new Rectangle(startpoint, new Size(50, 50)));
return img;
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
this.pictureBox1.Image = CreateImage();
this.pictureBox1.Refresh();
}
追问
你的能显示出来吗? 我怎么还是显示不了啊
追答
你的是不是在panel里面写的 调试下就知道了,估计是没触发到pictureBox1_MouseDown事件,而是触发到了panel的MouseDown的事件了,解决办法有两个:一是放出来 不要把pictureBox1放在容器里,二是在放置pictureBox1的容器的MouseDown里面设置pictureBox1_MouseDown一样的内容。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你是想实现什么样的功能?
追问
就是鼠标点一下,在图片上显示那个倒三角符号
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询