We help IT Professionals succeed at work.

Forcing Focus on VB Frame

GarySB
GarySB asked
on
I am displaying a Frame that contains a question with two command buttons below it.
End & Continue
This frame is over my Form with many other choices on it.  
How can i force the user to select End or Continue before they are able to click on anything else and not bypass my question, Thank you
Comment
Watch Question

Martin LissSocial distance - Don't touch your face - Wash your hands for 20 seconds
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
So this is like a MsgBox but on a form? If so why not display a separate form that has the same things as your form and show the new form with vbModal so that you user can't do anything until a button is clicked?
Martin LissSocial distance - Don't touch your face - Wash your hands for 20 seconds
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
If that's not satisfactory then try this. The code in Command1 restricts the cursor to the frame and Command2 (which should be in the frame) releases it.


Option Explicit
Private Type RECT
    left As Long
    top As Long
    right As Long
    bottom As Long
End Type

Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long
Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, lpRect As RECT) As Long

Private Sub Command1_Click()
' Confines the cursor to inside of Frame1

Dim r As RECT ' confinement rectangle

GetWindowRect Frame1.hwnd, r ' put window's coordinates into r
ClipCursor r ' confine the cursor to the boundries defined in r
End Sub

Private Sub Command2_Click()
' Unconfine the cursor

ClipCursor ByVal 0&

End Sub

Open in new window

Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009

Commented:
The user could still choose others things using the keyboard...

You can simply disable everything else using the Enabled() property, and then turn them back on after the user has make a choice.

Author

Commented:
I am displaying on first run only, my software license in a richtext box in the frame with my two buttons.  I have to have someway ot making sure that they select one of the two choices before the main program runs.  Install shield is to fancy for me right now, so I will be zipping my package after compiling with VB.
Also, I made my About information on a seperate small form.  You are suggesting that I do the same with this and set vbmodal to a certain value?  What?
If I do that, will they be able to click on another one of my forms/command buttons?
Social distance - Don't touch your face - Wash your hands for 20 seconds
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
If you do
Show MyForm vbModal

Open in new window

and the user can't do anything on any other form until MyForm is closed.
Martin LissSocial distance - Don't touch your face - Wash your hands for 20 seconds
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Sorry, ignore the 'and' in that sentence.

Author

Commented:
Thank You!

Author

Commented:
One last thing-
What should i use to properly close the form?
.Hide?
Unload?
Both or something else?
Thanks
Martin LissSocial distance - Don't touch your face - Wash your hands for 20 seconds
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Hide just hides it from view. To get rid of it use Unload.

Author

Commented:
Thanks Again
Martin LissSocial distance - Don't touch your face - Wash your hands for 20 seconds
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You're welcome.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.