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

        • Cor Ligthert[MVP]

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

          Tom,

          In my idea is this far beside the problem of the OP, but as it is this, then
          is in my idea this tip more complete.




          While this one is even more funny


          Cor

          "Tom Shelton" <tom_shelton@co mcast.netschree f in bericht
          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

          Comment

          • Malakie

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

            Hi,

            Thanks. I will play with what you posted. As for simple demo, well I am
            trying to make something that I will actually use as well and thought this
            'feature' would be what I want in this kind of utility. So I figure there
            is no better way to learn than do something that takes a bit of work and
            thought.. And realizing I would probably need some help here and there
            once I exhausted my ability to figure it out myself.

            Thanks again



            "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
            --
            until later.....

            Malakie


            Comment

            • Malakie

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

              Hi,

              First I am not looking for someone to write my code. I am looking for help
              with a specific issue I am having with a project I using to learn from and
              will hopefully be a useful utility I want to use. After working on this one
              particular thing for days, I am just not figuring it out. So I can either
              continue to try and figure it out without a clue on what I should be doing,
              I can give up or I can come here and ask for some code examples that will
              point me in the right direction so I can learn how to do this.

              As for showing my code, how am I supposed to do that when I don't know what
              to do what I am trying to do? I do not have any code for that specific
              function, that is why I am here! As for the rest of the application if you
              want me to upload all the code for that well I don't really see the point.
              It is a form with some text boxes on it, a drive list, directory list and
              that is it. I want to create buttons that show up dynamically for each
              drive on the system, appearing and disappearing as I add or remove drives.
              When I click a drive button, the drive and directory lists will update. I
              have that working as it was simple to do with plain static hard coded
              buttons. But I want to be able to use this on any of my machines here
              without having to hardcode what drives exist on each machine.. If the tool
              can dynamically add buttons for drives, problem solved.



              "Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
              news:01E90145-E068-48ED-ACBC-7C7C866FC4EF@mi crosoft.com...
              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
              >>
              >>
              >
              --
              until later.....

              Malakie


              Comment

              • Jack Jackson

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

                On Sun, 1 Jun 2008 21:39:47 -0500, "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.
                System.IO.Drive Info.GetDrives( ) will get you a list of drives. You
                can iterate through that list and create the buttons from there.

                For each button:
                Dim btn As New Button
                btn.Text = "some text"
                AddHandler btn.Click, AddressOf ButtonClickEven tHandler
                ' Set .Left and .Top properties
                Me.Controls.Add (btn)

                If you put a FlowLayoutPanel on your form, you can just create and add
                buttons to it and the panel will deal with laying them out.

                System.IO.FileS ystemWatcher can be used to watch for changes in the
                file system.

                Comment

                Working...