none
还是visual Basic 2008绘图问题 RRS feed

  • 问题

  • 窗体上有picturebox控件一个,button控件一个,当按钮按下时,调用一个Sub开始在picturebox里时时绘图,当窗体改变的时候,怎样保持图形?其中Draw_PIC,假设就是绘图子程序。

    Public Class Form1

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            With PictureBox1
                .SetBounds(10, 10, 500, 500)
            End With
            With Button1
                .SetBounds(450, 510, 50, 30)
            End With
        End Sub

        Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Call Draw_PIC(PictureBox1)
        End Sub


        Private Sub Draw_PIC(ByVal Para As Object)
            Para.CreateGraphics.DrawLine(Pens.Red, 100, 100, 200, 200)
        End Sub

    End Class

    2011年4月28日 14:12

答案

  • 您好

    請在 Form_Paint 進行重繪

    http://msdn.microsoft.com/zh-tw/library/3e40ahaz(v=vs.80).aspx

    Public Class Form1

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            With PictureBox1
                .SetBounds(10, 10, 500, 500)
            End With
            With Button1
                .SetBounds(450, 510, 50, 30)
            End With
        End Sub

        Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Call Draw_PIC(PictureBox1)
        End Sub


        Private Sub Draw_PIC(ByVal Para As Object)
            Para.CreateGraphics.DrawLine(Pens.Red, 100, 100, 200, 200)
        End Sub

        Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
            Call Draw_PIC(PictureBox1)
        End Sub
    End Class

     


    歡迎參觀我的Blog.NET菜鳥自救會
    2011年4月29日 2:34

全部回复

  • 您好

    請在 Form_Paint 進行重繪

    http://msdn.microsoft.com/zh-tw/library/3e40ahaz(v=vs.80).aspx

    Public Class Form1

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            With PictureBox1
                .SetBounds(10, 10, 500, 500)
            End With
            With Button1
                .SetBounds(450, 510, 50, 30)
            End With
        End Sub

        Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Call Draw_PIC(PictureBox1)
        End Sub


        Private Sub Draw_PIC(ByVal Para As Object)
            Para.CreateGraphics.DrawLine(Pens.Red, 100, 100, 200, 200)
        End Sub

        Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
            Call Draw_PIC(PictureBox1)
        End Sub
    End Class

     


    歡迎參觀我的Blog.NET菜鳥自救會
    2011年4月29日 2:34
  • Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
            Call Draw_PIC(PictureBox1)

        End Sub
    这样的话,窗体一完成就会执行,又得加一个变量判断是否按钮已按过?在vb2008里面,画图什么的,都那么费劲么?较之VB6。有什么可以参考的啊?画图这块


    2011年4月30日 14:04