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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. string question

string question

Scheduled Pinned Locked Moved C#
question
5 Posts 5 Posters 1 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.
  • B Offline
    B Offline
    bar3000
    wrote on last edited by
    #1

    I have a string with the value of "pictureBox89", a picturebox who's called pictureBox89, and another picturebox called picbox. Now when I recieve the "pictureBox89" string is there any way I can make picbox equal pictureBox89? I thought about If( a == "pictureBox89") picbox = pictureBox89; but the thing is I have too many pictureboxes. I figured if there's a command for this I could get it over with in one line. Thanks in advance.

    W A P V 4 Replies Last reply
    0
    • B bar3000

      I have a string with the value of "pictureBox89", a picturebox who's called pictureBox89, and another picturebox called picbox. Now when I recieve the "pictureBox89" string is there any way I can make picbox equal pictureBox89? I thought about If( a == "pictureBox89") picbox = pictureBox89; but the thing is I have too many pictureboxes. I figured if there's a command for this I could get it over with in one line. Thanks in advance.

      W Offline
      W Offline
      WinSolution
      wrote on last edited by
      #2

      I cant understand your logic Where does these string values comes from and what is the range of possible values (such as pictureBox1 ,pictureBox2 ,pictureBox3 ...) and why are you taking decision If you tell the me whole story i can give you a appropriate logic.

      1 Reply Last reply
      0
      • B bar3000

        I have a string with the value of "pictureBox89", a picturebox who's called pictureBox89, and another picturebox called picbox. Now when I recieve the "pictureBox89" string is there any way I can make picbox equal pictureBox89? I thought about If( a == "pictureBox89") picbox = pictureBox89; but the thing is I have too many pictureboxes. I figured if there's a command for this I could get it over with in one line. Thanks in advance.

        A Offline
        A Offline
        arun_pk
        wrote on last edited by
        #3

        i think u can store the string "picbox" in another string variable(suppose strPB) and make that string variable as "picturebox89" and u can use the strPB in the places where its required

        1 Reply Last reply
        0
        • B bar3000

          I have a string with the value of "pictureBox89", a picturebox who's called pictureBox89, and another picturebox called picbox. Now when I recieve the "pictureBox89" string is there any way I can make picbox equal pictureBox89? I thought about If( a == "pictureBox89") picbox = pictureBox89; but the thing is I have too many pictureboxes. I figured if there's a command for this I could get it over with in one line. Thanks in advance.

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          If I understand your question, what you are asking, is if you can associate picbox with another control, the only reference you have being the string. Off the top of my head, I'd use something like the code below:

          private Control FindControl(Controls controls, string controlName)
          {
          if (controls == null)
          return null;
          foreach (Control ctrl in controls)
          {
          if (ctrl.Name == controlName)
          {
          return ctrl;
          }
          else
          {
          Control c == FindControl(ctrl.Controls, controlName);
          if (c != null)
          {
          return c;
          }
          }
          }
          }

          Then, you can call this using

          picbox = FindControl(MyForm.Controls, nameToSearchFor) as PictureBox;

          "WPF has many lovers. It's a veritable porn star!" - Josh Smith

          My blog | My articles | MoXAML PowerToys

          1 Reply Last reply
          0
          • B bar3000

            I have a string with the value of "pictureBox89", a picturebox who's called pictureBox89, and another picturebox called picbox. Now when I recieve the "pictureBox89" string is there any way I can make picbox equal pictureBox89? I thought about If( a == "pictureBox89") picbox = pictureBox89; but the thing is I have too many pictureboxes. I figured if there's a command for this I could get it over with in one line. Thanks in advance.

            V Offline
            V Offline
            Vikram A Punathambekar
            wrote on last edited by
            #5

            You want to find a control given its name? Just do this.Controls["controlName"] and cast it back into a TextBox or whatever.

            Cheers, Vıkram.


            I've never ever worked anywhere where there has not been someone who given the choice I would not work with again. It's a job, you do your work, put up with the people you don't like, accept there are probably people there that don't like you a lot, and look forward to the weekends.   - Josh Gray.

            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