Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 2nd, 2008, 10:07 PM
Authorized User
 
Join Date: Aug 2008
Location: manila, , Philippines.
Posts: 38
Thanks: 1
Thanked 0 Times in 0 Posts
Default remove carriage return character in a textbox

I have a textbox that should send any text to a server program. I have a keypress event that activates upon pressing an enter key. It sends the messages plus additional character(carriage return). How can I remove this character. I already tried using trim and replace but did not work..I also want my cursor to go back to position 0,0 of textbox. I tried Focus() and SelectionStart but I don't like the outcome. Is there a way to set the position of the cursor to row 1 col 1 after pressing enter key?

Reply With Quote
  #2 (permalink)  
Old October 2nd, 2008, 10:27 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,413
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What purpose is being served by sending the cursor (caret) back to 0,0? That seems very unexpected from a usage standpoint. I could understand if you were to simple clear out the contents, then the caret would go there implicitly.

-Peter
compiledthoughts.com
Reply With Quote
  #3 (permalink)  
Old October 2nd, 2008, 11:03 PM
Authorized User
 
Join Date: Aug 2008
Location: manila, , Philippines.
Posts: 38
Thanks: 1
Thanked 0 Times in 0 Posts
Default

I want my textbox to clear out all its content and move back to its initial position, like in any typical chat applications. Whenever i run my program the cursor goes to the next row and rests there. I want to move it back but can't find solution..By the way thanks..

Reply With Quote
  #4 (permalink)  
Old October 2nd, 2008, 11:39 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,652
Thanks: 3
Thanked 141 Times in 140 Posts
Default

So do what Peter said: Just clear all the contents of the text box and presto. You will be giving the user a blank field, again. Yes, with the cursor at the start.

*************

As for the ending NEWLINE character: Two ways.
(1) Using JavaScript, instead of trapping the key via ONKEYPRESS, try trapping it via ONKEYDOWN and then *cancelling* the ENTER key! That way, it won't even end up in the field.

(2) Using C#, just wipe out the last one or two characters of the string. (You'll need to check to see if the ENTER key put just "\n" on the end of the text [Unix style] or "\r\n" [Windows style].)
Lots of ways to do that using the various string class functions. Just look up the .NET docs for the String class.
http://msdn.microsoft.com/en-us/library/system.string_members(VS.80).aspx
Huh. I didn't even know this method existed! Look how easy they have made it for you:
http://msdn.microsoft.com/en-us/library/system.string.trimend(VS.80).aspx
Reply With Quote
  #5 (permalink)  
Old October 3rd, 2008, 12:49 AM
Authorized User
 
Join Date: Aug 2008
Location: manila, , Philippines.
Posts: 38
Thanks: 1
Thanked 0 Times in 0 Posts
Default

I managed to remove the carriage returns using Trim(), All the text are cleared but the cursor remains in the 2nd row.

Reply With Quote
  #6 (permalink)  
Old September 15th, 2017, 09:38 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2017
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I know this post is old but I had the same problem and found no solution that worked on the internet, but I was trying several things and this fixed the problem:
txtbox.Multiline = false;
txtbox.Multiline = true;

(on the keypress event)
Just like that. No sense, but worked.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking for a Carriage return darkhalf Classic ASP Databases 2 November 5th, 2007 05:15 AM
about carriage return... edu1980 XSLT 1 July 5th, 2006 04:11 AM
Code to Remove Carriage Return From Spreadsheet Jersey Eric Excel VBA 2 May 12th, 2005 08:35 AM
New Line/Carriage Return interrupt Javascript How-To 7 October 3rd, 2004 06:27 AM
HELP Inserting Carriage Return orangem Classic ASP Databases 8 July 5th, 2004 08:36 PM



All times are GMT -4. The time now is 11:34 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.