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 146 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

    button1.FlatStyle = TypeOfStyleObject; I studied the link you pointed out and it solved my problem, with an exception. I fetched the name of the CONTROL (not a specific control like Button) and changed my function input from BUTTON to CONTROL. It passed without error but I did find a catch.... In the function that I apply the configuration parameters to the generic buttons I successfully applied Text, BackColor, ForeColor as a quick test. When I was passing the Button control I was setting FlatStyle but getting a string to object error (above). Now that I am passing the Control control it is saying my "Control" does not have a parameter FlatStyle. I am interpreting this way..... the Control lets me work without specifying the type of object(button, label, RTBox) but I may lose access to some parameters??? Accurate?? I may need to still find a way of passing specific controls instead of generic control object so I don’t lose configurability. I could follow your lead of preloading a Button[] object array and trying see if I can use its index as an object. Am going anywhere but backwards or circles…… I assuming there has to be some methods that allows you to convert-this-string-to-what-AnyObject-wants() so objects can be acted on in loops and sequences. You have to be able to store & retrieve non numeric

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

    If you look at the documentation for all these features you will see that they invariably have a numeric value which you can pass to the constructor, or set dynamically.

    1 Reply Last reply
    0
    • C Codice Fictor

      button1.FlatStyle = TypeOfStyleObject; I studied the link you pointed out and it solved my problem, with an exception. I fetched the name of the CONTROL (not a specific control like Button) and changed my function input from BUTTON to CONTROL. It passed without error but I did find a catch.... In the function that I apply the configuration parameters to the generic buttons I successfully applied Text, BackColor, ForeColor as a quick test. When I was passing the Button control I was setting FlatStyle but getting a string to object error (above). Now that I am passing the Control control it is saying my "Control" does not have a parameter FlatStyle. I am interpreting this way..... the Control lets me work without specifying the type of object(button, label, RTBox) but I may lose access to some parameters??? Accurate?? I may need to still find a way of passing specific controls instead of generic control object so I don’t lose configurability. I could follow your lead of preloading a Button[] object array and trying see if I can use its index as an object. Am going anywhere but backwards or circles…… I assuming there has to be some methods that allows you to convert-this-string-to-what-AnyObject-wants() so objects can be acted on in loops and sequences. You have to be able to store & retrieve non numeric

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

      Your control is (still) also a button, and you can test for that using "is" and "as", and switch between them. [https://stackoverflow.com/questions/3786361/difference-between-is-and-as-keyword\](https://stackoverflow.com/questions/3786361/difference-between-is-and-as-keyword)

      "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

        Your control is (still) also a button, and you can test for that using "is" and "as", and switch between them. [https://stackoverflow.com/questions/3786361/difference-between-is-and-as-keyword\](https://stackoverflow.com/questions/3786361/difference-between-is-and-as-keyword)

        "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
        #6

        Thank You to Everyone , Your time is valuable and I appreciate it………… I don’t comprehend ‘yet’ why when I pass a Button reference, I have a parameter to modify but when I pass it as a Control I’m told this parameter is no longer available, at the top level. I do understand there are other hooks into the control I haven’t learned yet. The reality of the matter is I stepped on a puddle and found out it was a pot hole, I’m sailing in unfamiliar waters. I am a self-taught C#’er with a background from Verlog FPGA and C firmware with no one local to tutor me. I started writing GUI’s in order to aid and test FPGA and firmware code development plus the automation of production testing. I’ve gotten away so far by walking around the ‘object mountain’ and I’ve reached a point I need to climb it. I have a strong background in state machine development and implementation, I just need to up the game on ‘objects’. I’m pretty good at making a big snow ball if I can figure out which direction to roll down the hill……….. As can been seen from my post I lack the vocabulary………… I was searching for Button when I should have been researching Controls. I fully comprehend the feedback I am getting but I’m lost in the implementation. Not having a full vocabulary in object language can you point me to a youtube series that would be a good launching point for me at my current level of comprehension. I find a free-flowing mind on video conveys more implementation guidance than a rigid text of facts. A finger pointing in the right direction is all I really need………….. Thank You Again for your time and help…….

        L 1 Reply Last reply
        0
        • C Codice Fictor

          Thank You to Everyone , Your time is valuable and I appreciate it………… I don’t comprehend ‘yet’ why when I pass a Button reference, I have a parameter to modify but when I pass it as a Control I’m told this parameter is no longer available, at the top level. I do understand there are other hooks into the control I haven’t learned yet. The reality of the matter is I stepped on a puddle and found out it was a pot hole, I’m sailing in unfamiliar waters. I am a self-taught C#’er with a background from Verlog FPGA and C firmware with no one local to tutor me. I started writing GUI’s in order to aid and test FPGA and firmware code development plus the automation of production testing. I’ve gotten away so far by walking around the ‘object mountain’ and I’ve reached a point I need to climb it. I have a strong background in state machine development and implementation, I just need to up the game on ‘objects’. I’m pretty good at making a big snow ball if I can figure out which direction to roll down the hill……….. As can been seen from my post I lack the vocabulary………… I was searching for Button when I should have been researching Controls. I fully comprehend the feedback I am getting but I’m lost in the implementation. Not having a full vocabulary in object language can you point me to a youtube series that would be a good launching point for me at my current level of comprehension. I find a free-flowing mind on video conveys more implementation guidance than a rigid text of facts. A finger pointing in the right direction is all I really need………….. Thank You Again for your time and help…….

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

          Everything in c# (.NET) is an "object". You then add dressing (a class) and turn it into something else. Add another class and make a composite of what came before. But it is still an "object" and also whatever comes after; you're just putting on and taking off diffferent coats. That's "inheritance" ... one of the "3 pillars" of OOP. That, and understanding "value types" versus "reference types" ("pointers" to "objects" or functions) allow you to model just about anything in software.

          "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
          • 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…………………….

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

            Codice Fictor wrote:

            Simply put, how would I research and find the solution for these types of problems:

            The general problem is that you need to map one value to another value. The specifics of the values for each is not really relevant. The process however, obviously, is. Being a bit more specific to your problem you want to map a 'string' (text) to something. I can't actually tell what you want to map to. But lets say, for example, that it is enum. Then there are two choices. 1. The string must match the name of the enum exactly. You can get by without case sensitivity but otherwise it must be the same. 2. You MUST provide code that maps from the string to the enum. Note that there are NO other choices. Pick one. Lets say you want to pick 1. Then you cannot name a key 'A Key' because a space is not something that can appear in a enum name. You can google for how to convert from string to enum and back again. Or if you pick 2. There are various ways to do this. But one way actually ends up looking like solution 1. So for example you would have a table that looks like what I posted below. You would read it then match the first value. Then use the second value to create an enum (like I said similar to 1.)

            'A Key', 'KeyA'
            'B Key', 'KeyB'
            '= Key', 'KeyEquals'

            Or you could just create a switch

            switch(keyValue)
            {
            case "A Key": return KeyValue.KeyA;
            case "B Key": return KeyVAlue.KeyB;

            There are variations on this.

            C 1 Reply Last reply
            0
            • L Lost User

              Everything in c# (.NET) is an "object". You then add dressing (a class) and turn it into something else. Add another class and make a composite of what came before. But it is still an "object" and also whatever comes after; you're just putting on and taking off diffferent coats. That's "inheritance" ... one of the "3 pillars" of OOP. That, and understanding "value types" versus "reference types" ("pointers" to "objects" or functions) allow you to model just about anything in software.

              "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
              #9

              Is that the essence of “wrapping”?? I have seen that term with a few libraries I have fiddled with from GitHub. “understanding "value types" versus "reference types" ("pointers" to "objects" or functions)” That sounds like the perfect search phrase to get me started…………. Thanks Again…………..

              L 1 Reply Last reply
              0
              • C Codice Fictor

                Is that the essence of “wrapping”?? I have seen that term with a few libraries I have fiddled with from GitHub. “understanding "value types" versus "reference types" ("pointers" to "objects" or functions)” That sounds like the perfect search phrase to get me started…………. Thanks Again…………..

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

                "Wrapping" (which is a "design pattern") is intentionally "hiding" one object by wrapping it with another in order to protect or facilitate certain features; not the same as "inheriting" which "adds" functionality.

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

                  "Wrapping" (which is a "design pattern") is intentionally "hiding" one object by wrapping it with another in order to protect or facilitate certain features; not the same as "inheriting" which "adds" functionality.

                  "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
                  #11

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

                    Codice Fictor wrote:

                    Simply put, how would I research and find the solution for these types of problems:

                    The general problem is that you need to map one value to another value. The specifics of the values for each is not really relevant. The process however, obviously, is. Being a bit more specific to your problem you want to map a 'string' (text) to something. I can't actually tell what you want to map to. But lets say, for example, that it is enum. Then there are two choices. 1. The string must match the name of the enum exactly. You can get by without case sensitivity but otherwise it must be the same. 2. You MUST provide code that maps from the string to the enum. Note that there are NO other choices. Pick one. Lets say you want to pick 1. Then you cannot name a key 'A Key' because a space is not something that can appear in a enum name. You can google for how to convert from string to enum and back again. Or if you pick 2. There are various ways to do this. But one way actually ends up looking like solution 1. So for example you would have a table that looks like what I posted below. You would read it then match the first value. Then use the second value to create an enum (like I said similar to 1.)

                    'A Key', 'KeyA'
                    'B Key', 'KeyB'
                    '= Key', 'KeyEquals'

                    Or you could just create a switch

                    switch(keyValue)
                    {
                    case "A Key": return KeyValue.KeyA;
                    case "B Key": return KeyVAlue.KeyB;

                    There are variations on this.

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

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