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?
Re: Custom Contol Problem
Adding that code to my custom control did not make any difference.
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.
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.
Re: Custom Contol Problem
Quote:
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.
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
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.
Re: Custom Contol Problem
Please read the MSDN on occasions like this. It says the following:
Quote:
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.
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
Re: Custom Contol Problem
NickThissen,
the compact framework only has gotfocus and lost focus, and it has none of the rest.
Re: Custom Contol Problem
Quote:
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.
Re: Custom Contol Problem
Quote:
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 :p
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