InfoBox and focus on the form


Author
Message
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Good.  I am glad that worked for you.  At some point all developers have the "Window Handle Blues." Hehe
Fabian R Silva, -
Fabian R Silva, -
StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)
Group: StrataFrame Users
Posts: 153, Visits: 1.2K
Thanks!!! It worked ok you got the solution, I not suppose that a timer can change the things, but you clarify me it. BigGrin

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


Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
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()

StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Well, I'm sorry, but I'm all out of ideas on trying to get the form to re-activate. 
Fabian R Silva, -
Fabian R Silva, -
StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)
Group: StrataFrame Users
Posts: 153, Visits: 1.2K
Thanks for the reply

I 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 Smile

StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
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.

Fabian R Silva, -
Fabian R Silva, -
StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)
Group: StrataFrame Users
Posts: 153, Visits: 1.2K
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!

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
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.

Fabian R Silva, -
Fabian R Silva, -
StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)
Group: StrataFrame Users
Posts: 153, Visits: 1.2K
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 Sad 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

Peter Jones
Peter Jones
Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)Advanced StrataFrame User (504 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
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

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search