VB6中的PictureBox控件的有AutoRedraw属性,设置为True,则窗口最小化或被覆盖后重新打开窗口,原来的图形还在(使用Line等函数画的图形),但VB.NET没有了这个属性,为此烦了好久,MSDN上也没有找到明确的代用方法,上星期去书店翻了翻,终于明白怎么会事.
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim Bmp As Bitmap Dim Gra As Graphics Dim Pen As New Pen(Color.White) Bmp = New Bitmap(PictureBox1.Width, PictureBox1.Height) Gra = Graphics.FromImage(Bmp) Dim Dia As Single = Math.Min(PictureBox1.Height, PictureBox1.Width) * 0.5! Gra.DrawArc(Pen, (PictureBox1.Width - Dia) / 2.0!, (PictureBox1.Height - Dia) / 2.0!, Dia, Dia, 0, 360) Gra.DrawLine(Pen, 0, 0, PictureBox1.Width / 2.0!, PictureBox1.Height / 2.0!) PictureBox1.Image = Bmp End Sub
上面代码画的图形在最小化后重新打开图形还在,下面的则没有了.
Private Sub PictureBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.DoubleClick Dim Gra As Graphics = PictureBox1.CreateGraphics() Dim Pen As New Pen(Color.Magenta) Dim Dia As Single = Math.Min(PictureBox1.Height, PictureBox1.Width) * 0.5! Gra.DrawRectangle(Pen, (PictureBox1.Width - Dia) / 2.0!, (PictureBox1.Height - Dia) / 2.0!, Dia, Dia) End Sub |