问题描述
想着点一下左键,drawstring画出鼠标的坐标privatevoidpictureBox1_MouseClick(objectsender,MouseEventArgse){g.DrawString("X:"+xSignal.ToString(),newFont("宋体",10),newSolidBrush(Color.Red),e.X,e.Y);}是不是需要重绘啊,具体要怎么做。this.Invalidate(true);
解决方案
解决方案二:
privatevoidpictureBox1_MouseClick(objectsender,MouseEventArgse){Graphicsg=pictureBox1.CreateGraphics();g.Clear(Color.White);g.DrawString("X:"+e.X.ToString()+"Y"+e.Y.ToString(),newFont("宋体",10),newSolidBrush(Color.Red),e.X,e.Y);}这样就可以如果不要先前鼠标点击的位置就不用g.Clear(Color.White);
解决方案三:
引用1楼的回复:
privatevoidpictureBox1_MouseClick(objectsender,MouseEventArgse){Graphicsg=pictureBox1.CreateGraphics();g.Clear(Color.White);g.DrawString("……
e.X应该是一个double类型的吧,,要是想截取小数的3位,该怎么转换。。貌似C#的类型转换搞的挺复杂的。。变量前面加(类型),convert.to...变量.tostring...这些个有啥区别咧。
解决方案四:
对了,,convert.toFloat这个为啥没有呢
解决方案五:
privatevoidpictureBox1_MouseClick(objectsender,MouseEventArgse){Graphicsg=Graphics.FromHwnd(pictureBox1.Handle);g.DrawString("X:我很好",newFont("宋体",10),newSolidBrush(Color.Red),e.X,e.Y);}
解决方案六:
你这样画出的文字当界面最小化再最大化就消失了,最好的办法还是,找一张画布,在画布上绘制文字,然后在picturebox的Piant时间中将画布绘制到picturerbox上面
解决方案七:
publicForm1(){InitializeComponent();bmp=newBitmap(pictureBox1.Width,pictureBox1.Height);g=Graphics.FromImage(bmp);}Bitmapbmp;Graphicsg;privatevoidpictureBox1_MouseClick(objectsender,MouseEventArgse){g.DrawString("X:"+e.X,newFont("宋体",10),newSolidBrush(Color.Red),e.X,e.Y);pictureBox1.Refresh();}privatevoidpictureBox1_Paint(objectsender,PaintEventArgse){Graphicsg=e.Graphics;g.DrawImage(bmp,newPoint(0,0));}