|
-
May 7th, 2009, 01:28 PM
#1
Thread Starter
Junior Member
Custom Contol Problem
I am working on a custom control and i have it working for the most part, but what i want to do now is, on the form that i put my custom control, i want to fire an event when my custom control gets focus. so what i did was just added an event
Code:
Private Sub CustCont1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles CustCont1.GotFocus
the problem is, is that when i put a breakpoint on this line i never hit the breakpoint. is there something special i need to code in my customcontrol to fire the gotfocus and lostfocus events?
BTW this is in the Compact Framework 3.5
thanks
doug
Last edited by dougg; May 7th, 2009 at 02:05 PM.
-
May 7th, 2009, 01:58 PM
#2
Junior Member
Re: Custom Contol Problem
You need to override the events from the base class.
vb Code:
Protected Overrides Sub OnGotFocus(ByVal e As System.EventArgs) MyBase.OnGotFocus(e) 'insert code here End Sub
*edit*
I just realized I misinterpreted what you wrote. Although you could try overriding it from within the control to see if it gets fired. What type of class are you inheriting the custom control from?
Last edited by insomnicoder; May 7th, 2009 at 02:04 PM.
Reason: misread
-
May 7th, 2009, 02:04 PM
#3
Thread Starter
Junior Member
Re: Custom Contol Problem
Adding that code to my custom control did not make any difference.
-
May 7th, 2009, 02:07 PM
#4
Thread Starter
Junior Member
Re: Custom Contol Problem
i am not inheriting from any from anything.
all my custom control is is a panel on the custom control. want a control that i can draw on.
-
May 7th, 2009, 02:11 PM
#5
Re: Custom Contol Problem
Whenever a control on your custom control gets focus, you need that control's GotFocus event to fire your custom controls GotFocus Event.
-
May 7th, 2009, 02:14 PM
#6
Thread Starter
Junior Member
Re: Custom Contol Problem
 Originally Posted by Campion
Whenever a control on your custom control gets focus, you need that control's GotFocus event to fire your custom controls GotFocus Event.
the only control on my custom control is a panel and that never gets a gotfocus event fired.
-
May 7th, 2009, 02:23 PM
#7
Junior Member
Re: Custom Contol Problem
You're right. I just tried the panel and even though it has the got focus event it does not fire. It's not typically a control that receives input directly though.
If you create a class that just inherits from the UserControl it seems to work and you can draw on it. You could even do your drawing from within the FocusPanel class if you wanted.
vb Code:
Public Class FocusPanel Inherits UserControl End Class
-
May 7th, 2009, 02:31 PM
#8
Thread Starter
Junior Member
Re: Custom Contol Problem
insomicoder, i don't quite follow. i added the focus panel class and added that to my form but i still dont get the events when i click in the control to start drawing. if i have a textbox on the form as well as the custom control, and i put the focus to the textbox and get the cursor for typing, even when i draw on my custom control, the cursor stays in the text box.
if i add a button control to my custom control i can get the got focus event to fire, but i dont want any other controls on the customcontrol besides the panel.
-
May 7th, 2009, 02:55 PM
#9
Re: Custom Contol Problem
Please read the MSDN on occasions like this. It says the following:
 Originally Posted by MSDN
Note The GotFocus and LostFocus events are low-level focus events that are tied to the WM_KILLFOCUS and WM_SETFOCUS Windows messages. Typically, the GotFocus and LostFocus events are only used when updating UICues or when writing custom controls. Instead the Enter and Leave events should be used for all controls except the Form class, which uses the Activated and Deactivate events.
http://msdn.microsoft.com/en-us/libr....gotfocus.aspx
So try using the Enter event, see if that works.
-
May 7th, 2009, 02:56 PM
#10
Junior Member
Re: Custom Contol Problem
The focus event of the user control only seems to fire when you hit tab. But you can set it's focus when it is clicked.
Code:
Private Sub FocusPanel1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FocusPanel1.Click
If Not FocusPanel1.Focused Then FocusPanel1.Focus()
End Sub
-
May 7th, 2009, 02:57 PM
#11
Thread Starter
Junior Member
Re: Custom Contol Problem
NickThissen,
the compact framework only has gotfocus and lost focus, and it has none of the rest.
-
May 7th, 2009, 02:59 PM
#12
Junior Member
Re: Custom Contol Problem
 Originally Posted by insomnicoder
The focus event of the user control only seems to fire when you hit tab. But you can set it's focus when it is clicked.
Code:
Private Sub FocusPanel1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FocusPanel1.Click
If Not FocusPanel1.Focused Then FocusPanel1.Focus()
End Sub
I think that will also work for just the regular panel too.
-
May 7th, 2009, 03:01 PM
#13
Re: Custom Contol Problem
 Originally Posted by dougg
NickThissen,
the compact framework only has gotfocus and lost focus, and it has none of the rest.
Sorry, I did not see you were referring to the compact framework. Maybe you should have made that more evident in your first post instead of a small 'btw' if it's as important as now
-
May 7th, 2009, 03:10 PM
#14
Thread Starter
Junior Member
Re: Custom Contol Problem
i think i may have somehting working here. i am going to roll it out of my test project and into my live app and test. if i have anything else i will resume this thread.
thanks again
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|