毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> net技术 >> 正文

System.ArgumentException Message=参数无效

更新时间:2014-6-7:  来源:毕业论文

Sub validatecode(ByVal vnum)
        Dim img As System.drawing.Bitmap
        Dim g As Graphics
        Dim r As Random = New Random
        Dim gheight As Integer = Int(Len(vnum) * 13)
        'gheight为图片宽度, 根据字符长度自动更改图片宽度
 
        img = New Bitmap(gheight, 20)
        g = Graphics.FromImage(img)
        g.DrawString(vnum, New System.Drawing.Font("Arial", 10), New System.Drawing.SolidBrush(Color.Blue), 3, 3)
        '新增,修改、画图片的背景噪音线
 
        For i As Integer = 0 To 10
            Dim x1 As Integer
            x1 = r.Next(img.Width)
            Dim x2 As Integer =r.Next(img.Width)
            Dim y1 As Integer =r.Next(img.Height)
            Dim y2 As Integer =r.Next(img.Height)
            g.DrawLine(New Pen(Color.Silver),x1, y1, x2, y2)
        Next i
        Dim font As Font
        font = New System.Drawing.Font("Arial", 12)
        Dim brush As System.Drawing.
        Drawing2D.LinearGradientBrush
        brush = New System.Drawing.Drawing2D.LinearGradientBrush(New Rectangle(0, 0, img.Width, img.Height), Color.Blue, Color.Blue, 1.2F, True)
        g.DrawString(vnum, font, brush, 2, 2)
        'VB.NET生成验证码中画图片的前景噪音点()
 
        For ii As Integer = 0 To 100
            Dim x As Integer = r.Next(img.Width)
            Dim y As Integer = r.Next(img.Height)
            img.SetPixel(x, y, Color.FromArgb(r.Next()))
        Next
        '画图片的边框线()
 
        g.DrawRectangle(New Pen(Color.Silver),0, 0, img.Width - 1,img.Height - 1)
        '在矩形内绘制字串(字串, 字体, 画笔颜色, 左上x.左上y)
 
        PictureBox1.Image = img
        PictureBox1.Refresh()
        g.Dispose()
        img.Dispose()
 
    End Sub


在最后那个picturebox1.image=img时报错,去掉这行,则通过.

未处理 System.ArgumentException
  Message=参数无效。
  Source=System.Drawing
  StackTrace:
       在 System.Drawing.Image.get_Width()
       在 System.Drawing.Image.get_Size()
       在 System.Windows.Forms.PictureBox.ImageRectangleFromSizeMode(PictureBoxSizeMode mode)
       在 System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
       在 System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
       在 System.Windows.Forms.Control.WmPaint(Message& m)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.Run(ApplicationContext context)
       在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       在 验证码.My.MyApplication.Main(String[] Args) 位置 17d14f5c-a337-4978-8281-53493378c1071.vb:行号 81
       在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ThreadHelper.ThreadStart()
  InnerException:
宽度和高度设置的多少,是不是<=0或者太大。 PictureBox1.Image = img
        PictureBox1.Refresh()
        g.Dispose()
        img.Dispose()  <---这里都dispose掉了当然报错了.

 PictureBox1.Image = img 改成
PictureBox1.Image=New Bitmap(img)

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。