For example, I had a button, but I disabled it in FormLoad. Now a radio button gets activated for no apparant reason...How do I control what gets focus and what doesent?
Printable View
For example, I had a button, but I disabled it in FormLoad. Now a radio button gets activated for no apparant reason...How do I control what gets focus and what doesent?
use the .SetFocus
like text1.setfocus
its done by the tab order
but do it in the Activate Event rather than the Load.
what if there are no members that I like that have that property, how do I stop anything from being activated?
-----Leave Activate empty :thumb:
wait...no, thats not completely right... can someone clear this up for me? how does VB single out the one button I DO NOT want clicked, and clicks it at load?
Whats going on? I cant even debug this, because when I do - everything works smooth, but if I press run it goes straight for OptionButton_Click(Index As Integer) with a preset index out of nowhere...
If you don't want to see anything gets focus when the form loads, create a Dummy text box, that has :
tab_index=0, enabled=true, locked=true,
width=0, left=0, border=transparent (or put it outside of viewable area.)
TabIndex=0. Whichever control has that property set will be the first to get focus, assuming it is enabled and can get the focus. Otherwise then next control in the tab order will get the focus if it can... Controls that can't receive focus are those that are invisible, those without an hWnd property (i.e., label, image control) and those that are disabled or are in a disabled container.Quote:
Originally Posted by unxzst
Put all your controls on that form in a frame. Set it to borderless and no caption. Then disable the frame and all controls in it will be disabled but look normal.
Or simply putQuote:
Originally Posted by RobDog888
Option1.Value = False
Option2.Value = False
etc in the form's Activate event.
@RodDog, your way will make it "look normal" but all controls are disabled, you will need code to enable them.
I think the OP wants no control gets focus when open the form but they must be enabled as normal and ready to be clicked.
By default, as LaVolpe said, the first enabled control (in tab order), if any, will receive focus when the form open, if no enabled control the form will receive focus.
That code would just beQuote:
Originally Posted by anhn
Frame1.Enabled = True
I think if the OP tells us what controls are on the form and what is to be non-selected at form load/activate then it may be easier to suggest. If all controls will need to be deselected or just a few then its easy to just set them all to False or whatever for each control in the activate event. We dont know what the OP is ultimately trying to achieve.
@MartinLiss,
Yes, I know it just be "Frame1.Enabled = True" but where to put it and when it will be run. After enable Frame1, the problem will come back.
It could easily be placed in a button click event if the button is not in the frame but we have no idea what the OP wants / needs so its all unsolveable for now.
Try it and you'll see that when you enable the frame the option buttons value(s) will not be set to True.Quote:
Originally Posted by anhn