Member Avatar for JOLO14

Hi, i want to ask u something guys. i have one textbox. While writing in, after pressing Space, i want to intstead of white space, write this "|" . This is my code

void TextBox1KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    if (e.KeyChar == (char)Keys.Space)
         {
            textBox1.AppendText("|");

        }
      }

Problem is it dont write only "|" but "| " . After that char it put whitespace and cursor moves after that white space. I try to use method

textBox1.Text = textBox1.Text.Substring(0, (textBox1.TextLength - 1)); 

but it dont work because it delete my "|" no that whitespace, since whitespace is not char....

Thanks for any help

Recommended Answers

All 3 Replies

In your KeyPressEventArgs object is a Handled property. Set that guy before returning from the event handler to disable subsequent control logic on the event.

Member Avatar for JOLO14

sorry but i dont understand, i use google translate to translate your answer because english is not my native language. And also my c# skills are not so high..If u could answer in basic or "lower" english..only words from your answer i undestand were: In your,that guy (but i dont think it mean that "man")

e.Handled = true;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.