Userform selected control - vba

If you look at the pictures I want the white TextBox to be selected instead of the "Doorgaan" CommandButton. This is an userform. Does anyone know how I can change this?
How i want it :
How it is:

Depending how you want it to interact with the user, you can set different things.
If you don't want user to be able to Tab there then make the button property TabStop to False, otherwise change the order of the Tab by the property TabIndex.
Note you can manually "Activate" a control by the .SetFocus method in your code to make it the current activated control. e.g. TextBox1.SetFocus

You probably have the properties TabIndex = 0 for the Button and 1 for the TextBox. By default the control with the least TabIndex will have the focus. Just set TabIndex = 0 for the TextBox.

Related

Can an OLEobjects textbox be Visible but not editable?

I have certain command buttons on a WorkSheet that I want hidden until a password is entered.
I do this by having an OLEobjects textbox cover them.
The textbox is called "HideButtons" and, when visible, covers certain command buttons.
The textbox has no border and is the same colour as the background.
To see the command buttons, a password is entered and I change the textbox visibility to False.
`ActiveSheet.OLEObjects("HideButtons").Visible = True
ActiveSheet.OLEObjects("HideButtons").Visible = False`
The WorkSheet is protected to ensure users only have access to certain cells and buttons.
When 'HideButtons' is visible, and the command buttons beneath it are hidden 'HideButtons' can still have text entered in to it.
Is there any way I can prevent users entering text into the 'HideButtons' textbox?

Program does not tab through controls in the correct order

I have a form with a button which adds text boxes in addition to the 8 text boxes already on the form which are named Textbox1 through 8. When I launch the application and enter the first textbox, I can tab through all the way from 1 - 8.
When I click my button it programmatically creates a textbox below the last textbox with appropriate name such as Textbox9 for the ninth, Textbox10 for the tenth etc.
However when a textbox is added via the button, tabbing through the controls skips from the eighth, to any buttons on the form, and then to the created textbox. Any idea why this happens and how I can resolve it? I've tried google to no avail. Please let me know if you need any code, thank you.
Thanks to Daniel Cook and Grim, I solved my issue by setting the tabindex to match the textbox number, however I also found that setting TabStop to false on the buttons and controls helped me to keep the tab focus within the text boxes.

not able to set readonly property of textboxes in a panel in windows form to true in vb.net

i want to enable the read only property of all the text boxes in a panel in windows forms to true during form load but its not working. i am using the below code.when i am debugging the code it skips that part.not sure why??
The below code does not work,it skips that part as if there are no text box controls in the particular panel.
Private Sub lockgroupcontrols()
For Each TextBox As TextBox In Pnltransaction.Controls.OfType(Of TextBox)()
TextBox.ReadOnly = True
Next
End Sub
Your code seems correct, so, I can only imagine that, if it skips the For Each, then you don't have any textboxes inside the PnlTransaction panel.
Sometimes this happens when you draw the Panel over preexisting textboxes. You think the controls are inside the panel, but in reality they are under the panel and you see them because the panel background is transparent.
Try to move the panel on a different place, drag&drop the textboxes over the panel and then reposition the panel.
You shouldn't use TextBox as name for your vars
For Each **TextBox** As **TextBox** In
try it with for ex.
...For Each **tBox** As **TextBox** In
tBox.ReadOnly = True....

Default Button on Form (VB 2008)

I want to find a way to make a specific button, the form's default button,
I.e. the button that is highlighted when the form opens for the first time.
I tried the AcceptButton property but when I run the program, that does not work.
Any idea?
Thank you in advance,
Tassos
You need to change the AcceptButton property of the containing form.
form1.AcceptButton = button1
Here form1 is the Form whose default button you need to set, and button1 is the name of the Button on that form.
The form's AcceptButton and CancelButton properties define the default behaviour for the Enter and Escape keys, rather than the highlighting.
To highlight the button use the Focus method, but when doing this in the form_load event you will need to call the Select method instead.
btnDefault.Select()
As mentioned in the comments, setting the control to the lowest taborder will achieve the same thing
The answer from 'chk' on 5/2/13 is the correct answer, but is shown as a string which of course is not the way to do it.
Also, in the form's property sheet you can find, under Misc, the property 'AcceptButton'. This will give you a list of buttons on the form - just select the one you want.
The button selected as the AcceptButton will behave as the 'default' button. It will be 'highlighted' with a darker border and will be clicked when you push the Enter key on your keyboard.
Setting up an AcceptButton is different than setting the button's focus. The AcceptButton's click event will be triggered by the Enter key no matter which control has the focus on the form.
You can also do this programmatically.
I have a maintenance form where initially I want the "search" button as the form accept button.
when I'm displaying the field maintenance area, I want the "ok" button to be the accept button.
You simply change this in the appropriate areas in your code to Me.AcceptButton = MyButtonName.

How can I set the tab order in VB.NET?

I have a bunch of buttons on a form and when the person presses TAB I want the focus of the controls move in a specific order. Does anyone know how to do this?
If you have form with lots of control then manage tab index by below method:
Open form in design mode.
Click on “View” from toolbar --> “Tab Order” at bottom.
Example:
Then just click on controls one by one in order that you want to set tab order.
You can do this in the Designer as well, see Setting the TabIndex property of many form controls in Visual Studio?
Each item in your form-designer should have a TabIndex property.
Set the TabIndex in ascending order. (low-to-high)
Change the TabIndex property of your controls and enumerate them according to your need.