CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2004
    Posts
    23

    Dynamic Controls ???

    I’m looking to build a dynamic GUI base on a XML File. I would like to create a Label with the Hostname, Label for Service, and Button with click event to call mymethod and pass in the value from Label Hostname and Label Service. I never tried to add controls dynamic and after google I’m more confused now. I really just want to be able to add to my XML file and the GUI pick it up on load. Also .Net 2.0 Please point me to a sample, good read, or anything for the novice.


    My XML

    <Servers>
    <Server>
    <Hostname>localhost</Hostname>
    <Service>spooler</Service>
    </Server>
    <Server>
    <Hostname>remotehost</Hostname>
    <Service>spooler</Service>
    </Server>
    </Servers>

  2. #2
    Join Date
    Feb 2006
    Posts
    8

    Re: Dynamic Controls ???

    This is a sample for creating a dynamic button.
    A button is represented with a Button class.

    // create an instance of the button
    Button btn = new Button();

    // set the properties of the new button
    btn.Text = "hello";
    btn.Size = new Size(75, 23);
    btn.Location = new Point(0, 0);

    // set the click event of the button to call your handler
    btn.Click += new EventHandler(btn_Click);

    // add the button to the form controls
    Controls.Add(btn);

    When the button is clicked the btn_click function is called
    This is a how it should look like:

    void btn_Click(object sender, EventArgs e)
    {
    MessageBox.Show("hello");
    }

    Now you should prepare a function for each type of control you want to dynamically create and use the XML file to contain all property values.

    Enjoy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured