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. C#
  4. How can I write text to a picturebox?

How can I write text to a picturebox?

Scheduled Pinned Locked Moved C#
question
10 Posts 6 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.
  • A Offline
    A Offline
    Andrew Stampor
    wrote on last edited by
    #1

    For the project I am working on, if I cannot find an image, I am going to write the image name to the picturebox instead. However, there doesn't seem to be a straightforward property (like "Text") that I can use. Is there an easy way to do this?

    N C M 3 Replies Last reply
    0
    • A Andrew Stampor

      For the project I am working on, if I cannot find an image, I am going to write the image name to the picturebox instead. However, there doesn't seem to be a straightforward property (like "Text") that I can use. Is there an easy way to do this?

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      Andrew Stampor wrote:

      Is there an easy way to do this?

      Define easy ;P One way would be to replace, at run time, the picture box with another control, like label, that has a text property. To keep the picture box you would need to create an image and write the text on to it, then assign it to the picture box. There numerous examples of how to do this.


      only two letters away from being an asset

      G 1 Reply Last reply
      0
      • N Not Active

        Andrew Stampor wrote:

        Is there an easy way to do this?

        Define easy ;P One way would be to replace, at run time, the picture box with another control, like label, that has a text property. To keep the picture box you would need to create an image and write the text on to it, then assign it to the picture box. There numerous examples of how to do this.


        only two letters away from being an asset

        G Offline
        G Offline
        Giorgi Dalakishvili
        wrote on last edited by
        #3

        You can place a label over a picturebox and change its visibility according to existence of picture

        my articles

        N 1 Reply Last reply
        0
        • G Giorgi Dalakishvili

          You can place a label over a picturebox and change its visibility according to existence of picture

          my articles

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          picturebox.visible = false; label.visible = true; This essentially replaces the picturebox with the label control.


          only two letters away from being an asset

          A 1 Reply Last reply
          0
          • N Not Active

            picturebox.visible = false; label.visible = true; This essentially replaces the picturebox with the label control.


            only two letters away from being an asset

            A Offline
            A Offline
            Andrew Stampor
            wrote on last edited by
            #5

            I only have access to the picturebox itself. Using a label would be a good way, but I cannot rely on it. I think I will try to override the OnPaint, but it seems like more trouble than it should be.

            N H 2 Replies Last reply
            0
            • A Andrew Stampor

              I only have access to the picturebox itself. Using a label would be a good way, but I cannot rely on it. I think I will try to override the OnPaint, but it seems like more trouble than it should be.

              N Offline
              N Offline
              Not Active
              wrote on last edited by
              #6

              Andrew Stampor wrote:

              I only have access to the picturebox itself.

              You can override the OnPaint event but you can't place a label control on the form?:confused:


              only two letters away from being an asset

              A 1 Reply Last reply
              0
              • N Not Active

                Andrew Stampor wrote:

                I only have access to the picturebox itself.

                You can override the OnPaint event but you can't place a label control on the form?:confused:


                only two letters away from being an asset

                A Offline
                A Offline
                Andrew Stampor
                wrote on last edited by
                #7

                The picturebox is inherited from and extended. I do not know which form(s) it will necessarily be on. I was able to take care of it with OnPaint. Thanks for your help, guys.

                1 Reply Last reply
                0
                • A Andrew Stampor

                  For the project I am working on, if I cannot find an image, I am going to write the image name to the picturebox instead. However, there doesn't seem to be a straightforward property (like "Text") that I can use. Is there an easy way to do this?

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

                  Yes, create a bitmap, draw the string onto it, and put it in the picturebox.

                  Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                  1 Reply Last reply
                  0
                  • A Andrew Stampor

                    I only have access to the picturebox itself. Using a label would be a good way, but I cannot rely on it. I think I will try to override the OnPaint, but it seems like more trouble than it should be.

                    H Offline
                    H Offline
                    Hesham Yassin
                    wrote on last edited by
                    #9

                    you can use a label as a pictureBox so catch two birds in one hand ;)

                    1 Reply Last reply
                    0
                    • A Andrew Stampor

                      For the project I am working on, if I cannot find an image, I am going to write the image name to the picturebox instead. However, there doesn't seem to be a straightforward property (like "Text") that I can use. Is there an easy way to do this?

                      M Offline
                      M Offline
                      Muammar
                      wrote on last edited by
                      #10

                      Bitmap bm = new Bitmap(@"C:\YourPicture.bmp");
                      Graphics gr = Graphics.FromImage(bm);
                      gr.DrawString(""test", new Font("Verdana", (float)10, FontStyle.Bold, GraphicsUnit.Pixel), new SolidBrush(Color.Red),(float)20, (float)20);
                      gr.Dispose();
                      pictureBox1.Image = bm;


                      Smile: A curve that can set a lot of things straight! (\ /) (O.o) (><)

                      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