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