Sorry bout the last post guys, it was not the real problem. Here it is, I have this code which creates a picturebox through code and supposed to display something like a line graph but I'm having errors in these lines:
gr1.DrawImage(con.Image, -m_Dx, 0)
con.Image = bm1
It says that 'Image is not a member of 'System.Windows.Forms.Control'.
I can seem to figure out what's missing.
gr1.DrawImage(con.Image, -m_Dx, 0)
con.Image = bm1
It says that 'Image is not a member of 'System.Windows.Forms.Control'.
I can seem to figure out what's missing.
VB.NET:
Imports System.Windows.Forms
Imports System.Drawing
Public Class Form1
Private Const m_Dx As Single = 1
Dim data As Integer = 1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim pic1 As New PictureBox
pic1.Location = New Point(12, 12)
pic1.Name = "pic1"
pic1.Width = 142
pic1.Height = 102
pic1.Visible = True
pic1.BackColor = Color.Black
pic1.BorderStyle = BorderStyle.Fixed3D
Controls.Add(pic1)
Dim bm1 As New Bitmap(pic1.Width, pic1.Height)
Dim gr1 As Graphics = Graphics.FromImage(bm1)
gr1.ScaleTransform(1, -101 / pic1.Height)
gr1.TranslateTransform(0, -101)
For i As Integer = 20 To 80 Step 20
gr1.DrawLine(Pens.Red, 0, i, pic1.Width, i)
Next i
pic1.Image = bm1
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
For Each con As Control In Me.Controls
If con.Name = "pic1" Then
Dim bm1 As New Bitmap(con.Width, con.Height)
Dim gr1 As Graphics = Graphics.FromImage(bm1)
gr1.DrawImage(con.Image, -m_Dx, 0)
gr1.ScaleTransform(1, -101 / con.Height)
gr1.TranslateTransform(0, -101)
Dim new_value1 As Integer = data / 2
If new_value1 < 1 Then new_value1 = 1
gr1.DrawLine(Pens.Blue, _
con.Width - 1, 0, _
con.Width - 1, new_value1)
For i As Integer = 20 To 80 Step 20
gr1.DrawLine(Pens.Red, con.Width - m_Dx, i, con.Width, i)
Next i
con.Image = bm1
End If
Next
data = data + 1
End Sub
End Class
Last edited: