Mini-Tutorial: VB6 -> VB.NET introduction
Ok, so you have used VB6 for years but suddenly you have migrated to VB.NET and don't have a clue... i have put this together to help get you started
the biggest issue you will have is forms... forms are no longer magically existant, they must be instantiated and have references passed to each other to access them.
here is a tutorial for using multiple forms: http://www.devcity.net/Articles/94/1/multipleforms.aspx (compliments of gigemboy)
but even before you visit there i recommend doing this simple exercise that will train you for instantiating objects. Control arrays no longer exist ( :eek: you say)
never fear, we can make them ourselves at runtime if we like. Ok, here is how to make a control array of 5 buttons
Make 5 buttons on the form from code
Code:
Dim buttonArray(5) as Button
but, that wont do the job.. what we have made is 5 empty "containers" for buttons, they need to be populated with an "instance" of an object
Code:
buttonArray(0) = New Button
that will instantiate the first one, what you need to do is use a for loop to instantiate them all. Also give them x and y co-ords and make them visible
The next problem faced is hw on earth do i know if they are clicked?
first, make a sub ready to handle a button click event
Code:
Sub ButtonArray_Clicked(ByVal sender As System.Object, ByVal e As System.EventArgs)
'sender will be the button that was clicked
End Sub
notice the layout is the same as any other button click event, it must have the same variables
now, in your for loop, you need to add a "handler" to link the buttons click event with that sub, doing so is as simple as
Code:
AddHandler ButtonArray(0).Click, AddressOf ButtonArray_Click
how do i know which one is clicked?
well, you may notice i noted that "sender" will be the button that was clicked.. but it is of type Object so how can we use it? this is yet another hurdle, object is the general type of all classes.. but we know that for this particular sub, it will always be a Button, so we can safety DirectCast it into a Button (As an object it is still a button.. but it doesnt know that it is, basically)
Code:
Sub ButtonArray_Clicked(ByVal sender As System.Object, ByVal e As System.EventArgs)
'sender will be the button that was clicked (in object form)
Dim buttonClicked as Button = DirectCast(sender,Button)
'now buttonClicked is the sender object in its correct Button form
End Sub
To extend on this simple array, experiment with using an ArrayList, declaring it at form level "Private ButtonArray As New ArrayList" so that you can add and remove controls from it at will.
If you are into graphics, when it comes time, don't use bltbit, readup on GDI+, included in .NET and very useful, do a search on this site for it.
Good Luck :wave:
Re: Mini-Tutorial: VB6 -> VB.NET introduction
This is a very good and simple article for vb6 guys who probably feel tired to read pages and pages of text.This one is neat.
But,I think you could add a few words in this thread like migrating from vb6 to vb.net...vb.net for vb6 developers,etc.in some conext...or maybe use a sentence for example like...this will be very good for vb6 developers migrating to .Net..
If you mention a few phrases like that,I think this would come on top in the google search.Many people would need this :) vbforums results come within top 5 on google many times if it contains specific information.