C#中paintbox 的paint事件
privatevoidpictureBox1_Paint(objectsender,PaintEventArgse){Graphicsp=this.pictureBox1...
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics p = this.pictureBox1.CreateGraphics();
Pen myPenp = new Pen(Color.Black, 1);
myPenp.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
p.DrawLine(myPenp, 0, 0, 100, 200);
}
希望程序一启动,picturebox上就有坐标线,但是这样不行,paint事件到底是怎么一回事儿哦??? 展开
{
Graphics p = this.pictureBox1.CreateGraphics();
Pen myPenp = new Pen(Color.Black, 1);
myPenp.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
p.DrawLine(myPenp, 0, 0, 100, 200);
}
希望程序一启动,picturebox上就有坐标线,但是这样不行,paint事件到底是怎么一回事儿哦??? 展开
2个回答
展开全部
是你自己写错了,在Paint事件里还用CreateGraphics,你用该用e.Graphics,而不是再创建一个。你那样写当然会画出来立即消失。
Graphics p = e.Graphics;
Pen myPenp = new Pen(Color.Black, 1);
myPenp.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
p.DrawLine(myPenp, 0, 0, 100, 200);
Graphics p = e.Graphics;
Pen myPenp = new Pen(Color.Black, 1);
myPenp.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
p.DrawLine(myPenp, 0, 0, 100, 200);
展开全部
e) 如果想在窗体中使用这个事件就把类中事件前的Private关键字改成Public如:
Public Sub PicCurve_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PicCurve.Paint
在窗体中调用的方法就是实例化类就行了。因为这个类有NEW所以在实例化的时候要赋参数
代码如下数值是我临时写的。调用的时候你根据实际情况改一下就行。参数PictureBox1是在窗体上添加的PictureBox控件。
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim AA() As Single =
Dim clsPaint As New bbbb(PictureBox1, AA, "PictureBox_1")
clsPaint.PicCurve_Paint(Me, Nothing)
End Sub
Public Sub PicCurve_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PicCurve.Paint
在窗体中调用的方法就是实例化类就行了。因为这个类有NEW所以在实例化的时候要赋参数
代码如下数值是我临时写的。调用的时候你根据实际情况改一下就行。参数PictureBox1是在窗体上添加的PictureBox控件。
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim AA() As Single =
Dim clsPaint As New bbbb(PictureBox1, AA, "PictureBox_1")
clsPaint.PicCurve_Paint(Me, Nothing)
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询