|
-
Jan 29th, 2002, 07:28 AM
#1
Thread Starter
Fanatic Member
Protected ?
I see there is a use of [qote] [/quote]
What does this mean? Is this the equiv of friend?
What about Overloads and Overrides??
What the hell are these?
-
Jan 29th, 2002, 09:52 AM
#2
Protected is sort of like Public but means it can only be accessed from tis own or an inherited class.
Overrides means that it replaces a sub/function of the same name and runs the overrides version when the orginal would be called.
Overloads allows you to define multiple subs/functions of the same name but different parameters. .NET will know which one to access depending on the parameter type(s) you pass.
I think that is the easiest way to expoain them. Got it?
-
Jan 30th, 2002, 12:47 AM
#3
Thread Starter
Fanatic Member
SWEAT!
Does this mean that I can write a procedure to replace the class' initialize event that accepts parameters?
-
Jan 30th, 2002, 04:24 AM
#4
Hyperactive Member
yes - you can do that. Although you use the "constructor" (replaces class initialize).
You can also overload it, so that it can accept different parameters
for example,
VB Code:
Public Sub New(ByVal strName As String)
...
End Sub
Public Sub New(ByVal blnSwitch1 As boolean, blnSwitch2 as Boolean)
...
End Sub
Last edited by Bananafish; Jan 30th, 2002 at 04:35 AM.
-
Jan 30th, 2002, 07:34 AM
#5
Thread Starter
Fanatic Member
Sorry, I haven't had time to play with this yet, but will the calling application see the change when creating new objects?
for example:
Previously we did this:
Code:
set obj = new Class
What do we do now if our object creation has parameters?
-
Jan 30th, 2002, 07:39 AM
#6
Hyperactive Member
You would now be able to do this...
VB Code:
Dim objA as New clsClassA(strParam)
-
Jan 30th, 2002, 08:17 AM
#7
Thread Starter
Fanatic Member
I also notice that when adding a button to a form, the onclick event appears with a new guy, "Handles".
What is the significance of this?
-
Jan 30th, 2002, 08:28 AM
#8
Hyperactive Member
Its the "Handles" bit that actually tells you the event (or events) that is being handled. The fact that the sub is called button1_click (or whatever it is) is actually irrelevent - you could rename it and the program wouldnt change.
If you wanted the same method to handle more than one event - ie this is how you would do it. (there are no longer control arrays in vb.Net).
For example,
VB Code:
Private Sub cmdNextPrior_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click, cmdPrior.Click
Dim oButton As System.Windows.Forms.Button
oButton = CType(sender, System.Windows.Forms.Button)
If oButton.Name = "cmdNext" Then
If mintOffset < mcolErr.Count - 1 Then
mintOffset = mintOffset + 1
DisplayException()
End If
End If
If oButton.Name = "cmdPrior" Then
If mintOffset > 0 Then
mintOffset = mintOffset - 1
DisplayException()
End If
End If
End Sub
This code handles the click event of two buttons. The "sender" argument is used to determine which of the two buttons were pressed.
-
Jan 30th, 2002, 09:18 AM
#9
Thread Starter
Fanatic Member
This is pretty cool.
But if there are no control arrays anymore, how do you create controls dynamicaly? And then how do you receive an event from the new control?
I also noticed the use of
System.Windows.Forms.Button
What is the difference between this and
Button
-
Jan 30th, 2002, 09:37 AM
#10
Hyperactive Member
First things first.
There is no difference between Button and System.Windows.Form.Button - it's a namespace thing. If your assembly imports System.Windows.Form, then you have no need to type System.Windows.Form before Button.
And now for something completely different.
An example of dynamically creating a control :-
VB Code:
Dim oNewButton as New Button
'Set it up on the form
oNewButton.Location = New System.Drawing.Point(200, 152)
oNewButton.Size = New System.Drawing.Size(80, 32)
oNewButton.Text = "Press Me"
'Add it to the Forms control collection
Me.Controls.Add(oNewButton)
'Hook it up to the event handler
AddHandler oNewButton.Click AddressOf Me.Button_Click
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|