C# School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C# Expert!

Join 308,420 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 3,356 people online right now. Registration is fast and FREE... Join Now!




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

 

Don't allow Enter Key to make a new line, but, Do not update Rich textbox with Enter Key

Tertitten

3 Mar, 2009 - 10:58 PM
Post #1

New D.I.C Head
*

Joined: 2 Mar, 2009
Posts: 9

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.
CODE

        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: 3 Mar, 2009 - 11:00 PM

User is offlineProfile CardPM
+Quote Post


PsychoCoder

RE: Don't Allow Enter Key To Make A New Line, But

3 Mar, 2009 - 11:08 PM
Post #2

I Code, Therefore I am
Group Icon

Joined: 26 Jul, 2007
Posts: 15,001



Thanked: 522 times
Dream Kudos: 11700
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
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

User is offlineProfile CardPM
+Quote Post

Tertitten

RE: Don't Allow Enter Key To Make A New Line, But

3 Mar, 2009 - 11:14 PM
Post #3

New D.I.C Head
*

Joined: 2 Mar, 2009
Posts: 9

QUOTE(PsychoCoder @ 3 Mar, 2009 - 11:08 PM) *

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.

User is offlineProfile CardPM
+Quote Post

itlee

RE: Don't Allow Enter Key To Make A New Line, But

4 Mar, 2009 - 01:22 AM
Post #4

D.I.C Head
**

Joined: 16 Jul, 2008
Posts: 52



Thanked: 7 times
My Contributions
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.
User is offlineProfile CardPM
+Quote Post

Tertitten

RE: Don't Allow Enter Key To Make A New Line, But

4 Mar, 2009 - 02:17 AM
Post #5

New D.I.C Head
*

Joined: 2 Mar, 2009
Posts: 9

QUOTE(itlee @ 4 Mar, 2009 - 01: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.


Thanks a bunch, that helped allot smile.gif
I changed it to Alt+Enter and it works just fine wink2.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/24/09 01:08PM

Live C# Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month