Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2006

Tip: Looking for answers? Try searching our database.

cancel newline in multiline textbox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sverre.bakke@gmail.com - 20 Aug 2006 12:01 GMT
Hi

I am using a multiline textbox with wordwrapping for creating "large"
texts, but I dont want the user to be able to create a new line. The
property called SuppressKeyPress seem to be the perfect way to solve
this using the KeyDown event. It doesnt work.

My code looks like this:

           if (e.KeyCode == Keys.Enter)
           {
               e.SuppressKeyPress = true;  //doesnt work

               MessageBox.Show("yes I pushed enter and
SuppressKeyPress was changed");
           }

But still it doesnt work. After reading MSDN I am sure that there is
something MSDN hasnt told me about SuppressKeyPress or there are some
sort of bug, cause I cant get this to work.

Thanks in advance for the help.
Jared - 20 Aug 2006 14:22 GMT
I'm assuming this is handled in your KeyPress event handler.  Your solution
should work fine as long as you are testing for both enter or return.

e.SuppressKeyPress = (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return);

> Hi
>
[quoted text clipped - 18 lines]
>
> Thanks in advance for the help.
sverre.bakke@gmail.com - 20 Aug 2006 22:27 GMT
> I'm assuming this is handled in your KeyPress event handler.  Your solution
> should work fine as long as you are testing for both enter or return.
>
> e.SuppressKeyPress = (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return);

Excellent! it worked. Didnt know I had to trap them both. Thanks for
the help!
sverre.bakke@gmail.com - 20 Aug 2006 22:38 GMT
> > I'm assuming this is handled in your KeyPress event handler.  Your solution
> > should work fine as long as you are testing for both enter or return.
[quoted text clipped - 3 lines]
> Excellent! it worked. Didnt know I had to trap them both. Thanks for
> the help!

I just found out that this doesnt work if I call a blocking messagebox
inside the method. Any quickfix for this? What happens is that the
moment I click "OK" on the messagebox the newline appear even though I
did suppresskeypress.
Jared - 25 Aug 2006 12:28 GMT
Can you call your messagebox after you handle the key?

> > > I'm assuming this is handled in your KeyPress event handler.  Your solution
> > > should work fine as long as you are testing for both enter or return.
[quoted text clipped - 8 lines]
> moment I click "OK" on the messagebox the newline appear even though I
> did suppresskeypress.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.