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. controls

controls

Scheduled Pinned Locked Moved C#
helptutorial
6 Posts 3 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.
  • T Offline
    T Offline
    theanil
    wrote on last edited by
    #1

    hello, i need a help, can we replace the controls dynamically(example: replace radio button by textbox when some event has occurred), if yes then please help me in this thank you :)

    theanil

    P B 2 Replies Last reply
    0
    • T theanil

      hello, i need a help, can we replace the controls dynamically(example: replace radio button by textbox when some event has occurred), if yes then please help me in this thank you :)

      theanil

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

      As you haven't specified what technology you are using (e.g. WinForms), I'm going to have to be fairly general here. Yes you can. You would need to remove the controls you don't want from the parents control collection (you have to iterate over this using a for loop as you are removing items which you can't do inside a foreach if it directly affects the item being iterated). NOTE: Don't forget to dereference the eventhandlers. Once you have removed them, add in your new controls taking care to set any relevant properties such as location, etc.

      Forgive your enemies - it messes with their heads

      "Mind bleach! Send me mind bleach!" - Nagy Vilmos

      My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

      T 1 Reply Last reply
      0
      • P Pete OHanlon

        As you haven't specified what technology you are using (e.g. WinForms), I'm going to have to be fairly general here. Yes you can. You would need to remove the controls you don't want from the parents control collection (you have to iterate over this using a for loop as you are removing items which you can't do inside a foreach if it directly affects the item being iterated). NOTE: Don't forget to dereference the eventhandlers. Once you have removed them, add in your new controls taking care to set any relevant properties such as location, etc.

        Forgive your enemies - it messes with their heads

        "Mind bleach! Send me mind bleach!" - Nagy Vilmos

        My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

        T Offline
        T Offline
        theanil
        wrote on last edited by
        #3

        thank you, but i tried that way, i need to toggle between the controls and as the answer you said, deleting the controls every time and adding new one is time consuming, is there any alternate way to do this.

        theanil

        P 1 Reply Last reply
        0
        • T theanil

          thank you, but i tried that way, i need to toggle between the controls and as the answer you said, deleting the controls every time and adding new one is time consuming, is there any alternate way to do this.

          theanil

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

          Rather than delete them, change their Visibility. The downside is that you will consume more memory leaving that much open.

          Forgive your enemies - it messes with their heads

          "Mind bleach! Send me mind bleach!" - Nagy Vilmos

          My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

          T 1 Reply Last reply
          0
          • P Pete OHanlon

            Rather than delete them, change their Visibility. The downside is that you will consume more memory leaving that much open.

            Forgive your enemies - it messes with their heads

            "Mind bleach! Send me mind bleach!" - Nagy Vilmos

            My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

            T Offline
            T Offline
            theanil
            wrote on last edited by
            #5

            i can try that thing, i am working on IEEE paper so i have to check for both time and memory.

            theanil

            1 Reply Last reply
            0
            • T theanil

              hello, i need a help, can we replace the controls dynamically(example: replace radio button by textbox when some event has occurred), if yes then please help me in this thank you :)

              theanil

              B Offline
              B Offline
              BillWoodruff
              wrote on last edited by
              #6

              Well, yes you can, but why would you ? Particurlarly in this case: it's hard for me to imagine a scenario in which a RadioButton (usually used in groups where the function desired is to select one option from many) replaces a TextBox, or, the reverse. The second thought ... which I see Pete O'Hanlon has already explained, is to implement both controls, and "swap" them by changing their visibility. In the case where both "alternate" controls expose the same Events (with the exact same type of EventArgs parameter), you could have, for example, a RadioButton and a TextBox use the same EventHandler for Click, although I think that, too is "dubious" practice: better, imho, they each have their own Click handler, and then call a common method if there's any code that both Click events need to use. So, I suggest you re-consider your design here.

              "Science is facts; just as houses are made of stones: so, is science made of facts. But, a pile of stones is not a house, and a collection of facts is not, necessarily, science." Henri Poincare

              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