473,480 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Stopping text from highlighting in textbox

Is there a way of stopping text from highlighting in textbox?
Many thanks,
Adrian.
Jun 3 '07 #1
14 13307
On Jun 3, 10:09 pm, "Adrian <" <x...@xx.xxwrote:
Is there a way of stopping text from highlighting in textbox?
Many thanks,
Adrian.
You mean to ask, we should be able to select the complete text?..Pls
clarify.

Jun 3 '07 #2
On Jun 3, 10:09 pm, "Adrian <" <x...@xx.xxwrote:
Is there a way of stopping text from highlighting in textbox?
Many thanks,
Adrian.
You mean to ask, we should not be able to select the complete
text?..Pls
clarify.

Jun 3 '07 #3
Supposing I have a textbox with a text. Then as soon as - later on - I do
something in the same textbox, with the text still there, say I want to
click the textbox for some action, I risk some of the text getting
"highlight". I want to stop that from happening.

Adrian.

"Aneesh P" <an******@gmail.comwrote in message
news:11**********************@d30g2000prg.googlegr oups.com...
On Jun 3, 10:09 pm, "Adrian <" <x...@xx.xxwrote:
Is there a way of stopping text from highlighting in textbox?
Many thanks,
Adrian.

You mean to ask, we should not be able to select the complete
text?..Pls
clarify.

Jun 3 '07 #4
On Jun 4, 12:11 am, "Adrian <" <x...@xx.xxwrote:
Supposing I have a textbox with a text. Then as soon as - later on - I do
something in the same textbox, with the text still there, say I want to
click the textbox for some action, I risk some of the text getting
"highlight". I want to stop that from happening.

Adrian.

"Aneesh P" <anees...@gmail.comwrote in message

news:11**********************@d30g2000prg.googlegr oups.com...
On Jun 3, 10:09 pm, "Adrian <" <x...@xx.xxwrote:
Is there a way of stopping text from highlighting in textbox?
Many thanks,
Adrian.
You mean to ask, we should not be able to select the complete
text?..Pls
clarify.- Hide quoted text -

- Show quoted text -
I don't see a way to restrict the highlighting. But in the Click Event
and Double Click event we deselect the selected text. So the behavior
will be like - the text will be selected for a fraction of second and
deselected.

private void textBox1_Click(object sender, EventArgs e)
{
textBox1.DeselectAll();
}

private void textBox1_DoubleClick(object sender, EventArgs e)
{
textBox1.DeselectAll();
}
Jun 4 '07 #5
Hi,

Maybe it's out of the posts' scope but you can try to hook the text
box, catch for example the mouse click message and not forward the
message. This might prevent the further behavior of the message
(highlighting for example).
Maybe you can *save* the highglight prior to the event and set it
again afterwards (this may cause the UI not look good)...

I am not aware of and text highlight disabling option in the TextBox
control class.

Feel free to ask any further questions.

Cheers,
Moty.

Jun 4 '07 #6
I am not aware of and text highlight disabling option in the TextBox
control class.

Feel free to ask any further questions.
Thank you.

Adrian.
Jun 4 '07 #7
private void textBox1_Click(object sender, EventArgs e)
{
textBox1.DeselectAll();
}

private void textBox1_DoubleClick(object sender, EventArgs e)
{
textBox1.DeselectAll();
}

This will do the trick I guess.
I am very pleased with your solution.
Thank you for responding.

Adrian
Jun 4 '07 #8

"Adrian <" <x@xx.xxwrote in message
news:46**********************@dreader2.news.tiscal i.nl...
private void textBox1_Click(object sender, EventArgs e)
{
textBox1.DeselectAll();
}

private void textBox1_DoubleClick(object sender, EventArgs e)
{
textBox1.DeselectAll();
}

This will do the trick I guess.
I am very pleased with your solution.
Thank you for responding.

Adrian

No it didn't do the trick :( ...
Can the forecolor of the selected text be changed?

Adrian.
Jun 4 '07 #9
On 3 Jun, 20:11, "Adrian <" <x...@xx.xxwrote:
Supposing I have a textbox with a text. Then as soon as - later on - I do
something in the same textbox, with the text still there, say I want to
click the textbox for some action, I risk some of the text getting
"highlight". I want to stop that from happening.

Adrian.

"Aneesh P" <anees...@gmail.comwrote in message

news:11**********************@d30g2000prg.googlegr oups.com...
On Jun 3, 10:09 pm, "Adrian <" <x...@xx.xxwrote:
Is there a way of stopping text from highlighting in textbox?
Many thanks,
Adrian.
You mean to ask, we should not be able to select the complete
text?..Pls
clarify.- Hide quoted text -

- Show quoted text -
Can you please expalin how some of the text getting hightlighted when
you are still in same textbox. Is it the case that user press Shift
key when they click it somewhere else. If this is the case then trap
the kepress event and check of code for shift key and then set
deselectall.

Jun 4 '07 #10
Can you please expalin how some of the text getting hightlighted when
you are still in same textbox.
Supposing I have a textbox with a text. Then as soon as - later on - I do
something in the same textbox, with the text still there, say I want to
click the textbox for some action, I risk some of the text getting
"highlight". I want to stop that from happening.

Adrian.
Jun 4 '07 #11
On Mon, 04 Jun 2007 06:10:18 -0700, Adrian < <x@xx.xxwrote:
>Can you please expalin how some of the text getting hightlighted when
you are still in same textbox.

Supposing I have a textbox with a text. Then as soon as - later on - I do
something in the same textbox, with the text still there, say I want to
click the textbox for some action, I risk some of the text getting
"highlight". I want to stop that from happening.
Do you want to disable all mouse interaction with the control except for
the click? Or do you want to still preserve the ability to move the
insertion caret with the mouse?

It seems to me that either way, you should be able to do what you want by
overriding the OnMouse... methods() in the control. It does mean you have
to create your own custom control that inherits from TextBox, but it
should work fine. If you want to disable all mouse interaction, then
simply write the overrides and then do nothing in them. If you just want
to disable selection, then you may be able to do that by making the
OnMouseDown() method do nothing, and then in OnMouseUp() call both the
base OnMouseDown() method and the base OnMouseUp() method with the same
event args (so that it looks to the base class as if the mouse was clicked
in a single spot).

I will reiterate my usual warning against unnecessarily disabling or
changing standard functionality. But if you have a genuinely important
need to do this, I think the above might work.

Pete
Jun 4 '07 #12
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Mon, 04 Jun 2007 06:10:18 -0700, Adrian < <x@xx.xxwrote:
Can you please expalin how some of the text getting hightlighted when
you are still in same textbox.
Supposing I have a textbox with a text. Then as soon as - later on - I
do
something in the same textbox, with the text still there, say I want to
click the textbox for some action, I risk some of the text getting
"highlight". I want to stop that from happening.

Do you want to disable all mouse interaction with the control except for
the click? Or do you want to still preserve the ability to move the
insertion caret with the mouse?

It seems to me that either way, you should be able to do what you want by
overriding the OnMouse... methods() in the control. It does mean you have
to create your own custom control that inherits from TextBox, but it
should work fine. If you want to disable all mouse interaction, then
simply write the overrides and then do nothing in them. If you just want
to disable selection, then you may be able to do that by making the
OnMouseDown() method do nothing, and then in OnMouseUp() call both the
base OnMouseDown() method and the base OnMouseUp() method with the same
event args (so that it looks to the base class as if the mouse was clicked
in a single spot).

I will reiterate my usual warning against unnecessarily disabling or
changing standard functionality. But if you have a genuinely important
need to do this, I think the above might work.

Pete
Thank you, I will have a go at that.

Adrian.
Jun 4 '07 #13

"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Mon, 04 Jun 2007 06:10:18 -0700, Adrian < <x@xx.xxwrote:
Can you please expalin how some of the text getting hightlighted when
you are still in same textbox.
Supposing I have a textbox with a text. Then as soon as - later on - I
do
something in the same textbox, with the text still there, say I want to
click the textbox for some action, I risk some of the text getting
"highlight". I want to stop that from happening.

Do you want to disable all mouse interaction with the control except for
the click? Or do you want to still preserve the ability to move the
insertion caret with the mouse?

It seems to me that either way, you should be able to do what you want by
overriding the OnMouse... methods() in the control. It does mean you have
to create your own custom control that inherits from TextBox, but it
should work fine. If you want to disable all mouse interaction, then
simply write the overrides and then do nothing in them. If you just want
to disable selection, then you may be able to do that by making the
OnMouseDown() method do nothing, and then in OnMouseUp() call both the
base OnMouseDown() method and the base OnMouseUp() method with the same
event args (so that it looks to the base class as if the mouse was clicked
in a single spot).

I will reiterate my usual warning against unnecessarily disabling or
changing standard functionality. But if you have a genuinely important
need to do this, I think the above might work.

Pete
It didn't work I'm afraid to say.

Adrian.
Jun 5 '07 #14
On Tue, 05 Jun 2007 12:03:26 -0700, Adrian < <x@xx.xxwrote:
>you should be able to do what you want by
overriding the OnMouse... methods() in the control. It does mean you
have
to create your own custom control that inherits from TextBox, but it
should work fine. If you want to disable all mouse interaction, then
simply write the overrides and then do nothing in them. If you just
want
to disable selection, then you may be able to do that by making the
OnMouseDown() method do nothing, and then in OnMouseUp() call both the
base OnMouseDown() method and the base OnMouseUp() method with the same
event args (so that it looks to the base class as if the mouse was
clicked
in a single spot).
[...]

It didn't work I'm afraid to say.
Sorry about that. The theory was sound, but it turns out (unbeknownst to
me) that the TextBox class does not actually do its real work in the
OnMouse... methods. After thinking about it a moment, I realize that this
may be because the TextBox class doesn't really implement most of the
behavior, but instead just uses the built-in Windows text edit control.

With that in mind, I looked to see if you could accomplish the same thing
at a lower level, and lo and behold you can. Here is some code that does
basically what I was talking about (it goes in the control class derived
from TextBox, and you need to use the derived class as the control in your
form):

const int WM_MOUSEMOVE = 0x0200;
const int WM_LBUTTONDOWN = 0x0201;
const int WM_LBUTTONUP = 0x0202;

protected override void WndProc(ref Message m)
{
bool fHandled = false;

switch (m.Msg)
{
case WM_LBUTTONDOWN:
// Ignore the left mouse button down event
fHandled = true;
break;
case WM_MOUSEMOVE:
// Ignore any mouse move events
fHandled = true;
break;
case WM_LBUTTONUP:
// Before we process the left mouse button up event,
// send a left mouse button down event with the same
// mouse location as the mouse up event, to simulate
// an actual click at the location.
Message mT = m; // copy the current message
mT.Msg = WM_LBUTTONDOWN; // change the message ID
base.WndProc(ref mT); // send the simulated message
break;
}

if (!fHandled)
{
base.WndProc(ref m);
}
}

Because this version of the implementation operates on the underlying
Windows messages themselves, it means that even when the text selection is
being handled by a non-.NET piece of code, the mouse messages are still
intercepted before that code handles them.

Note that the above disables selection, but allows the user to reposition
the caret. If you want no mouse interaction at all, just set "fHandled"
in the WM_LBUTTONUP case as well, and take out the code that's in that
case now.

Also note that the above is really just proof-of-concept. I have not
verified that hiding the mouse messages like this does not also result in
some other funny behavior, that may or may not be desired. You should
think about the exact behavior and do thorough testing before using
anything like this in real-world code (especially since I did neither :)).

Hope that helps.

Pete
Jun 6 '07 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3402
by: GGerard | last post by:
Hello When tabbing in a textbox that contains text, the text string is usually highlighted so that if the user starts typing new text in the textbox, the old text is erased. Is there a way...
2
2521
by: rsquarev | last post by:
Hi, I am getting a problem regarding textboxes. In my application I am using a framework, which provides the page base for my application, It's just designing of page. But by using this I am not...
3
2417
by: mudassir368 | last post by:
How to select text in textbox control, if it is focussed using javascript
1
2609
by: clem | last post by:
Hello, there is an asp.net textbox which contains some text. <asp:textbox runat="server"></asp:textbox> I select some part of the text with the mouse: how can i get that part of text in a...
9
3933
by: trixxy | last post by:
how do i make ctrl+A to work? i have a textbox with text and i want to ctrl A it to select all of the text. instead of highlighting the whole textbox with my mouse. TIA
6
52933
by: aeris | last post by:
Hello, I'm a beginner of using C#. I'm creating a window application, May I know how to clear the default text on textbox when I click directly on the textbox? For example, the txtBox has the...
4
3006
by: aeris | last post by:
Hello! I'm using C# to doing my window application. May I ask, how to write text on textbox after the default text is clear? I have setted the default text in textbox, when a user click on it,...
2
3104
by: polluxsoftech | last post by:
i want to enter text in textbox by dropdown only when clicking on button i want that all this perform at client side by javascript.. this is dont in apsx page but i want it in .ascx this is...
0
7054
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6918
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7057
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
4798
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4495
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3008
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3000
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
570
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
199
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.