this pointer

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All,

In vb.net. why can't a object be accessed within its event handler, uisng
'this' pointer?

Are there any alternatives to using 'this'?

kd
 
kd said:
In vb.net. why can't a object be accessed within its event handler, uisng
'this' pointer?

Use 'Me' instead of 'this'.
 
kd said:
Me - refers to the form name and not the current object name.

'Me' does exactly the same what 'this' does in C++, Java, and C#. Inside an
event handler you can get a reference to the control raising the event in
the value passed to the handler's 'sender' parameter:

\\\
Public Sub Button1_Click(...)...
Dim SourceControl As Button = DirectCast(sender, Button)
SourceControl.Enabled = False
...
End Sub
///
 
KD,

"Me" is the same as in C# "this". It is used in the class not in the
object.

In javascript it is often used as a passed reference to an object, that kind
of "this" you can use in VBNET in the same way as you do it in javascript,
something as

\\\\
dim dt as datatable = new datatable()
dt.columns.Add("hello")
dt.rows.Add(dt)

function mysub(byval this as datatable)
return this.NewRow
end function.
///

I hope this helps

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top