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

感谢CSDN!图像重画,已经解决!贴上源码!该怎么处理

2012-02-20 
感谢CSDN!图像重画,已经解决!贴上源码!郁闷了一个下午,终于解决了多次重画图形问题!感谢:dylike、bw555、yan

感谢CSDN!图像重画,已经解决!贴上源码!
郁闷了一个下午,终于解决了多次重画图形问题!
感谢:dylike、bw555、yanlongwuhui、keenweiwei
更感谢CSDN
下面是我用bitmap解决画图闪烁,用数组解决重画的源码(只画直线):

VB.NET code
Public Class Form1    Dim Bmp1 As Bitmap    Dim IsDown As Boolean = False    Dim myPen As New Pen(Color.GreenYellow, 2)    Dim arrayLine(,) As Point    Dim pLine1, pLine2 As Point    Dim countLine, countRect, countEillpse As Integer    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown        IsDown = True        pLine1.X = e.X        pLine1.Y = e.Y    End Sub    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove        If IsDown Then            Dim gbmp As Graphics = Graphics.FromImage(Bmp1)            pLine2.X = e.X            pLine2.Y = e.Y            gbmp.Clear(Color.Gainsboro)            Dim i As Integer            If countLine <> 0 Then                For i = 0 To countLine                    gbmp.DrawLine(myPen, arrayLine(1, i).X, arrayLine(1, i).Y, arrayLine(2, i).X, arrayLine(2, i).Y)                Next            End If            gbmp.DrawLine(myPen, pLine1.X, pLine1.Y, pLine2.X, pLine2.Y)            Me.CreateGraphics.DrawImage(Bmp1, 0, 0)        End If    End Sub    Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp        IsDown = False        countLine += 1        ReDim Preserve arrayLine(2, countLine)        arrayLine(1, countLine) = pLine1        arrayLine(2, countLine) = pLine2    End Sub    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load        Bmp1 = New Bitmap(Me.Size.Width, Me.Size.Height)        countLine = 0    End SubEnd Class


[解决办法]
看看
[解决办法]
收藏看看
[解决办法]
学习
[解决办法]
看看,顶
[解决办法]
呵呵
[解决办法]
来学习
[解决办法]
收藏,学习
[解决办法]
学习

收藏之
[解决办法]
不错
[解决办法]
vb...
[解决办法]
感谢分享.

建议:全局变量不要用Dim来定义,在这份代码里,用Private好些.
代码没有考虑到程序界面切换的处理,比如界面最小化再激活.

可以作为示例代码,推荐.
[解决办法]
没有做好即时资源释放.这样会导致狂吃内存,而且只上不下.

热点排行