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. Converting string into non-string Form.Object types for passing to methods or updating non-string object.Property with strings

Converting string into non-string Form.Object types for passing to methods or updating non-string object.Property with strings

Scheduled Pinned Locked Moved C#
helpquestioncsharpgraphicsdata-structures
22 Posts 6 Posters 159 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.
  • C Codice Fictor

    Thank You Jerry, ButtonBase BUTTONx = this.Controls.["button1"]; I tried that before and ButtonBase doesn't associate with the string name. I get error CS1001 at the '['. This doesn't work either ButtonBase.Button BUTTONx = this.Controls.["button1"];

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

    I posted about "is" and "as" already in this thread; which would have answered your question. The other aspect related to "is" and "as" is "boxing"; but that is generally used for "value types".

    "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

    1 Reply Last reply
    0
    • C Codice Fictor

      Hello & Salutations to Everyone, using: Win Forms .NET 4.7.2 I have a set of Form buttons named button1, button2, button3,……… I have an array of strings BUTTON_LIST_str[] =” button1”, “button2”, “button3”,… I have a function: private void APPLY_BUTTON_CFG(Button b) { …………… } What I need to do is loop through BUTTON_LIST_str[] and pass each button object to APPLY_BUTTON_CFG(Button b). Basically for every string I need to use for pointing to a different type form object or its property of object, I get the error "String cannot be converted to the object required type/format (System.Form......) I have searched every convoluted order of words for hours and cannot find a solution that matched my scenario of converting strings to all form object types (or specific ones either). With so many unique object specific variables how does one research the solution to convert a string to each type for each case? Is there a ConvertToType universal function that solves this issue. I also ran into same problem with: FlatStyle P_STYLE = “Flat”; Button1.FlatStyle = P_STYLE or FlatStyle.P_STYLE ; // error cannot convert string to…………..FlatStyle object type I understand that a string name cannot point to a form object OOP when passing to a function. I’m not sure I can ask my question competently…………. With so many unique object specific variables how does one research the string conversion solution for each case? Simply put, how would I research and find the solution for these types of problems: Button1.FlatStyle = How to convert string to FlatStyle object reference, or Font, TextAlign when an error occurs? I did find this translator for colors but not FlatStyle though or for any other applicable parameters. P_COLOR = System.Drawing.ColorTranslator.FromHtml("White"); //"White" will be replaced with a string array element CFG_PARAM_PARSED[2]); Button1.ForeColor = P_COLOR; This is the real kicker: Button name as string (String_Array[x]) needs conversion (typecast?) to object name reference var ButtonObject = String_Array[x]; or Button ButtonObject = String_Array[x]; APPLY_BUTTON_CFG(ButtonObject); private void APPLY_BUTTON_CFG(Button b) { …………… } Thank You So Much for your time and assistance…………………….

      B Offline
      B Offline
      Bosse62
      wrote on last edited by
      #22

      Your BUTTON_LIST_str array contains the class System.String Your APPLY_BUTTON_CFG method needs the class System.Windows.Forms.Button as the parameter Theres is no way to convert a string to a button.

      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