PerformClick stopped working
I have the code below that worked for a long time and I made some simple code changes, like adding a msgbox stmt, and now none of my PerformClicks work. Anyone know why? Here is the code:
PrivateSub
frm_ARExport_Shown(ByVal
senderAsObject
,ByVal
eAs
System.EventArgs)HandlesMe
.ShownMsgBox(
"AutoStart=" & AutoStart.ToString)If
AutoStartThen
MsgBox(
"Before btnLogin.PerformClick()") 'fires btnLogin.PerformClick() 'does not fire
MsgBox(
"After btnLogin.PerformClick()") 'fires btnDoFile.PerformClick() 'does not fire
'Me.Close()
EndIf
EndSub
PrivateSub
btnLogin_Click(ByVal
senderAs
System.Object,ByVal
eAs
System.EventArgs)Handles
btnLogin.Click MsgBox(
"btnLogin_Click")EndSub
Can you give us code for BtnDoFile?
have you also tried:
BtnDoFile_Click(nothing, nothing)
to see if that fires?
Check if btnLogin.PerformClick() contains
RaiseEvent Me.Click(this, nothing);
JRQ at 2007-10-8 >

such a function does not exist in VB.NET :-) That's C# you posted....must be something similar perhaps
Never mind my previous post it will not work either.
First thing first
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
MsgBox("btnLogin_Click")
End Sub
You are handling btnLogin.Click. This means that you have to define an event in the button class that looks something like this.
Public Shadows Event Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
To be able to do this;
public sub PerformClick()
RaiseEvent Click(Me, nothing)
end sub
However you will lose the default Click event.
So what you really want is--
Public Event CustomClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
public sub PerformClick()
RaiseEvent CustomClick(Me, nothing)
end sub
Then map both CustoCLick and Click to the same event handler
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click, btnLogin.CustomClick
MsgBox("btnLogin_Click")
End Sub
IF you really just want to stick with one Click event, then you will have to use SendMessage API call inside PerformClick. In this case public shadows Click is no longer needed.
JRQ at 2007-10-8 >

From ahmedilyas >such a function does not exist in VB.NET :-) That's C# you posted....must be something similar perhaps
What function does not exist in VB.Net? What do you mean?
I was referring to the code JRQ posted
Reply to JRQ>You are handling btnLogin.Click. This means that you have to define an event in the button class that looks something like this.
The code worked and then stopped working. I did not change anything in the btnLogin routine. It worked like a charm before. The PerformClick is a simple method defined for the button class as:
Generates a Click event for a button.
| Visual Basic (Usage) |
| DiminstanceAs Buttoninstance.PerformClick |
What am I missing here? I have it a 100 times in other code and it works just like clicking on the button.
I didn't known button has a PerformClick method. Odd, but let me look further.
Can you post the frm_ARExport code. I'm intrigue by the Me.Shown.
JRQ at 2007-10-8 >

There's just one reason I can think of why btnLogin.PerformClick() wouldn't work: btnLogin.Enabled = False. Instead of PerformClick, you can just call the event handler directly with:
btnLogin_Click(Me, EventArgs.Empty) You found it! I changed the enabled of the button because it was being called from the scheduler and the purpose of the routine was to click the button. Duh. That's why it stopped working.
Your suggestion was how I got the program to work but I was curious why the performClick was not working. Thanks for the insight.
There is too much code to post. The Me.Shown allows some code to fire when the form shows on the screen. There is some code in the form.load event that determines whether the program is being opened for some ad hoc work by a user or is being run by the operating system scheduler. If it is run by the scheduler, then I want the buttons to be clicked automatically to make it do what it does.