Click here to Skip to main content
11,576,293 members (60,946 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hi,

I want to know Which event fires when vb.net form lost it's focus? I am using Krypton Navigator.

I am using the following code to show a form.
private sub showForm(byval pform as form
Dim kryPage As New KryptonPage
 
Me.kryNavi.Pages.Add(kryPage)
 
With pform
 
.TopLevel = False
 
.Parent = kryPage
 
.Dock = DockStyle.Fill
 
.BringToFront()
 
.Show()
 
.Activate()
 
End With
 
end sub

I am using the above code to show a form.

Reply Quote
Posted 4-Dec-12 19:16pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This issue can really be confusing. Formally, the form has focus-related properties, but in a very different way than controls.

The "focus" always means keyboard focus, and it is something functional for focusable controls, not forms. A form is activated or deactivated, and when it is activated, the focus goes to the control which was focused before is any.

So, you can handle the events when each control is focused, or, you rather need to handle the event System.Windows.Forms.Form.Activated or System.Windows.Forms.Form.Deactiveate. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.activated.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.deactivate.aspx[^].

—SA
  Permalink  
v2
Comments
Espen Harlinn at 5-Dec-12 18:11pm
   
5
Sergey Alexandrovich Kryukov at 5-Dec-12 21:58pm
   
Thank you, Espen.
--SA
kgmmurugesh at 7-Dec-12 5:36am
   
I vb6, when we close a form it fires form_unload event, when we show a form it fires form_load, form_Activate event, when the user goes from form A to another form then he return to the form A, it fires form_activate event. I need the equivalent event in vb.net
Sergey Alexandrovich Kryukov at 7-Dec-12 14:19pm
   
Why are you asking about VB6 at all? I rather would reply "forget it"... Your question was about VB.NET, so consider accepting the answer formally (green button) -- thanks.
--SA
kgmmurugesh at 8-Dec-12 4:43am
   
My actual requirement is to note the active control of a form when user go to another form without closing the current form.
Sergey Alexandrovich Kryukov at 8-Dec-12 23:28pm
   
Define "to note". Anyway, I answered your initial question, don't you see it?
Anyway, there is nothing to do. If you activate any form, its previously focused control gets focus.
--SA
kgmmurugesh at 10-Dec-12 0:35am
   
No, Your answer is not working. If you need the coding to check i will send it.
Sergey Alexandrovich Kryukov at 10-Dec-12 1:14am
   
No, I don't need it. My answer is working; are you kidding? -- the problem is too simple to unsure. You are doing something wrong, that's it.
--SA
kgmmurugesh at 10-Dec-12 1:17am
   
No Sir, It is not working.
Sergey Alexandrovich Kryukov at 10-Dec-12 16:34pm
   
It's your code is not working, not my advice.

OK, then you need to show some code sample. There are many ways to screw up things, and I don't know your way... :-)
The problem is really trivial. So, please create and test some code sample. Explain what you wanted to achieve by what means, what it was supposed to do, what did you observe in reality and why do you think it's wrong. I'll help you to fix it.
--SA
kgmmurugesh at 11-Dec-12 3:10am
   
Use the following link to download my project & Krypton Tools.

http://sdrv.ms/XMNTak
Sergey Alexandrovich Kryukov at 11-Dec-12 11:16am
   
No, thank you; this is too long way. Can you make a code sample focusing only on one problem?
--SA
kgmmurugesh at 11-Dec-12 23:21pm
   
I want to write some code when the form lost it focus, while i am using krypton navigator.
Sergey Alexandrovich Kryukov at 11-Dec-12 23:40pm
   
Is that is? Handle the event System.Windows.Forms.Form.Deactiveate.
Execute it under debugger to make sure your handler is really called.
If it is not, check up if the handler is really added to the invocation list of this event instance. Add code to the handler.

If you think it does not work, show these two fragments of your code. Or do you want me to show how to handle an event?
--SA
kgmmurugesh at 11-Dec-12 23:42pm
   
I checked all the options, if i am not using krypton navigator it works well otherwise it doesn't work.
Sergey Alexandrovich Kryukov at 11-Dec-12 23:48pm
   
You never mentioned that the problem is only with the use of Krypton navigator...
Are you handling the Deactivate event of the form, or something else? Are you sure you really deactivate the form? Are you sure your handler is really not called? using the debugger?

As this is a navigation-related component, it could intervene in the form operation, but... I still cannot imagine how this event could be disrupted... I think it should work as usual.
--SA
kgmmurugesh at 11-Dec-12 23:56pm
   
Yes the problem is only with the use of krypton navigator.
Sergey Alexandrovich Kryukov at 11-Dec-12 23:56pm
   
You see, your "does not work" is not informative. You need to tell what exactly happens. If you explicitly tell that your handler is not called under debugger, I would consider it as "not working" (so far, I hardly can believe in that)...
--SA
kgmmurugesh at 11-Dec-12 23:59pm
   
Nothing happens, if you have any more doubts download and run my project.
Sergey Alexandrovich Kryukov at 12-Dec-12 0:02am
   
You see, you are the one who is interested in resolution, not me. Therefore, will you please take a labor of running it under the debugger and checkup that the execution reaches required point? This is up to your, of course, but...
--SA
kgmmurugesh at 12-Dec-12 0:08am
   
I already checked, the form_deactivate event not fires when i close or go to another form.
Sergey Alexandrovich Kryukov at 12-Dec-12 0:20am
   
There is not such event "form_deactivate". You are not telling me that a handler is not called in a convincing way. You did not confirm that you checked it up under debugger (optionally: used system log), not any other way...
--SA
kgmmurugesh at 13-Dec-12 1:10am
   
Private Sub Form2_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Deactivate

gAryFormControl(2) = Me.ActiveControl
Mdi.Text = Mdi.Text & "2 DE"
End Sub

is the above is form_deactivate event?
Sergey Alexandrovich Kryukov at 13-Dec-12 1:18am
   
No, there is no such event; the event is System.Windows.Forms.Deactivate, and your method is an event handler; an event instance is the object of some class which supports the collection of handlers...

But this code fragment looks correct... and what, if you set a breakpoint at "gAryFormControl(2) = ..." the execution never stop at that line..? Would be strange...

--SA
kgmmurugesh at 13-Dec-12 1:41am
   
i checked it many more times, it will not work when i am using krypton navigator, It works well when i am not using krypton navigator.
Sergey Alexandrovich Kryukov at 13-Dec-12 1:50am
   
One questionable thing is the use of MDI... Are you deactivating an MDI child (I don't think you mentioned it before)? Can you try with regular windows (MDI is generally evil, best avoided...)?
--SA
kgmmurugesh at 13-Dec-12 2:12am
   
Ok, Thanks. I must need MDI and Krypton Navigator.
Sergey Alexandrovich Kryukov at 13-Dec-12 12:19pm
   
I can believe that you might need Krypton Navigator, but nobody really need MDI. This design style was proven so bad that Microsoft is doing hard work to phase it out. You don't want to scare off your user and give yourself development nightmare. Many user will deny working with software just because this is MDI. Alternatives (TabControl is the nearest) are way easier to develop and more convenient...
--SA
kgmmurugesh at 14-Dec-12 0:08am
   
Ok, I will inform you after checking it without using mdi.
Sergey Alexandrovich Kryukov at 14-Dec-12 0:18am
   
Good.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 295
1 F-ES Sitecore 140
2 OriginalGriff 125
3 Dave Kreskowiak 80
4 Abhinav S 78
0 OriginalGriff 705
1 Sergey Alexandrovich Kryukov 630
2 Abhinav S 438
3 F-ES Sitecore 410
4 Suvendu Shekhar Giri 365


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 5 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100