By Fabian R Silva, - - 11/1/2007
I like to display a InfoBox, but I want to keep the focus on the active control. How I can do that? I don't find a property on the infobox that says "getFocus" or something else, thanks
|
By Peter Jones - 11/1/2007
Hi,I think InfoBox.focus is what you want. Cheers, Peter
|
By Fabian R Silva, - - 11/2/2007
Hello, thanks for reply, my english is bad and I not make good questions I try to avoid the infobox to give focus, I try to validate a textbox and show an infobox that say something, but while the infobox is displaying I like to mantain the focus on the textbox, it is posible? I try with mytextbox.focus before calling the infobox without sucess, but when I call the infobox, if I press faster click on the textbox, it get focus. I think that if I pause some millisecons and focus on textbox it can have focus but I think that's not a good idea :/ Thanks
|
By Peter Jones - 11/2/2007
Hi Fabian,Sorry for the misunderstanding. I've never used the InfoBox control so I'm not speaking from experience but, from the SF Help, I see that it has these propeties: .CanFocus - you could set this to false so it never receives focus. .GotFocus - you could trap the focus event and return focus to your text box. Cheers, Peter
|
By Fabian R Silva, - - 11/5/2007
Peter Jones (11/02/2007)
Hi Fabian, Sorry for the misunderstanding. I've never used the InfoBox control so I'm not speaking from experience but, from the SF Help, I see that it has these propeties: .CanFocus - you could set this to false so it never receives focus. .GotFocus - you could trap the focus event and return focus to your text box. Cheers, Peter Thanks for reply .CanFocus is readonly and I try to trap gotfocus with an eventhandler, but the infobox is a static class and I guess that cannot trap it I not sure what more I can try :/ thanks
|
By Trent L. Taylor - 11/5/2007
The problem you are running into is the basic window handle issue that comes up from time to time when using WinForms.The InfoBox is a window, which will take the focus away from the calling form. However, you CAN set the focus back to your main for that called the InfoBox. InfoxBox.NotifyBox(...) Me.Focus() If this doesn't work, then you can go a step further by using the WinAPI methods such as the SetActiveWindow: SetActiveWindow(Me.Handle) Ultimately you will just have to make a call to refocus your main window rather than the InfoBox. Finally, you may experience different behavior depending upon whether or not the InfoBox parent is the screen or the form. This is a parameter that can be provided when showing an InfoBox (it is the Parent parameter). If you set it to Nothing, then the InfoBox will show in the screen. Otherwise it will appear within the control or form that you specify. This may have an effect on getting the focus back as well, just FYI.
|
By Fabian R Silva, - - 11/5/2007
Thanks for reply.
Dim HWmdActiveWindow As Integer = GetActiveWindow()
MicroFour.StrataFrame.Messaging.InfoBox.NotifyBox("Notificación", "No se encontró el registro tipeado") ', Me.ParentForm
SetActiveWindow(HWmdActiveWindow)
I try from a usercontrol.textbox_keypress with me.parentform.Focus() and SetActiveWindow(me.parentform.handle) and no luck, the infoBox get the focus again
I try to use system.threading.thread.sleep with some variants and nothing...
to gain form focus I see that only works when I call the infobox and click on the form, It get focus and don't loose it again.
Any idea? thanks!
|
By StrataFrame Team - 11/6/2007
You might try this from within the form:InfoBox.NofityBox(...) Me.Activate() Me.textBox.Focus() You might even need to make a call to System.Windows.Forms.Application.DoEvents(). What it does is force all of the Windows messages that are caught up on the message pump to push through, so even if the UI thread is busy, it will pause there and process the activate and focus calls. It's worth a try. A word of warning, though... always be careful with the call to DoEvents(). It can get you into trouble more often than not. Just Google it and I'm sure you'll find some articles telling you how horrible it is.
|
By Fabian R Silva, - - 11/6/2007
Thanks for the replyI try with you suggestions (Activate, SetActiveWindow, Focus, DoEvent) but I cannot make the form got focus while the infobox is showing (except with a mouse click on the form)... If I can't make it work, I will edit the infobox source to accept a parameter with the calling form to see if I can call form.activate() or form.focus() from there and see if it get the order Thanks for the support, I known I'm try to make the stuff from another way that the framework works and it give me troubles, but I have to make the try because my boss have his needs to adapt from his FoxPro DOS App. and I are the only programmer and I convinced him to use .NET & SF
|
By StrataFrame Team - 11/7/2007
Well, I'm sorry, but I'm all out of ideas on trying to get the form to re-activate.
|
By Trent L. Taylor - 11/7/2007
Fabian,Try this just to see if it works. Use a timer to re-execute the activation of the form. The problem could be that all of this is trying to execute on the same thread and so the re-activation never takes place. Also, this is not an issue with SF, it has 100% to do with the way WinForms works. InfoBox() '-- You can reduce this to a smaller interval, but starting with 1 second will give you a good visual when it executes. MyTimer.Interval = 1000 MyTimer.Enabled = True Timer Code MyTimer.Enabled = False
'-- You might try just forcing the focus back to the control itself first. You could then try ' All of the other options previously mentioned in this thread if it doesn't work. MyControlToFocus.Focus()
|
By Fabian R Silva, - - 11/7/2007
Thanks!!! It worked ok you got the solution, I not suppose that a timer can change the things, but you clarify me it. Dim InfoboxTimer As New Timer() InfoboxTimer.Interval = 50 'the min value that work ok for me... AddHandler InfoboxTimer.Tick, AddressOf InfoboxTimer_Tick InfoboxTimer.Enabled = True MicroFour.StrataFrame.Messaging.InfoBox.DefaultTimeOut = 1000 MicroFour.StrataFrame.Messaging.InfoBox.NotifyBox("Title","description") 'Timer_Tick handler Private Sub InfoboxTimer_Tick(ByVal sender As Object, ByVal e As EventArgs) Dim Tmr As Timer = CType(sender, Timer) Tmr.Enabled = False Me.ParentForm.Activate() 'I coding on a user control... activate his form 'Me.txtCodigo.Focus() End Sub
|
By Trent L. Taylor - 11/7/2007
Good. I am glad that worked for you. At some point all developers have the "Window Handle Blues."
|
|