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. Form Layout at Runtime ?

Form Layout at Runtime ?

Scheduled Pinned Locked Moved C#
designxmlquestion
4 Posts 2 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.
  • J Offline
    J Offline
    jamesjk
    wrote on last edited by
    #1

    Is it possible to control the layout of controls on a form at runtime. Actually I have a xml file which will contain some questions & the type of answer it expects. I need to design an interface with these questions on different labels & appropriate controls for accepting the answer to these questions (it might check box, radio button or textbox...) Thanks in Advance, Cheers

    S 1 Reply Last reply
    0
    • J jamesjk

      Is it possible to control the layout of controls on a form at runtime. Actually I have a xml file which will contain some questions & the type of answer it expects. I need to design an interface with these questions on different labels & appropriate controls for accepting the answer to these questions (it might check box, radio button or textbox...) Thanks in Advance, Cheers

      S Offline
      S Offline
      Simon P Stevens
      wrote on last edited by
      #2

      jamesjk wrote:

      Is it possible to control the layout of controls on a form at runtime.

      Yes, just write code that adjust the particular properties of the controls that you want to change. e.g. If you want to change the text of a label. just do myLabel.Text = "NewText"; If you want to add new controls, you can create them just as you would with any other object, and then you just need to add them to the forms .Controls collection.Label myNewLabel = new Label(); myNewLabel.Text = "NewText"; this.Controls.Add(myNewLabel); // Add the new control to the Controls collection so it's displayed on the form. myNewLabel.Left = 50; myNewLabel.Top = 50; myNewLabel.Visible = true; myNewLabel.BackColor = Color.Red;

      Simon

      J 1 Reply Last reply
      0
      • S Simon P Stevens

        jamesjk wrote:

        Is it possible to control the layout of controls on a form at runtime.

        Yes, just write code that adjust the particular properties of the controls that you want to change. e.g. If you want to change the text of a label. just do myLabel.Text = "NewText"; If you want to add new controls, you can create them just as you would with any other object, and then you just need to add them to the forms .Controls collection.Label myNewLabel = new Label(); myNewLabel.Text = "NewText"; this.Controls.Add(myNewLabel); // Add the new control to the Controls collection so it's displayed on the form. myNewLabel.Left = 50; myNewLabel.Top = 50; myNewLabel.Visible = true; myNewLabel.BackColor = Color.Red;

        Simon

        J Offline
        J Offline
        jamesjk
        wrote on last edited by
        #3

        Thanks Simon. The main problem I'm facing is that the xml will be variable. I'm providing a xml editor to the user so that he can add as many questions in it. With uncertain number of questions do you have any suggestions on how i'll be able to manage the layout ? Thanks Again for the reply.

        S 1 Reply Last reply
        0
        • J jamesjk

          Thanks Simon. The main problem I'm facing is that the xml will be variable. I'm providing a xml editor to the user so that he can add as many questions in it. With uncertain number of questions do you have any suggestions on how i'll be able to manage the layout ? Thanks Again for the reply.

          S Offline
          S Offline
          Simon P Stevens
          wrote on last edited by
          #4

          You could have 1 page per question, just do your layout for a page to fit 1 question on it, then have controls to move to the next question, which would have exactly the same layout just with the question text and answers changed. (it wouldn't actually need to be a differnt page or form or anything, just change the text on the form to match the next question) Or, you could use something like the FlowLayoutPanel, which would allow you to add controls to it and it rearranges them to flow in order. You'd probably create one Panel per question, using a predefined layout for the panel, with question and answer buttons, then added each of the question panels to 1 main FlowLayoutPanel which would take care of ordering the question panels for you.

          Simon

          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