Array of buttons... identify button on click

  • Thread starter Thread starter Francesco Ranieri
  • Start date Start date
F

Francesco Ranieri

Hi to all,

I'm programming with CF 1.0 and VB.NET 2003.

I've created an array of button "btnPRVPagesButtons" on my form.
All buttons click are handled by one only function
"btnPRVPagesButtons_Click"
I'm trying to capture (identify) the button clicked reading its ".Text"
property.

Private btnPRVPagesButtons(MAX_PAGES, MAX_BUTTONS_PER_PAGE) As ImageButton

...........................

private sub CreateButtons(ByVal intPageIndex As Integer, ByVal
intButtonIndex As Integer)

btnPRVPagesButtons(intPageIndex, intButtonIndex) = New ImageButton

btnPRVPagesButtons(intPageIndex, intButtonIndex).Text = "P" &
intPageIndex.ToString & "I" & intButtonIndex.ToString

AddHandler btnPRVPagesButtons(intPageIndex, intButtonIndex).Click,
AddressOf btnPRVPagesButtons_Click

Me.Controls.Add(btnPRVPagesButtons(intPageIndex, intButtonIndex))

end sub

Private Sub btnPRVPagesButtons_Click(ByVal objPRMSender As Object, ByVal
earPRMEvent As EventArgs)

'?????????????????????????????????

End Sub


I wish to find the instruction that allows me to read ".Text" property of
the button clicked into click handler "btnPRVPagesButtons_Click", there
where I've put '???????.

Any suggestion?
Thanks in advance
Francesco
 
Cast the objPRMSender (you know that hungarian notation is no longer the
preferred convention for naming, right?) to a Button and read the Text
property.
 
Thanks Chris for your immediate response.

Only a few days ago, I've decided to write my 'first' vb.net application...
for this reason...
.... for now, I'm upgrading to VB.net from VB 6.0 and....
.... for now, sorry, Hungarian notation is my world (as vb 6.0 that I've
decided to lay aside)...
.....it will be upgraded.... when I'll undestand vb.net!!! :-((

I've tried to 'cast' as you have suggested... with this

Dim myButton As Button
myButton = objPRMSender

or

myButton = New objPRMSender

but I believe I'm wrong... an error occurs!!!
What's means 'cast'?? Sorry!!
Thanks again
....
 
In VB I'm not certain the syntax - CType I think. Not sure if the "as"
keywork is available for you. In C# it's this:

Button myButton = (Button)objPRMSender;
or
Button myButton = objPRMSender as Button;
 
Thanks Chris again...
You're right:

Dim myButton As ImageButton
myButton = CType(objPRMSender, ImageButton)

MessageBox.Show("btnPagesButtons_Click " & myButton.Text)

.... is the right solution.
 
you know that hungarian notation is no longer the preferred convention for
naming, right?

Actually I think the wonderful VS refactoring and renaming capabilities make
Hungarian notation an even more attractive convention than ever before.

Cheers
Doug Forster
 
How so? I see really no point in using hungarian notation. The IDE tells
you types through IntelliSense, so what good is also having it in the name,
other than making it ugly and less maintainable? When the IDE wouldn't tell
you, it was useful so you didn't have to dig back through layers of code
files to figure it out, but it's no longer the case. We also seem to have
gotten rid of line numbers, because again they're pretty useless.
 
How so?
By removing one major impediment that you mention: 'maintainability'
Well the subject has always polarised programmers and I'm fine with that.
But our company has over a million lines of code written using hungarian in
various languages and we are not about to change just because one particular
language team says so.
you types through IntelliSense, so what good is also having it in the
name,
Way too slow and clunky - like looking up a dictionary to read a written
language you don't speak.
gotten rid of line numbers, because again they're pretty useless.
Well yes that was punched card era stuff .

Anyway this is off topic and I guess it boils down to a matter of opinion
anyway

Cheers
Doug Forster
 
Back
Top