I am passing a form to a printing sub using Public Sub PrintForm(ByRef frmFrom as Form). I then call this form to print and all works well except txtBox1 is highlighted in the printed form. When I tried to deselect it using frmFrom.Controls("txtBox1").SelectionStart = frmFrom.Controls("txtBox1").Text.Length I get an error that txtBox1 Represents text as a sequence of UTF-16 code units and SelectionStart is not a member of "Control". I am able to manipulate several other buttons (turning them off to print) but can't seem to unhighlight the Focused textbox. Any ideas would certainly be appreciated.
Asked
Active
Viewed 42 times
0
-
Why is the parameter of the `PrintForm` method declared `ByRef`? Are you assigning something to that parameter inside the method? If not, there's no reason to declare it `ByRef`. `ByVal` is the default for a reason. – jmcilhinney Apr 14 '20 at 00:13
-
Just updated: [How to print hidden and visible content of a Container with ScrollBars](https://stackoverflow.com/a/57309095/7444103) – Jimi Apr 14 '20 at 03:26
1 Answers
1
Is that TextBox
the first selectable control in the Tab order? If so, it will get focus by default when the form is displayed. The Shown
event is raised immediately after the form is displayed. That is probably where you should be initiating the printing from and that is also where you can set the form's ActiveControl
to Nothing
, meaning that no control will have focus, meaning that a TextBox
will not show highlighted text even if text is selected.

jmcilhinney
- 50,448
- 5
- 26
- 46
-
-
If an answer has solved your issue, please accept it by clicking the big check mark. That will show anyone viewing the thread, directly or in a list, that you no longer need help. This site is all about the questions and answers too, so you are not supposed to add comments saying "think you" or the like. accepting or up-voting answers is how you thank the people who posted them. – jmcilhinney Apr 15 '20 at 01:25