How to prevent SELECTION by user, in TEXTBOX ?

T

tony

Hi,

I want to prevent the user, from selecting text (blue selection) in TextBox
, How can i do this ?

(the textbox must be enabled=true)
Thanking in advance.
 
P

Paul G. Tobey [eMVP]

Why must it be enabled, but not selectable? Tell us *what* you are trying
to do, *not* how you've decided to do it. We can give you a good answer
that way.

Paul T.
 
S

Simon Hart [MVP]

This sounds quite ugly. But if you'd really need to do it, you'd have to
implement the OnMouseUp event check the selected text and set it to zero if
its greater than 0 - ugly but will work.
 
T

tony

Hi,

The problem is I created custom textbox ,
I want to prevent the user to change the text.

For some reason the Text.ReadOnly did not prevent the user to write text in
the TextBox,
so i create custom read only that will return immedialy from Key events.

till here everything was O.K

but then, i notice that if i select the text and then write somthing, the
text is changed, although i had the custom readonly=true.

Thanking in advance,


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:%[email protected]...
 
P

Paul G. Tobey [eMVP]

So, the problem is that ReadOnly isn't working, NOT THAT YOU NEED TO PREVENT
SELECTION OF TEXT! Give us the details on your environment. You haven't
told us what the target device is (Windows Mobile? Windows CE? Version?),
what version of .NET Compact Framework you are working with, etc. It might
be worthwhile to build a simple custom textbox that demonstrates the
problem, verify that it exists in that case, and post the code. Can we
presume, also, that regular Textbox controls *do* work correctly with
respect to ReadOnly for you? I can't find any situations where ReadOnly
doesn't work.

Paul T.

tony said:
Hi,

The problem is I created custom textbox ,
I want to prevent the user to change the text.

For some reason the Text.ReadOnly did not prevent the user to write text
in the TextBox,
so i create custom read only that will return immedialy from Key events.

till here everything was O.K

but then, i notice that if i select the text and then write somthing, the
text is changed, although i had the custom readonly=true.

Thanking in advance,


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:%[email protected]...
Why must it be enabled, but not selectable? Tell us *what* you are
trying to do, *not* how you've decided to do it. We can give you a good
answer that way.

Paul T.
 
P

PrTaS

I also could not imagine why it does not work but you may try this:

private void textBox_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
}
 
A

Adrian Rotaru

Hi

TextBox.ReadOnly stii won't work. At least for multiline textboxes.

I am using CF3.5 on a Windows Mobile 6.1 system.

I will try PrTaS's solution.




PrTaS wrote:

How to prevent SELECTION by user, in TEXTBOX ?
28-Jul-08

I also could not imagine why it does not work but you may try this

private void textBox_KeyPress(object sender, KeyPressEventArgs e

e.Handled = true
}

Previous Posts In This Thread:

How to prevent SELECTION by user, in TEXTBOX ?
Hi

I want to prevent the user, from selecting text (blue selection) in TextBo
, How can i do this

(the textbox must be enabled=true
Thanking in advance.

Why must it be enabled, but not selectable?
Why must it be enabled, but not selectable? Tell us *what* you are tryin
to do, *not* how you have decided to do it. We can give you a good answe
that way

Paul T.

This sounds quite ugly.
This sounds quite ugly. But if you'd really need to do it, you'd have to
implement the OnMouseUp event check the selected text and set it to zero if
its greater than 0 - ugly but will work
--
Simon Har
Visual Developer - Device Application Development MV
http://simonrhart.blogspot.co

:

Hi,The problem is I created custom textbox ,I want to prevent the user to
Hi

The problem is I created custom textbox
I want to prevent the user to change the text

For some reason the Text.ReadOnly did not prevent the user to write text in
the TextBox
so i create custom read only that will return immedialy from Key events

till here everything was O.

but then, i notice that if i select the text and then write somthing, the
text is changed, although i had the custom readonly=true

Thanking in advance

"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message
So, the problem is that ReadOnly isn't working, NOT THAT YOU NEED TO PREVENT
So, the problem is that ReadOnly isn't working, NOT THAT YOU NEED TO PREVENT
SELECTION OF TEXT! Give us the details on your environment. You haven't
told us what the target device is (Windows Mobile? Windows CE? Version?),
what version of .NET Compact Framework you are working with, etc. It might
be worthwhile to build a simple custom textbox that demonstrates the
problem, verify that it exists in that case, and post the code. Can we
presume, also, that regular Textbox controls *do* work correctly with
respect to ReadOnly for you? I can't find any situations where ReadOnly
doesn't work

Paul T


How to prevent SELECTION by user, in TEXTBOX ?
I also could not imagine why it does not work but you may try this

private void textBox_KeyPress(object sender, KeyPressEventArgs e

e.Handled = true
}


Submitted via EggHeadCafe - Software Developer Portal of Choice
Join Lists with LINQ - SharePoint 2010
http://www.eggheadcafe.com/tutorial...6e-7d3fb7d38eca/join-lists-with-linq--sh.aspx
 
A

Adrian Rotaru

I found out that the nasty behavior of ReadOnly property has to do with the t9 dictionary input style.

That is, my Assus PDA works in t9 dictionary mode when typing. In this mode, the editing is not prevented.

Not sure if this is the only case when this faulty behavior occurs.



Adrian Rotaru wrote:

ReadOnly still not working
16-Feb-10

Hi

TextBox.ReadOnly stii won't work. At least for multiline textboxes.

I am using CF3.5 on a Windows Mobile 6.1 system.

I will try PrTaS's solution.

Previous Posts In This Thread:


Submitted via EggHeadCafe - Software Developer Portal of Choice
Generic Feed Parsers Redux
http://www.eggheadcafe.com/tutorial...6-acd41f462063/generic-feed-parsers-redu.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top