首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

如何处理通过后台代码在picturebox中画的内容被遮挡后消失?怎么将picturebox中内容保存成图片

2012-12-16 
如何避免通过后台代码在picturebox中画的内容被遮挡后消失?如何将picturebox中内容保存成图片? Dim i As I

如何避免通过后台代码在picturebox中画的内容被遮挡后消失?如何将picturebox中内容保存成图片?
 Dim i As Integer = 0
            Dim MyGraphics As Graphics = Me.PictureBox2.CreateGraphics
            Dim MyGraphicsP2 As Graphics = Me.P2.CreateGraphics
            Dim MyBrush As New SolidBrush(Color.Red)
            Dim MyProportion As Single
            Dim MyRect As New Rectangle
            Dim MyPoint As New PointF
            Dim R As Single
            Dim arrValues(1) As Integer
            arrValues(0) = Qty
            arrValues(1) = mBad
            Dim arrValueNames(1) As String
            arrValueNames(0) = "总计:" + arrValues(0).ToString
            arrValueNames(1) = "不满意:" + arrValues(1).ToString
            MyGraphics.Clear(Me.PictureBox2.BackColor)
            MyGraphicsP2.Clear(Me.P2.BackColor)
            Dim MyStartAngel As Double
            Dim MySweepAngel As Double

            R = Math.Min(Me.PictureBox2.Width, Me.PictureBox2.Height) / 2 - 15
            MyPoint.X = Me.PictureBox2.Width / 2
            MyPoint.Y = Me.PictureBox2.Height / 2
            MyRect.X = MyPoint.X - R
            MyRect.Y = MyPoint.Y - R
            MyRect.Width = R * 2
            MyRect.Height = R * 2

            MyStartAngel = 0
            MyProportion = mBad / Qty
            MySweepAngel = 360 * MyProportion
            MyBrush.Color = Color.Red
            MyGraphics.FillPie(MyBrush, MyRect, MyStartAngel, MySweepAngel)

            MyStartAngel = MyStartAngel + MySweepAngel
            MyProportion = (Qty - mBad) / Qty


            MySweepAngel = 360 * MyProportion
            MyBrush.Color = Color.Blue
            MyGraphics.FillPie(MyBrush, MyRect, MyStartAngel, MySweepAngel)
            Dim mW As Integer = Panel2.Width / 15
            Dim mH As Integer = Panel2.Height / 40
            Dim symbolLeg As PointF = New PointF(1, 10)
            Dim descLeg As PointF = New PointF(mW + 1, 10)

            For i = 0 To arrValueNames.Length - 1
                MyGraphicsP2.FillRectangle(New SolidBrush(GetColor(i)), symbolLeg.X, symbolLeg.Y, mW, mH)
                MyGraphicsP2.DrawRectangle(Pens.Black, symbolLeg.X, symbolLeg.Y, mW, mH)

                MyGraphicsP2.DrawString(arrValueNames(i).ToString, New Font("宋体", 8 * Me.Width / x, FontStyle.Bold), Brushes.Navy, descLeg)
                symbolLeg.Y += 35
                descLeg.Y += 35
            Next
[最优解释]
避免在paint中直接绘制picturebox的graphic,而是绘制到内存中的bitmap对象。

然后paint事件加载这个内存图片。
[其他解释]
在OnPaint事件中绘制,不会被遮挡
如果想保存图像,你可以new一个bitmap,然后在bitmap上画图,画好后,将bitmap作为picture的底图,你可以保存bitmap,而且这样做,你可以控制要重回的时机,不用考虑被遮挡的问题
[其他解释]
最好给点代码提示,我在这方面是菜鸟,谢谢
[其他解释]
谢谢 我试下

引用:
在OnPaint事件中绘制,不会被遮挡
如果想保存图像,你可以new一个bitmap,然后在bitmap上画图,画好后,将bitmap作为picture的底图,你可以保存bitmap,而且这样做,你可以控制要重回的时机,不用考虑被遮挡的问题

[其他解释]
能不能给代码提示,Onpaint不会用啊

热点排行