PictureBox
-
Hello, I am programming in VB2005. I have a Form1 and Class A: a) In Form1, I have a Picturebox (Name=PictureBox1) b) Class A inherits from PictureBox I am trying the following but the Picturebox1 does not display anything: Dim MyA As New A(PictureBox1.Width, PictureBox1.Height) MyA.Location = New System.Drawing.Point(150, 150) MyA.BackColor = Color.Red PictureBox1 = MyA Why doesn't it works? I have an alternative to solve the problem but I would like to understood the problem above. Alternative sdolution: Dim MyA As New A(500, 350) MyA.Location = New System.Drawing.Point(150, 150) MyA.BackColor = Color.Red controls.add(MyA)
Shay Noy
-
Hello, I am programming in VB2005. I have a Form1 and Class A: a) In Form1, I have a Picturebox (Name=PictureBox1) b) Class A inherits from PictureBox I am trying the following but the Picturebox1 does not display anything: Dim MyA As New A(PictureBox1.Width, PictureBox1.Height) MyA.Location = New System.Drawing.Point(150, 150) MyA.BackColor = Color.Red PictureBox1 = MyA Why doesn't it works? I have an alternative to solve the problem but I would like to understood the problem above. Alternative sdolution: Dim MyA As New A(500, 350) MyA.Location = New System.Drawing.Point(150, 150) MyA.BackColor = Color.Red controls.add(MyA)
Shay Noy
shaynoy wrote:
In Form1, I have a Picturebox (Name=PictureBox1)
Why don't you use real variable names ?
shaynoy wrote:
Dim MyA As New A(PictureBox1.Width, PictureBox1.Height) MyA.Location = New System.Drawing.Point(150, 150) MyA.BackColor = Color.Red PictureBox1 = MyA
This is a bit dumb. What you need to do, is either change your picturebox to be a ClassA, or you need to just create a picturebox and add it to the Controls collection of the form.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
Hello, I am programming in VB2005. I have a Form1 and Class A: a) In Form1, I have a Picturebox (Name=PictureBox1) b) Class A inherits from PictureBox I am trying the following but the Picturebox1 does not display anything: Dim MyA As New A(PictureBox1.Width, PictureBox1.Height) MyA.Location = New System.Drawing.Point(150, 150) MyA.BackColor = Color.Red PictureBox1 = MyA Why doesn't it works? I have an alternative to solve the problem but I would like to understood the problem above. Alternative sdolution: Dim MyA As New A(500, 350) MyA.Location = New System.Drawing.Point(150, 150) MyA.BackColor = Color.Red controls.add(MyA)
Shay Noy
-
shaynoy wrote:
I have an alternative to solve the problem but I would like to understood the problem above.
Start by highlighting the differences between the first and the second code. What does
controls.Add
do?I are Troll :suss:
In the first code PictureBox alrady exists so I do not have to add it. In the second code PictureBox doesn't exist so I am adding it at run-time. So what now?
Shay Noy
-
shaynoy wrote:
In Form1, I have a Picturebox (Name=PictureBox1)
Why don't you use real variable names ?
shaynoy wrote:
Dim MyA As New A(PictureBox1.Width, PictureBox1.Height) MyA.Location = New System.Drawing.Point(150, 150) MyA.BackColor = Color.Red PictureBox1 = MyA
This is a bit dumb. What you need to do, is either change your picturebox to be a ClassA, or you need to just create a picturebox and add it to the Controls collection of the form.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
This is a bit dumb. What you need to do, is either change your picturebox to be a ClassA,
My ClassA inherits from PictureBox object. Now my form1 is creating a new instance of class A and this new instance will "return" a PictureBox that I would like to display on my form1. So I though to do the following form1.PictureBox1=NewInstanceOfClassA to display the result of new instance of ClassA to my form1.
...or you need to just create a picturebox and add it to the Controls collection of the form.
WHay to add it if already exists in my form1, I only want to overwrite it with my new instance of class A Thank you
Shay Noy
-
In the first code PictureBox alrady exists so I do not have to add it. In the second code PictureBox doesn't exist so I am adding it at run-time. So what now?
Shay Noy
shaynoy wrote:
In the first code PictureBox alrady exists so I do not have to add it.
PictureBox1 = MyA
This would not 'replace' the PictureBox1 in memory with an MyA, and I don't know whether the property is smart enough to add the control to the controls-collection on it's own.
I are Troll :)
-
shaynoy wrote:
In the first code PictureBox alrady exists so I do not have to add it.
PictureBox1 = MyA
This would not 'replace' the PictureBox1 in memory with an MyA, and I don't know whether the property is smart enough to add the control to the controls-collection on it's own.
I are Troll :)
Thank you, so you suggest to use controls.add, don't you
Shay Noy
-
Thank you, so you suggest to use controls.add, don't you
Shay Noy
-
That's not what I'm suggesting; you asked merely why the first version didn't work as you expected it to. I guess that you want to replace that
pictureBox1
with aClassA
. Delete the PictureBox from the Form and drop a ClassA on it :)I are Troll :suss:
What do you mean when you say drop?
Shay Noy
-
What do you mean when you say drop?
Shay Noy
-
I meant dragging a ClassA-item from your Toolbox to the Form; just like you add any other control to the form :)
I are Troll :suss:
Thank you for the tip
Shay Noy