Connecting Tech Pros Worldwide Help | Site Map

overrides help please

Merlin
Guest
 
Posts: n/a
#1: Nov 20 '05
I have created a users control with a text box and button on it, what I want
to do is override the usercontrol Keydown events with that of the Text box.
What is the correct syntax to accomplish this?

Example of my text box sub:-
Private Sub Edit_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Edit.KeyDown
End Sub

Thanks


Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#2: Nov 20 '05

re: overrides help please


Hello,

"Merlin" <jeff@jg-tech.co.uk> schrieb:[color=blue]
> I have created a users control with a text box and button on it,
> what I want to do is override the usercontrol Keydown events
> with that of the Text box. What is the correct syntax to accomplish
> this?[/color]

What behavior would you expect?

Regards,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet


Armin Zingler
Guest
 
Posts: n/a
#3: Nov 20 '05

re: overrides help please


"Merlin" <jeff@jg-tech.co.uk> schrieb[color=blue]
> I have created a users control with a text box and button on it, what
> I want to do is override the usercontrol Keydown events with that of
> the Text box.[/color]

???
Sorry, I don't get your intention.

[color=blue]
> What is the correct syntax to accomplish this?
>
> Example of my text box sub:-
> Private Sub Edit_KeyDown(ByVal sender As Object, ByVal e As
> System.Windows.Forms.KeyEventArgs) Handles Edit.KeyDown
> End Sub[/color]


--
Armin

Merlin
Guest
 
Posts: n/a
#4: Nov 20 '05

re: overrides help please


Sorry, I'll try to make myself clearer:-

What I want to be able to do is place my UserControl on a form and then in
the UserControl KeyDown Event trap key presses from my text box that is
within the UserControl. So in otherwords override the UserControl KeyDown
Events with the Text box KeyDown Events.

Thanks,
Merlin


"Merlin" <jeff@jg-tech.co.uk> wrote in message
news:bindmc$a9f$1@hercules.btinternet.com...[color=blue]
> I have created a users control with a text box and button on it, what I[/color]
want[color=blue]
> to do is override the usercontrol Keydown events with that of the Text[/color]
box.[color=blue]
> What is the correct syntax to accomplish this?
>
> Example of my text box sub:-
> Private Sub Edit_KeyDown(ByVal sender As Object, ByVal e As
> System.Windows.Forms.KeyEventArgs) Handles Edit.KeyDown
> End Sub
>
> Thanks
>
>[/color]


Armin Zingler
Guest
 
Posts: n/a
#5: Nov 20 '05

re: overrides help please


"Merlin" <jeff@jg-tech.co.uk> schrieb[color=blue]
> Sorry, I'll try to make myself clearer:-
>
> What I want to be able to do is place my UserControl on a form and
> then in the UserControl KeyDown Event trap key presses from my text
> box that is within the UserControl. So in otherwords override the
> UserControl KeyDown Events with the Text box KeyDown Events.[/color]

Now I think I understand - if you leave out the last sentence. ;-)

You can handle the textbox' keypress event in the Usercontrol:

Private Sub TextBox1_KeyPress( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles TextBox1.KeyPress

End Sub

Still I don't think that's what you wanted to know, so...

--
Armin

Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#6: Nov 20 '05

re: overrides help please


Hello,

"Armin Zingler" <az.nospam@freenet.de> schrieb:[color=blue][color=green]
> > Sorry, I'll try to make myself clearer:-
> >
> > What I want to be able to do is place my UserControl on a form and
> > then in the UserControl KeyDown Event trap key presses from my text
> > box that is within the UserControl. So in otherwords override the
> > UserControl KeyDown Events with the Text box KeyDown Events.[/color]
>
> Now I think I understand - if you leave out the last sentence. ;-)
>
> You can handle the textbox' keypress event in the Usercontrol:
>
> Private Sub TextBox1_KeyPress( _
> ByVal sender As Object, _
> ByVal e As System.Windows.Forms.KeyPressEventArgs) _
> Handles TextBox1.KeyPress
>
> End Sub
>
> Still I don't think that's what you wanted to know, so...[/color]

I think merlin wants to forward/redirect the keyboard input of the textbox
to the usercontrol. Every time the user presses a key in the textbox, the
usercontrol's KeyPress event should be raised.

Regards,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet


Fergus Cooney
Guest
 
Posts: n/a
#7: Nov 20 '05

re: overrides help please


Hi Merlin,

If the other responses haven't quite answered your question (I
find it quite ambiguous), can you tell us <why> you want this override
and what you hope to achieve?

Regards,
Fergus


Merlin
Guest
 
Posts: n/a
#8: Nov 20 '05

re: overrides help please


Sorry, I'll try to make myself clearer:-

What I want to be able to do is place my UserControl on a form and then in
the UserControl KeyDown Event trap key presses from my text box that is
within the UserControl. So in otherwords override the UserControl KeyDown
Events with the Text box KeyDown Events.

Thanks,
Merlin


Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#9: Nov 20 '05

re: overrides help please


Hello,

"Merlin" <jeff@jg-tech.co.uk> schrieb:[color=blue]
> What I want to be able to do is place my UserControl on a form and then in
> the UserControl KeyDown Event trap key presses from my text box that is
> within the UserControl. So in otherwords override the UserControl KeyDown
> Events with the Text box KeyDown Events.[/color]

Untested (!), code for the UserControl:

\\\
Private Sub TextBox1_KeyDown( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs _
) Handles TextBox1.KeyDown
MyBase.OnKeyDown(e)
End Sub
///

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet


Merlin
Guest
 
Posts: n/a
#10: Nov 20 '05

re: overrides help please


Ok here goes,

I have created a control that has a text box and a button at the end of the
text box, I want my control to totally emulate a text box, but have the
added addition of a button at the end. The idea of this control is to allow
a user to input text in the normal manner or press a button to display a
pick list.

Therefore I want the usercontrol events all overridden with the Text box
events. As it stands If I were to place my user control on a form and trap
the usercontrol keydown event when entering text, I'd only be trapping
events for the user control so get nothing whereas I want to trap the text
box events:-

i.e
instead of UserControl.TextBox1.Keydown
I want UserControl.Keydown to be exactly the same.

Hope thats clearer.

Thanks

Merlin.

"Fergus Cooney" <filter-1@tesco.net> wrote in message
news:uYoLZtxbDHA.2412@TK2MSFTNGP09.phx.gbl...[color=blue]
> Hi Merlin,
>
> Lol. That's the <what>.
> Can you tell us the <why> ?
>
>
> This is the bit that everyone is struggling to understand. It really[/color]
makes[color=blue]
> <no sense> to us at all, yet it's the bit that you haven't changed!!
>
> Post 1: override the usercontrol Keydown events with that of the Text box
> Post 2: override the UserControl KeyDown Events with the Text box KeyDown
> Events
> Post 3: override the UserControl KeyDown Events with the Text box KeyDown
> Events
>
>
> Tell us in human terms. - What effect do you want to achieve - for
> yourself, for the user?
>
> With curiousity and anticipation,
> Fergus.
>
>[/color]


Jay B. Harlow [MVP - Outlook]
Guest
 
Posts: n/a
#11: Nov 20 '05

re: overrides help please


Merlin,
Say the following without using the word 'overridden'! :-|
[color=blue]
> Therefore I want the usercontrol events all overridden with the Text box
> events.[/color]

I believe the word 'overridden' above is what is confusing every one about
your post.

If you want each TextBox event to raise the respective usercontrol event
then you need to do as I & Herfried pointed out earlier.

Note if you are not seeing OnKeyDown method from Herfried's & my earlier
posts, use "Tools - Options - Text Editor - Basic - General - Hide advanced
members" to see all the On* event methods in UserControl & Control.

Hope this helps
Jay


"Merlin" <jeff@jg-tech.co.uk> wrote in message
news:bism0v$j63$1@titan.btinternet.com...[color=blue]
> Ok here goes,
>
> I have created a control that has a text box and a button at the end of[/color]
the[color=blue]
> text box, I want my control to totally emulate a text box, but have the
> added addition of a button at the end. The idea of this control is to[/color]
allow[color=blue]
> a user to input text in the normal manner or press a button to display a
> pick list.
>
> Therefore I want the usercontrol events all overridden with the Text box
> events. As it stands If I were to place my user control on a form and trap
> the usercontrol keydown event when entering text, I'd only be trapping
> events for the user control so get nothing whereas I want to trap the text
> box events:-
>
> i.e
> instead of UserControl.TextBox1.Keydown
> I want UserControl.Keydown to be exactly the same.
>
> Hope thats clearer.
>
> Thanks
>
> Merlin.
>
> "Fergus Cooney" <filter-1@tesco.net> wrote in message
> news:uYoLZtxbDHA.2412@TK2MSFTNGP09.phx.gbl...[color=green]
> > Hi Merlin,
> >
> > Lol. That's the <what>.
> > Can you tell us the <why> ?
> >
> >
> > This is the bit that everyone is struggling to understand. It really[/color]
> makes[color=green]
> > <no sense> to us at all, yet it's the bit that you haven't changed!!
> >
> > Post 1: override the usercontrol Keydown events with that of the Text[/color][/color]
box[color=blue][color=green]
> > Post 2: override the UserControl KeyDown Events with the Text box[/color][/color]
KeyDown[color=blue][color=green]
> > Events
> > Post 3: override the UserControl KeyDown Events with the Text box[/color][/color]
KeyDown[color=blue][color=green]
> > Events
> >
> >
> > Tell us in human terms. - What effect do you want to achieve - for
> > yourself, for the user?
> >
> > With curiousity and anticipation,
> > Fergus.
> >
> >[/color]
>
>[/color]


Merlin
Guest
 
Posts: n/a
#12: Nov 20 '05

re: overrides help please


Thanks Jay and Hertfried,

I thought overrides is what I needed, which is why like you said I confused
everyone.

Next question then:
What does override do or when should it be used?

Regards,
Merlin


"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow@email.msn.com> wrote in message
news:uwH4Tr8bDHA.1488@TK2MSFTNGP12.phx.gbl...[color=blue]
> Merlin,
> Say the following without using the word 'overridden'! :-|
>[color=green]
> > Therefore I want the usercontrol events all overridden with the Text box
> > events.[/color]
>
> I believe the word 'overridden' above is what is confusing every one about
> your post.
>
> If you want each TextBox event to raise the respective usercontrol event
> then you need to do as I & Herfried pointed out earlier.
>
> Note if you are not seeing OnKeyDown method from Herfried's & my earlier
> posts, use "Tools - Options - Text Editor - Basic - General - Hide[/color]
advanced[color=blue]
> members" to see all the On* event methods in UserControl & Control.
>
> Hope this helps
> Jay
>
>
> "Merlin" <jeff@jg-tech.co.uk> wrote in message
> news:bism0v$j63$1@titan.btinternet.com...[color=green]
> > Ok here goes,
> >
> > I have created a control that has a text box and a button at the end of[/color]
> the[color=green]
> > text box, I want my control to totally emulate a text box, but have the
> > added addition of a button at the end. The idea of this control is to[/color]
> allow[color=green]
> > a user to input text in the normal manner or press a button to display a
> > pick list.
> >
> > Therefore I want the usercontrol events all overridden with the Text box
> > events. As it stands If I were to place my user control on a form and[/color][/color]
trap[color=blue][color=green]
> > the usercontrol keydown event when entering text, I'd only be trapping
> > events for the user control so get nothing whereas I want to trap the[/color][/color]
text[color=blue][color=green]
> > box events:-
> >
> > i.e
> > instead of UserControl.TextBox1.Keydown
> > I want UserControl.Keydown to be exactly the same.
> >
> > Hope thats clearer.
> >
> > Thanks
> >
> > Merlin.
> >
> > "Fergus Cooney" <filter-1@tesco.net> wrote in message
> > news:uYoLZtxbDHA.2412@TK2MSFTNGP09.phx.gbl...[color=darkred]
> > > Hi Merlin,
> > >
> > > Lol. That's the <what>.
> > > Can you tell us the <why> ?
> > >
> > >
> > > This is the bit that everyone is struggling to understand. It[/color][/color][/color]
really[color=blue][color=green]
> > makes[color=darkred]
> > > <no sense> to us at all, yet it's the bit that you haven't changed!!
> > >
> > > Post 1: override the usercontrol Keydown events with that of the Text[/color][/color]
> box[color=green][color=darkred]
> > > Post 2: override the UserControl KeyDown Events with the Text box[/color][/color]
> KeyDown[color=green][color=darkred]
> > > Events
> > > Post 3: override the UserControl KeyDown Events with the Text box[/color][/color]
> KeyDown[color=green][color=darkred]
> > > Events
> > >
> > >
> > > Tell us in human terms. - What effect do you want to achieve - for
> > > yourself, for the user?
> > >
> > > With curiousity and anticipation,
> > > Fergus.
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#13: Nov 20 '05

re: overrides help please


Hello,

"Merlin" <jeff@jg-tech.co.uk> schrieb:[color=blue]
> What does override do or when should it be used?[/color]

http://msdn.microsoft.com/library/en...ancebasics.asp
http://msdn.microsoft.com/library/en...yOverrides.asp

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet


Fergus Cooney
Guest
 
Posts: n/a
#14: Nov 20 '05

re: overrides help please


Lol, Merlin

Nice one.

Regards,
Fergus

ps. I'm only watching this one... ;-)


Armin Zingler
Guest
 
Posts: n/a
#15: Nov 20 '05

re: overrides help please


"Merlin" <jeff@jg-tech.co.uk> schrieb[color=blue]
> Ok here goes,
>
> I have created a control that has a text box and a button at the end
> of the text box, I want my control to totally emulate a text box, but
> have the added addition of a button at the end. The idea of this
> control is to allow a user to input text in the normal manner or
> press a button to display a pick list.
>
> Therefore I want the usercontrol events all overridden with the Text
> box events. As it stands If I were to place my user control on a form
> and trap the usercontrol keydown event when entering text, I'd only
> be trapping events for the user control so get nothing whereas I want
> to trap the text box events:-
>
> i.e
> instead of UserControl.TextBox1.Keydown
> I want UserControl.Keydown to be exactly the same.
>
> Hope thats clearer.[/color]

It is.

- Event bubbling: Handle the textbox' events in the usercontrol and, for
each event, raise an event in the usercontrol that can be handled outside
(lot of work).

- Make the textbox public (or friend). Outside the Usercontrol, you can use
Addhandler MyUserControlInstance.MyTextbox.Textchanged, addressof ...


--
Armin

Fergus Cooney
Guest
 
Posts: n/a
#16: Nov 20 '05

re: overrides help please


Hi Merlin, Armin,

"And the prize goes to ..... Armin Zingler - for his Event Bubbling."

The ideal purpose of a UserControl is to provide a composite Control which
conforms as far as possible to the standards of the basic Controls. This means
that the designer (you) should do as much as possible to make your UserControl
interface act as expected for a Control.

Which means do the work!!

Regards, both,
Fergus


Cor
Guest
 
Posts: n/a
#17: Nov 20 '05

re: overrides help please


Hi,
Terrific good written Jay with very good in mind the not native speaking
English people.
Cor


Closed Thread