Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. PictureBox

PictureBox

Scheduled Pinned Locked Moved Visual Basic
graphicshelpquestion
11 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H helelark123

    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

    C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #2

    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.

    H 1 Reply Last reply
    0
    • H helelark123

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #3

      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:

      H 1 Reply Last reply
      0
      • L Lost User

        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:

        H Offline
        H Offline
        helelark123
        wrote on last edited by
        #4

        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

        L 1 Reply Last reply
        0
        • C Christian Graus

          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.

          H Offline
          H Offline
          helelark123
          wrote on last edited by
          #5

          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

          1 Reply Last reply
          0
          • H helelark123

            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

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #6

            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 :)

            H 1 Reply Last reply
            0
            • L Lost User

              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 :)

              H Offline
              H Offline
              helelark123
              wrote on last edited by
              #7

              Thank you, so you suggest to use controls.add, don't you

              Shay Noy

              L 1 Reply Last reply
              0
              • H helelark123

                Thank you, so you suggest to use controls.add, don't you

                Shay Noy

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #8

                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 a ClassA. Delete the PictureBox from the Form and drop a ClassA on it :)

                I are Troll :suss:

                H 1 Reply Last reply
                0
                • L Lost User

                  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 a ClassA. Delete the PictureBox from the Form and drop a ClassA on it :)

                  I are Troll :suss:

                  H Offline
                  H Offline
                  helelark123
                  wrote on last edited by
                  #9

                  What do you mean when you say drop?

                  Shay Noy

                  L 1 Reply Last reply
                  0
                  • H helelark123

                    What do you mean when you say drop?

                    Shay Noy

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #10

                    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:

                    H 1 Reply Last reply
                    0
                    • L Lost User

                      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:

                      H Offline
                      H Offline
                      helelark123
                      wrote on last edited by
                      #11

                      Thank you for the tip

                      Shay Noy

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups