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 133 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.
  • L Lost User

    Sounds a lot like a decorator pattern. Do you despise it? I mean, I do like adding functionality by using a decorator, and the .NET framework apparently too, as there are a lot of places where we use them.

    Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

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

    I said a wrapper can hide or "facilitate"; which is a good thing. I wrapped a C++ "animation" engine in a FoxPro dll so I could generate 3rd graphics using FoxPro. I did it to earn a license that normally cost $8,000. (A "long" time ago). I could create and race a buggy over 3D terrain ... The ultimate plan was to use the graphics engine in my "rail car repair system", but that's another track.

    "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

    L 1 Reply Last reply
    0
    • C Codice Fictor

      It’s getting clear now…. Because of my background and my only experience with C# is working with objects, refs and pointers created and generated at run time, I was lost on setting up a reference (linking them) in my code with the instantiation of a pre-existing object dragged onto the Form. Every help link is about creating an object with your definitions and manipulating what you created not syntax/methodology on decoding what you didn’t create. Thank you……….. And I understand Class and SubClass structure but not how to maneuver around in it in C#. Now that I can pass my Form Control around in my code I’m not sure the buzz words to comprehend this problem (abbreviated): private void ManuplateButtons(Control InputButton) { InputButton.Text = // Good Button12.FlatStyle = // Good (pre-instantiated on Form) InputButton.FlatStyle = // CS1061 'type' does not contain a definition ………… Button FlatStyle is available but Control FlatStyle is not in the list of parameters. So now I need to learn how to dig into the object reference(Control InputButton) to find how FlatStyle is referenced inside of the object reference (Control InputButton). Is it Control.InputButton.A.B.C nope, so I need to learn how to navigate into the object reference (Control InputButton) and query where FlatStyle is stored or discover what else I can do with an object I didn’t create. I imagine this is not an across the board answer because of the many things you could put/reference in an object. Timeout; I was composing this when I just read jschell’s post. I believe I have caught up to your post. In reference to above and #1: I usually depend on the Visual Studio dropdown list and look up the details of the options available until I find the parameter/function that I need or the research of the p/f leads me to an answer. The available button12.X where x = Flatstyle, Flatstyle is in the list but in the case of reference(Control InputButton). Flatstyle is not in the list so I must find it……….. methodology unknown to me ‘yet’. “…..convert from string to enum” but I need to find the enum def for reference(Control InputButton).Flatstyle before I can convert my string to the relevant enum. I understand the cross correlation between 1 & 2 of jschell’s post. What are the key search phrases of OOP for the methodology and implementation of how discover what is enumerated in an object that is not shown in the dropdown list, because if “string must match the name of the e

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

      Button, inherits from ButtonBase, which inherits from Control. FlatStyle is defined in ButtonBase. At a minimum, you need to "cast" Control to ButtonBase to access that property. As a side note, ButtonBase is an "abstract" class: you can't actually create ButtonBase except via a class that inherits it (like Button, CheckBox, and RadioButton; or your own "custom" button).

      "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

      C 1 Reply Last reply
      0
      • L Lost User

        I said a wrapper can hide or "facilitate"; which is a good thing. I wrapped a C++ "animation" engine in a FoxPro dll so I could generate 3rd graphics using FoxPro. I did it to earn a license that normally cost $8,000. (A "long" time ago). I could create and race a buggy over 3D terrain ... The ultimate plan was to use the graphics engine in my "rail car repair system", but that's another track.

        "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

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

        A "decorator" is usually there to add functionality?

        Gerry Schmitz wrote:

        I could create and race a buggy over 3D terrain

        Now there is some code I'd like to read and learn from :) I'm really bad at making games, I do forms and databases.

        Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

        P L 2 Replies Last reply
        0
        • L Lost User

          A "decorator" is usually there to add functionality?

          Gerry Schmitz wrote:

          I could create and race a buggy over 3D terrain

          Now there is some code I'd like to read and learn from :) I'm really bad at making games, I do forms and databases.

          Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

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

          I'm sure, with a bit of lateral thinking, you could make a game out of form filling.

          Advanced TypeScript Programming Projects

          L 1 Reply Last reply
          0
          • P Pete OHanlon

            I'm sure, with a bit of lateral thinking, you could make a game out of form filling.

            Advanced TypeScript Programming Projects

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

            Way off topic; I'll try. If I succeed, it will become a new article. ..I just never looked at it that way; it is a game, not a form. Input is input, regardless where it comes from? Thank you for making my day :)

            Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

            1 Reply Last reply
            0
            • L Lost User

              A "decorator" is usually there to add functionality?

              Gerry Schmitz wrote:

              I could create and race a buggy over 3D terrain

              Now there is some code I'd like to read and learn from :) I'm really bad at making games, I do forms and databases.

              Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

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

              What is a "game"? I was a Windows Form evangelist because WPF didn't have a data grid at the time. Then WPF ... I now use UWP because it gets me in the Store, for one thing. (But now any exe can be added to the Store.) My game consists mostly of moving rectangles around and measuring angles and distances. "Gettysburg!" It's under "Books and References" so I don't pay the "game premium".

              "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
              • L Lost User

                Button, inherits from ButtonBase, which inherits from Control. FlatStyle is defined in ButtonBase. At a minimum, you need to "cast" Control to ButtonBase to access that property. As a side note, ButtonBase is an "abstract" class: you can't actually create ButtonBase except via a class that inherits it (like Button, CheckBox, and RadioButton; or your own "custom" button).

                "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

                C Offline
                C Offline
                Codice Fictor
                wrote on last edited by
                #19

                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"];

                J L 2 Replies Last reply
                0
                • 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"];

                  J Offline
                  J Offline
                  jschell
                  wrote on last edited by
                  #20

                  Codice Fictor wrote:

                  this.Controls.["button1"];

                  I seriously doubt that there is any situation in which the period before the bracket would ever be valid.

                  1 Reply Last reply
                  0
                  • 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