473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

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
Jun 27 '08 #1
7 1360
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.comschreef in bericht
news:u7**************@TK2MSFTNGP05.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

Jun 27 '08 #2
On Jun 1, 8:39*pm, "Malakie" <MalakieUSN_at_Hotmail.comwrote:
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
Jun 27 '08 #3
"Tom Shelton" <to*********@comcast.netwrote in message
news:28**********************************@a70g2000 hsh.googlegroups.com...
On Jun 1, 8:39 pm, "Malakie" <MalakieUSN_at_Hotmail.comwrote:
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.
Jun 27 '08 #4
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.

http://www.vb-tips.com/DynamicControl.aspx
While this one is even more funny
http://www.vb-tips.com/MoveControl.aspx

Cor

"Tom Shelton" <to*********@comcast.netschreef in bericht
news:28**********************************@a70g2000 hsh.googlegroups.com...
On Jun 1, 8:39 pm, "Malakie" <MalakieUSN_at_Hotmail.comwrote:
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

Jun 27 '08 #5
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" <to*********@comcast.netwrote in message
news:28**********************************@a70g2000 hsh.googlegroups.com...
On Jun 1, 8:39 pm, "Malakie" <MalakieUSN_at_Hotmail.comwrote:
>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
Jun 27 '08 #6
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]" <no************@planet.nlwrote in message
news:01**********************************@microsof t.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.comschreef in bericht
news:u7**************@TK2MSFTNGP05.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
Jun 27 '08 #7
On Sun, 1 Jun 2008 21:39:47 -0500, "Malakie"
<MalakieUSN_at_Hotmail.comwrote:
>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.DriveInfo.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 ButtonClickEventHandler
' 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.FileSystemWatcher can be used to watch for changes in the
file system.
Jun 27 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David J. Berman | last post by:
Thanks for any help...! My error is: Object reference not set to an instance of an object. > public int DisplayOrder { > get { >>>>>> return (int) ViewState; > }
0
by: tommy | last post by:
hello everybody, i haved read a few articles about, how to create controls in asp.net dynamically! i have tested it -- all works fine.... but....now it comes--> HOW create controls...
17
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but...
5
by: Chris | last post by:
Is there any way you can dynamically add an event and then some code. I get it that you could, in your code, add a control and dynamically add an event handler for e.g. the click event. However the...
5
by: Chris | last post by:
I have a page with mixture of static and dynamically added controls is there any way of controlling the order which they are added to the page. My submit button (statically added) appears before...
2
by: Dica | last post by:
i've got a script that creates a new tablerow + tablecell and appends that to a non dynamically created table control. a new row is added for each recordset returned from my sql statement. within...
13
by: Konrad Hammerer | last post by:
Hi! Can somebody tell me or show me an example how to add a textbox and a button dynamically by code to an apsx page and how to read the filled in value from the textbox after the user has...
1
by: hyerk | last post by:
I currently have a FlowLayoutPanel that creates buttons dynamically for each entry in a database: for (int i = 0; i < int_num_users; i++) { Button b = new Button(); ...
3
by: Malakie | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.