Highlight textbox

Smee

Well-Known Member
Licensed User
Longtime User
I am not sure how to explain this but i know that it can be done.
What i want to do is highlight the text in a textbox so that a user can still see what is there but if they start to type the new input will overwrite the existing text.

I have done it in VB using sendkeys(Home and END) etc. Can anyone advise some simple code to accomplish this?

Thanks

Joe
 

harry5568

Member
Its fairly simple..Go to Designer-- Form and click on your textbox.
In the Text option,type the text you want.
It'll show everytime your appl starts.When you start typing,its overwritten.
IS THIS WHAT YOU WANTED?..harry
 

klaus

Expert
Licensed User
Longtime User
When the user clicks 2 times onto the TextBox the text is highlighted and the next text is overwritten.

I remember having done what you want in VB, with
TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Text)

but, in .NET
TextBox1.SelectionStart = 0
TextBox1.SelectionLength = StrLength(TextBox1.Text)

this doesn't work the same way, the text is not highlighted.

Best regards.
 

Smee

Well-Known Member
Licensed User
Longtime User
Thanks Klaus,

Yes this is the effect i want to perform in code. Is there a work around that will perform the effect i want that is similar to the double click effect?
 

konisek

Member
Licensed User
Longtime User
A very simple question - how can I "copy" a highlighted text from a textbox to another place in PDA (or to the same textbox)? "Tap and hold" does not work.
 

klaus

Expert
Licensed User
Longtime User
Hi Smee,

No, I haven't found a workaround for this.
I have tried quite some different methods but none did work, so now I am used to the double click which is the standard Windows behaviour.

When you jump from one object to the other with the Tab key the text is highlighted by default.

Best regards.
 

Smee

Well-Known Member
Licensed User
Longtime User

Klaus, this seems to work

I exit a textbox to a combobox which scrolls through a list looking for a match and then the focus is sent back to the textbox which has the commands;

Sub txtCustomer_GotFocus
txtCustomer.SelectionStart = 0
txtCustomer.SelectionLength = StrLength(txtCustomer.Text)
End Sub

and voila it does highlight the box as required. I am using CE 5 if this makes a difference or not i dont know, but hey, it DOES work


Joe
 

klaus

Expert
Licensed User
Longtime User
If you set in a ComboBox_SelectionChanged routine
txtCustomer.Focus
the text in the TextBox is highlighted even if you don't have the txtCustomer_GotFocus routine.
But if you have several TextBoxes on a form and the user clicks onto one of those the text is not highlighted even with a GotFocus routine as you show, but this worked with VB.

Best regards.
 

dlfallen

Active Member
Licensed User
Longtime User
You can highlight the text when clicking into a textbox (even with multiple text boxes) if you embed the focus code within a click event added with the door library. Here is a working example with three textboxes.
There are three text boxes named TextBox1 TextBox2, & TextBox3, a door object object named "Obj", and three door object events named TB1Click, TB2Click, and TB3Click.

Sub App_Start
Form1.Show
For i = 1 To 3
obj.New1(False)
obj.FromControl("Main.TextBox" & i)
Control("TB" & i & "Click").new1(obj.Value,"Click")
Next i
End Sub

Sub TB1Click_NewEvent
TextBox_Click(Sender)
End Sub

Sub TB2Click_NewEvent
TextBox_Click(Sender)
End Sub

Sub TB3Click_NewEvent
TextBox_Click(Sender)
End Sub

Sub TextBox_Click(TBnum)
TBnum = SubString(TBnum,2,1)
Control("Textbox" & TBnum).SelectionStart = 0
Control("Textbox" & TBnum).SelectionLength = StrLength(Control ("Textbox" & TBnum).Text)
Control("Textbox" & TBnum).focus
End Sub
 

klaus

Expert
Licensed User
Longtime User
Hi Dave,

I tested your code, but there are 2 problems:

1) Unfortunately the code doesn't work on my device (htc Touch HD) as expected, the text is not highlighted. Optimized compiled nor in the device IDE.

2) When optimized compiling, line
Control("TB" & i & "Click").new1(obj.Value,"Click")

must be
Control("TB" & i & "Click",Event).new1(obj.Value,"Click")

otherwise the compiler is throwing an error.

Best regards.
 

dlfallen

Active Member
Licensed User
Longtime User
Klaus,
Yes, I also had to change the statement to
Control("TB" & i & "Click",Event).new1(obj.Value,"Click")
when compiling for the device.

I'm still puzzled why it doesn't work. What I did discover, is that the added click event is not firing on the device. I discovered this when I added a TextBox4, and in the Sub TB1Click_NewEvent I added
TextBox4.Text = "H"
Alas, the Textbox4 text never changes!

The other thing that is puzzling is that in another program I am writing, I use:
CellClick0.New1(obj.Value,"Click")
where I don't specify the object type, yet it compiles without error and runs just fine on the device.

-Dave
 

agraham

Expert
Licensed User
Longtime User
What I did discover, is that the added click event is not firing on the device.
I am afraid that there is no Click, nor any of the Mouse events, implemented on the device TextBox.
where I don't specify the object type, yet it compiles without error and runs just fine on the device
That's because you aren't using the Control keyword but are specifying the object directly so the compiler knows the type. For the Control function, because the type of the control would need to be derived from the parameter, it is easier on the compiler to explicitly specify it.
 

Simontelescopium

Member
Licensed User
A very simple question - how can I "copy" a highlighted text from a textbox to another place in PDA (or to the same textbox)? "Tap and hold" does not work.

What I do is open the SIP and then press Ctrl & C this puts the highlighted text into the clipboard and is available anywhere just use paste or ctrl & v
 

dlfallen

Active Member
Licensed User
Longtime User
Work Around

If the goal is to highlight and replace the text anytime a textbox receives focus, then a simple work-around would be:

Sub Globals
'Declare the global variables here.
TextNormalColor = cWhite
TextHighlightColor = cCyan
End Sub
Sub App_Start
Form1.Show
AddTextBox("Form1","TextBox1",75,40,75,22,"ABCDEF")
AddTextBox("Form1","TextBox2",75,80,75,22,"ABCDEF")
AddTextBox("Form1","TextBox3",75,120,75,22,"ABCDEF")
End Sub
Sub TextBox1_GotFocus
TextBox1.Color = TextHighlightColor
End Sub

Sub
TextBox1_LostFocus
TextBox1.Color = TextNormalColor
End Sub

Sub
TextBox1_KeyPress(Key)
If TextBox1.Color = TextHighlightColor Then TextBox1.Text = ""
TextBox1.Color = TextNormalColor
End Sub

Add similar subs for other text boxes.
 

dlfallen

Active Member
Licensed User
Longtime User
I am afraid that there is no Click, nor any of the Mouse events, implemented on the device TextBox.

I am confused by this (my shortcoming, not yours). Are you saying the Click event is not supported by Compact Framework, hence not available on the device? I checked on MSDN and as near as I can tell, the Click event is not supported for the Label control either. Yet I can add a Click event to a Label with the Door.dll -- an event that works on the device. What's the difference between the two? I guess my confusion is over the word "implemented".

-Dave
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…