CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2011
    Posts
    2

    Moving cursor in Visual Studio 2008

    I'm using a TextBox object in my application. The mission is to transform input characters as they are typed (letters only). I'm using string manipulations on TextBox->Text. The problem is that when I'm doing so, the cursor goes to the beginning of line. On the other hand, when the character is typed transparently (without my code), the cursor moves as I type.
    My code looks like this:

    private: System::Void m_TextPane_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) {
    /*
    bla-bla-bla
    */

    // transform input char (e->KeyChar) into String, while manipulation on its value
    // final char String is in curr_out


    // add new char to the typed text
    m_TextPane->Text = String::Concat(m_TextPane->Text, curr_out);
    }


    Any ideas why cursor behaves so and how can I move it to the end of the typed text?

  2. #2
    Join Date
    Jul 2002
    Posts
    2,543

    Re: Moving cursor in Visual Studio 2008

    m_TextPane->Text = String::Concat(m_TextPane->Text, curr_out);
    m_TextPane->SelectionStart = m_TextPane->Text->Length;
    m_TextPane->SelectionLength = 0;

  3. #3
    Join Date
    Jun 2011
    Posts
    2

    Re: Moving cursor in Visual Studio 2008

    This fixes the problem. Thanks a lot!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured