|
-
Jan 14th, 2012, 09:13 AM
#1
Thread Starter
New Member
editing picturebox on panel array?
Hi, I'm new here...browsed around a bit and like what i see, hoping to learn a bunch from reading other threads
i have a question about editing a picturebox...i have a class called panelArray and it builds an array of panels based on the number of panels i pass it...each panel has 4 labels and a picturebox added to it when the panel is created. I'm able to edit the labels by using something like:
Me.HostForm.Controls.Item(replaceIndex).Controls.Item(2).Text = ""
Since there are 5 objects total (1 picturebox & 4 labels) i thought i would be able to just use the same strategy for the picturebox, but it doesn't like using Image in the same manner it uses .Text
Also, I realize I'm a noob, so maybe there's a completely easier way to do this than the way i'm doing it
PS: Is there any good beginner guides or member threads that give maybe like a walkthrough or helpful hints to remember when starting a project?
Another thing...is it okay to start a thread in any situation? Searching helps sometimes, but other times its just easier to start a new thread. Don't want to start off by breaking any forum etiquette.
Thanks in advance
-
Jan 14th, 2012, 12:05 PM
#2
Re: editing picturebox on panel array?
Create a class as shown below
Placed in form
Code:
Private ContainerOfSomeClass As New List(Of SomeClass)
. . .
' Add one item
ContainerOfSomeClass.Add(New SomeClass With {.Label1 = Me.Label1, .Label2 = Me.Label2, .PictureBox = Me.PictureBox1})
Manipluate the first item
Code:
Dim Item = ContainerOfSomeClass.First
Item.Label1.Text = "Hello"
Item.Label2.Text = "There"
Item.PictureBox.Image = Nothing
Class (does two labels, add more as needed)
Code:
Public Class SomeClass
Private mLabel1 As Label
Private mLabel2 As Label
Private mPictureBox As PictureBox
Public Property PictureBox() As PictureBox
Get
Return mPictureBox
End Get
Set(ByVal value As PictureBox)
mPictureBox = value
End Set
End Property
Public Property Label2() As Label
Get
Return mLabel2
End Get
Set(ByVal value As Label)
mLabel2 = value
End Set
End Property
Public Property Label1() As Label
Get
Return mLabel1
End Get
Set(ByVal value As Label)
mLabel1 = value
End Set
End Property
Public Sub New()
End Sub
End Class
-
Jan 15th, 2012, 11:13 AM
#3
Thread Starter
New Member
Re: editing picturebox on panel array?
Thanks for the reply!
I'm not understanding this line:
ContainerOfSomeClass.Add(New SomeClass With {.Label1 = Me.Label1, .Label2 = Me.Label2, .PictureBox = Me.PictureBox1})
my form doesn't have a label1, label2, or picturebox1 so its telling me they dont exist on the form. when i get to "With {." it recognizes the 4 labels & picturebox in my class, but i dont understand why im setting it to "=me.label1" since me.label1 doesn't exist
Here's what I was doing
on my form i have
Code:
For i As Integer = 0 to 4 'adds 5 panels
' Call the AddNewPanel Method of MyControlArray
MyControlArray.AddNewPanel(dtInfo.Rows(i)("ID"), dtInfo.Rows(i)("Pic"), dtInfo.Rows(i)("First") & " " & dtInfo.Rows(i)("Last"), dtInfo.Rows(i)("Title"), dtInfo.Rows(i)("Address"))
panelCount += 1
Next
On my class i have
Code:
Public Function AddNewPanel(ByVal ID As Integer, ByVal pic As String, ByVal name As String, ByVal title As String, ByVal add As String) As System.Windows.Forms.Panel
'declare variables
Dim aPanel As New System.Windows.Forms.Panel
Dim picLogo As New System.Windows.Forms.PictureBox
Dim lblName As New System.Windows.Forms.Label
Dim lblID As New System.Windows.Forms.Label
Dim lblTitle As New System.Windows.Forms.Label
Dim lblAdd As New System.Windows.Forms.Label
Dim picPath As String = Application.StartupPath & "\" & pic & ".jpg"
'add control properties
lblName.Location = New Point(80, 2)
lblName.MaximumSize = New Size(220, 20)
lblName.Size = New Size(220, 20)
lblName.Font = New Font("Microsoft Sans Serif", 9.25, FontStyle.Bold)
lblName.Text = name
'etc.......
'add controls to panel
aPanel.Controls.Add(picLogo)
aPanel.Controls.Add(lblID)
aPanel.Controls.Add(lblName)
aPanel.Controls.Add(lblTitle)
aPanel.Controls.Add(lblAdd)
Return aPanel
End Function
-
Jan 15th, 2012, 12:11 PM
#4
Re: editing picturebox on panel array?
 Originally Posted by RedGoneWILD
Thanks for the reply!
I'm not understanding this line:
ContainerOfSomeClass.Add(New SomeClass With {.Label1 = Me.Label1, .Label2 = Me.Label2, .PictureBox = Me.PictureBox1})
my form doesn't have a label1, label2, or picturebox1 so its telling me they dont exist on the form. when i get to "With {." it recognizes the 4 labels & picturebox in my class, but i dont understand why im setting it to "=me.label1" since me.label1 doesn't exist
My intent was to give you something that provides a solution to your problem but outside the context of your problem which means you need to adapt the proposed code to your problem.
The line with ContainerOfSomeClass.Add( is used to add a new item to the list of SomeClass. Figure 1 shows that again and two other methods to do the same thing.
This part With {.Label1 = Me.Label1, .Label2 = Me.Label2, .PictureBox = Me.PictureBox1} assigns controls to the new instance. Replace the control assignments with your controls after they are created in your class.
Figure 1
Code:
ContainerOfSomeClass.Add(New SomeClass With {.Label1 = Me.Label1, .Label2 = Me.Label2, .PictureBox = Me.PictureBox1})
Dim Item1 As New SomeClass With _
{ _
.Label1 = Me.Label1, .Label2 = Me.Label2, .PictureBox = Me.PictureBox1 _
}
Dim Item2 As New SomeClass
Item2.Label1 = Label1
Item2.Label1 = Label2
Item2.PictureBox = PictureBox1
ContainerOfSomeClass.Add(Item1)
ContainerOfSomeClass.Add(Item2)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|