Don't allow Enter Key to make a new line, but

Do not update Rich textbox with Enter Key

Page 1 of 1

4 Replies - 3879 Views - Last Post: 04 March 2009 - 03:17 AM Rate Topic: -----

#1 Tertitten  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 02-March 09

Don't allow Enter Key to make a new line, but

Post icon  Posted 03 March 2009 - 11:58 PM

Hi I need help with the code below, if you see the code comments it will be clear what I try to achieve.
I've tried my best but I can't seem to do it on my own so any help would be greatly appreciated.
		private void rtfSend_KeyUp(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Enter) e.Handled = false;
			else e.Handled = true;
			{   
				if (e.Control == true & e.KeyCode == Keys.Enter)
				// User Pushed Enter Key and Control, 
				// We don't want the body of Rich TextBox to capture the new line 
				// and need to remove the new line somehow. 
				// However only when Control and Enter are pushed at the same time. 
				{
					//Some Function here to remove the extra line made by Enter Key
					msg.Body = rtfSend.Text;
					rtfSend.Text = "";
				}
			}
		}


This post has been edited by Tertitten: 04 March 2009 - 12:00 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Don't allow Enter Key to make a new line, but

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Don't allow Enter Key to make a new line, but

Posted 04 March 2009 - 12:08 AM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:

  • Post the code you're having problems with (DONE)
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#3 Tertitten  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 02-March 09

Re: Don't allow Enter Key to make a new line, but

Posted 04 March 2009 - 12:14 AM

View PostPsychoCoder, on 3 Mar, 2009 - 11:08 PM, said:

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with (DONE)
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

I don't get any errors, what happens is that im typing in a RichTextBox
I don't want a new line created in the box if I push down Control+Enter Key, however I do want a new line if I push down Enter
Control+Enter is "hotkey" for some code, so I dont want the RichTextBox to update with a new line.
Was This Post Helpful? 0
  • +
  • -

#4 itlee  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 55
  • Joined: 16-July 08

Re: Don't allow Enter Key to make a new line, but

Posted 04 March 2009 - 02:22 AM

You code implies you are removing the line entered by the key combination Ctrl+Enter, how will you then implement the new line command in the RTF control?

I would suggest you change your hotkey to Alt+Enter, otherwise you are changing the expected behavour of the control. Users will find it easier to remember the change in the hotkey than remembering the change in the RTF control.

itlee.
Was This Post Helpful? 1
  • +
  • -

#5 Tertitten  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 02-March 09

Re: Don't allow Enter Key to make a new line, but

Posted 04 March 2009 - 03:17 AM

View Postitlee, on 4 Mar, 2009 - 01:22 AM, said:

You code implies you are removing the line entered by the key combination Ctrl+Enter, how will you then implement the new line command in the RTF control?

I would suggest you change your hotkey to Alt+Enter, otherwise you are changing the expected behavour of the control. Users will find it easier to remember the change in the hotkey than remembering the change in the RTF control.

itlee.


Thanks a bunch, that helped allot :)
I changed it to Alt+Enter and it works just fine ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1