Results 1 to 2 of 2

Thread: [RESOLVED] picturebox problem

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2010
    Posts
    46

    Resolved [RESOLVED] picturebox problem

    I have this code which creates a picturebox during runtime and displays line graph but I always get an error in this line:

    gr1.DrawImage(pic1.Image, -m_Dx, 0) 'it says Value cannot be null. Parameter name: image

    code Code:
    1. Public Class Form1
    2.     Private Const m_Dx As Single = 1
    3.     Dim data As Integer = 1
    4.  
    5.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    6.         Dim pic1 As New PictureBox
    7.         pic1.Location = New Point(12, 12)
    8.         pic1.Name = "pic1"
    9.         pic1.Width = 142
    10.         pic1.Height = 102
    11.         pic1.Visible = True
    12.         pic1.BackColor = Color.Black
    13.         pic1.BorderStyle = BorderStyle.Fixed3D
    14.  
    15.         Controls.Add(pic1)
    16.  
    17.         Dim bm1 As New Bitmap(pic1.Width, pic1.Height)
    18.         Dim gr1 As Graphics = Graphics.FromImage(bm1)
    19.         gr1.DrawImage(pic1.Image, -m_Dx, 0)
    20.  
    21.         gr1.ScaleTransform(1, -101 / pic1.Height)
    22.         gr1.TranslateTransform(0, -101)
    23.  
    24.         Dim new_value1 As Integer = Val(data) / 2
    25.  
    26.         If new_value1 < 1 Then new_value1 = 1
    27.         gr1.DrawLine(Pens.Blue, _
    28.             pic1.Width - 1, 0, _
    29.             pic1.Width - 1, new_value1)
    30.  
    31.         For i As Integer = 20 To 80 Step 20
    32.             gr1.DrawLine(Pens.Red, pic1.Width - m_Dx, i, pic1.Width, i)
    33.         Next i
    34.  
    35.         pic1.Image = bm1
    36.  
    37.     End Sub
    38.  
    39.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    40.         data = data + 1
    41.     End Sub
    42. End Class

    Did I miss something?

  2. #2
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: [RESOLVED] picturebox problem

    You have marked this thread resolved. Please be so considerate next time to add the solution as well. We are all here to help and learn from each other
    VB.NET MVP 2008 - Present

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width