Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a sub "Button1_Click" Handling Button1.Click

can I call this sub ?

 

For example if I click on another button, I want to use the code Call Button1_Click(?)

but where "?" is I need to parse in some arguments : ByVal sender As Object, ByVal e As System.EventArgs

 

 

How do I do that ?

Development & Research Department @ Elven Soft
Posted
I have a sub "Button1_Click" Handling Button1.Click

can I call this sub ?

 

For example if I click on another button, I want to use the code Call Button1_Click(?)

but where "?" is I need to parse in some arguments : ByVal sender As Object, ByVal e As System.EventArgs

 

 

How do I do that ?

this is why VB is simply awful. In C# you just associate the same on onclick handler with every button that you want to use it. easy to do, straight forward and alot less user code cluttering up your project.

 

I believe in vb you just do this

 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Button1_Click(Button2, e)
End Sub

 

in c#, you wouldnt have to write any code, just associate the event using the property window

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Posted

Well actually Joe Mamma, you can do the same in VB, and in C# if you want associate the code with an event you need to add the += new EventHandler blah blah blah, so, it's the same, just in diff ways.

And if you with writting less code, in VB you end up adding less code than in C#

Fat kids are harder to kidnap
Posted
Well actually Joe Mamma, you can do the same in VB, and in C# if you want associate the code with an event you need to add the += new EventHandler blah blah blah, so, it's the same, just in diff ways.

And if you with writting less code, in VB you end up adding less code than in C#

but I cant do it in the IDE by setting a property can I?

I actually have to go in and write the '+=' which means switching between FormDesign and Code

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Posted
:))))))))))))))))))))))))))))))))))))))))))))))))))))))) the energy to reply here would haved been enough for the next 100 switches
Development & Research Department @ Elven Soft
  • *Experts*
Posted
I have a sub "Button1_Click" Handling Button1.Click

can I call this sub ?

 

For example if I click on another button, I want to use the code Call Button1_Click(?)

but where "?" is I need to parse in some arguments : ByVal sender As Object, ByVal e As System.EventArgs

 

 

How do I do that ?

To answer your question (I assume the question is still standing), you can pass

whatever you like in the parameters. If you're not using them within the sub, then

just pass Nothing to the sender and a new instance of the EventArgs class to e.

 

Button1_Click(null, New EventArgs())

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted
To answer your question (I assume the question is still standing), you can pass

whatever you like in the parameters. If you're not using them within the sub, then

just pass Nothing to the sender and a new instance of the EventArgs class to e.

 

Button1_Click(null, New EventArgs())

if in a handler you will want to send the

event args that were initially sent into the handler and the object generating the event as the sender

 

Button1_Click(sender, e)

 

that way Button1_Click can refernece the sending object and the event state

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Posted

Call load event?

 

Right, I'm doing the same, only slightly differently!

 

I want to call the load event from a command button, is this possible? And if so how would I go about it please.

 

I have used the above examples to make one command button perform another command buttons function, but when I tried it on the load event I got an error.

  • *Experts*
Posted

You shouldn't have any problem with calling the Load event; it has the same

parameters as a button's Click event (sender as Object, e As EventArgs).

 

Could you tell us the error you're getting?

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

Well I don�t know what�s going on I�ve had another bash at it tonight and it works OK�.. Must have been tired and made a mistake,

 

This is the code for the button that closes the form:

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

Me.Close()

End Sub

 

And this test button now calls the button above

Private Sub btnReset_Click1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click

btnExit_Click(btnReset, e)

End Sub

 

I also tried this and it works OK.

Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click

frmPizza_Load(sender, e)

End Sub

 

And it also works OK in this format:

Private Sub btnReset_Click1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click

frmPizza_Load(btnReset, e)

End Sub

 

Are either of the last two above more correct than the other or are they both equally as good?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...