WithEvents keyword gone!

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

Guest

Hi, all

I got a problem when I create a custom control. I created a custom Button and it works just fine. But the Windows Form Designer always remove the WithEvents keyword of my object declare. If I manually add the keyword, it works for a monent and it will automatically gone after some time. What may be the problem? Any help is appraciated.
 
Hi John,

Where are you putting the declaration? It sounds like you might be putting
it within the "Windows Form Designer generated code" region. You should not
put you own code within this region as it gets automatically generated
whenever changes are made in the designer which may cause any code you put
in that region to be changed/deleted.

Gary

John said:
Hi, all

I got a problem when I create a custom control. I created a custom Button
and it works just fine. But the Windows Form Designer always remove the
WithEvents keyword of my object declare. If I manually add the keyword, it
works for a monent and it will automatically gone after some time. What may
be the problem? Any help is appraciated.
 
* "=?Utf-8?B?Sm9obg==?= said:
I got a problem when I create a custom control. I created a custom
Button and it works just fine. But the Windows Form Designer always
remove the WithEvents keyword of my object declare. If I manually add
the keyword, it works for a monent and it will automatically gone after
some time. What may be the problem? Any help is appraciated.

Do you add the control to the form using the Windows Forms designer.
Remember that VS doesn't like it if you change the designer generated
code.
 
Thanks Gary, but where should I put the decaration? I tried to put it out side the "Windows Form Designer generated code" region, but the Form Designer automatically put it back to its region and removes the WithEvents Keyword -:( Also, it removes the Handles keyword after the Button_Click event handler.
Appreciated for your help!
 
I think this is a get out of the car and get back in. Did you at any time
have a control with the name WButton1. I have seen on several occcasions
the remnants of old controls sticking around. Had to stop VS and restart.

Lloyd Sheen

John said:
I really stuck!
I put the declaration " Friend WithEvents WButton1 As WButton " out side
" Windows Form Designer generated code " Region, It works for the first
time. If I switch to Form Design View, and double click on the WButton1, the
Form Designer automatically removes WithEvents keyword, and it also removes
the " Handles WButton1.Click " after the event handler. The original code
look like this:
Private Sub WButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
and form designer generates the following code:
Private Sub WButton1_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles WButton1.Click
and an error says Handles clause requires a WithEvents variable, since it takes that keyword away!
Don't you think that's stupid? I really need all your HELP! With many
thanks!
 
Yes, that works. But it needs a lot extra works. I want my application to have the same button with the same size, the same feel and look and my application will have more than a hundred button. It would be nice if there's a way to just drag and drop the button on the form, leaving the works of adding WithEvents and Handles keywords to the form designer
But thanks for your help anyway.
 
Back
Top