The cursor is not positioned in the middle of the text box after setfocus

rap

New Member
Joined
May 5, 2023
Messages
2
Office Version
  1. 2013
Platform
  1. Windows
Hi Guys,

Can anyone help me with this problem.

Once I press the Tab button inside a text box, the cursor must be positioned in another text box. I used setfocus command to do it. However, once the cursor is on the other text box it is not at the center. It appears that a tab space is introduce hence it is not on the center of the textbox. I have already set the property of the text box's Text Align to fmTextAlignCenter and yet everytime the second text box has the focus it is not at the center but rather after the tab space that was introduced.

Thanks guys, hope to hear from you soon.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
In the event code you apparently have but did not show, when you set the focus to Textbox2 (or whatever its name is) try also
TextBox2.SelStart = Int(Len(TextBox2) / 2)
If the control is empty it should not error. If it contains an odd number of characters, the cursor should end up just left of what center would otherwise be.
 
Upvote 0

Forum statistics

Threads
1,224,604
Messages
6,179,857
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top