Example of code that dynamically creates controls on form for each HD or CD etc

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Malakie

    Example of code that dynamically creates controls on form for each HD or CD etc

    Hi all,

    I am trying to self teach VB .net to myself. Not sure what is worse, trying
    to accomplish this or thinking I can actually do it! ;-)

    Anyhow, Would someone be able to give me some example VB net code that would
    create buttons on a form dynamically for each drive (cd or HD or virtual
    etc) found on a system; labeling each created button with one of the found
    drive letters. It would also need to remove said button if the drive was
    disconnected say in the case of an external usb drive and of course add
    buttons as drives are added.

    I have been researching this and trying everything I can on my own and am
    getting no where fast. Basically I creating a index program for myself as
    a learning project but am stuck at trying to figure out how to do this
    function. If someone could give me some code that does this that I can
    learn from and modify, play with etc, it would be most appreciated.

    Thanks.

    --
    until later.....

    Malakie
    MalakieUSN at Hotmail.com


  • Cor Ligthert[MVP]

    #2
    Re: Example of code that dynamically creates controls on form for each HD or CD etc

    Malakie,

    As this are your questions, then first in my opinion you should first create
    an easier project for yourself.

    This is not a newsgroup that creates code for others, there are many people
    active here by helping others, but not with creating programs to them.

    If you have questions, then show your code, a lot of people here will help
    you to improve that. But not from scratch.

    Just my own opinion.

    Cor

    "Malakie" <MalakieUSN_at_ Hotmail.comschr eef in bericht
    news:u7mc2nFxIH A.1436@TK2MSFTN GP05.phx.gbl...
    Hi all,
    >
    I am trying to self teach VB .net to myself. Not sure what is worse,
    trying to accomplish this or thinking I can actually do it! ;-)
    >
    Anyhow, Would someone be able to give me some example VB net code that
    would create buttons on a form dynamically for each drive (cd or HD or
    virtual etc) found on a system; labeling each created button with one of
    the found drive letters. It would also need to remove said button if the
    drive was disconnected say in the case of an external usb drive and of
    course add buttons as drives are added.
    >
    I have been researching this and trying everything I can on my own and am
    getting no where fast. Basically I creating a index program for myself
    as a learning project but am stuck at trying to figure out how to do this
    function. If someone could give me some code that does this that I can
    learn from and modify, play with etc, it would be most appreciated.
    >
    Thanks.
    >
    --
    until later.....
    >
    Malakie
    MalakieUSN at Hotmail.com
    >
    >

    Comment

    • Tom Shelton

      #3
      Re: Example of code that dynamically creates controls on form foreach HD or CD etc

      On Jun 1, 8:39 pm, "Malakie" <MalakieUSN_at_ Hotmail.comwrot e:
      Hi all,
      >
      I am trying to self teach VB .net to myself.  Not sure what is worse, trying
      to accomplish this or thinking I can actually do it!  ;-)
      >
      Anyhow, Would someone be able to give me some example VB net code that would
      create buttons on a form dynamically for each drive (cd or HD or virtual
      etc) found on a system; labeling each created button with one of the found
      drive letters.   It would also need to remove said button if the drive was
      disconnected say in the case of an external usb drive and of course add
      buttons as drives are added.
      >
      I have been researching this and trying everything I can on my own and am
      getting no where fast.   Basically I creating a index program for myselfas
      a learning project but am stuck at trying to figure out how to do this
      function.  If someone could give me some code that does this that I can
      learn from and modify, play with etc, it would be most appreciated.
      >
      Thanks.
      >
      --
      until later.....
      >
      Malakie
      MalakieUSN at Hotmail.com
      Malakie,

      That's a bit much for a simple demo :) But, the basic concept of
      dynamic controls is fairly simple...

      Dim b As New Button()
      b.Text = "Hello!"
      b.Position = new Point(150,150)
      AddHandler b.Click, Me.b_Click

      Me.Controls.Add (b)

      That's pretty much all there is to it. Though, you need to calculate
      a possition on the form possibly - replacing the hardcoded values
      above :)

      --
      Tom Shelton

      Comment

      • Michael D. Ober

        #4
        Re: Example of code that dynamically creates controls on form for each HD or CD etc

        "Tom Shelton" <tom_shelton@co mcast.netwrote in message
        news:28759d63-94c6-4492-943b-36257eacb203@a7 0g2000hsh.googl egroups.com...
        On Jun 1, 8:39 pm, "Malakie" <MalakieUSN_at_ Hotmail.comwrot e:
        Hi all,
        >
        I am trying to self teach VB .net to myself. Not sure what is worse,
        trying
        to accomplish this or thinking I can actually do it! ;-)
        >
        Anyhow, Would someone be able to give me some example VB net code that
        would
        create buttons on a form dynamically for each drive (cd or HD or virtual
        etc) found on a system; labeling each created button with one of the found
        drive letters. It would also need to remove said button if the drive was
        disconnected say in the case of an external usb drive and of course add
        buttons as drives are added.
        >
        I have been researching this and trying everything I can on my own and am
        getting no where fast. Basically I creating a index program for myself as
        a learning project but am stuck at trying to figure out how to do this
        function. If someone could give me some code that does this that I can
        learn from and modify, play with etc, it would be most appreciated.
        >
        Thanks.
        >
        --
        until later.....
        >
        Malakie
        MalakieUSN at Hotmail.com
        Malakie,

        That's a bit much for a simple demo :) But, the basic concept of
        dynamic controls is fairly simple...

        Dim b As New Button()
        b.Text = "Hello!"
        b.Position = new Point(150,150)
        AddHandler b.Click, Me.b_Click

        Me.Controls.Add (b)

        That's pretty much all there is to it. Though, you need to calculate
        a possition on the form possibly - replacing the hardcoded values
        above :)

        --
        Tom Shelton


        To remove the controls, simply hide them. They'll still be there but will
        be unavailable for the end user.

        Mike Ober.


        Comment

        Working...