Case Flipping

Discussion in 'C#' started by x64, Apr 16, 2007.

  1. x64

    x64 New Member

    Joined:
    Apr 16, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    St.Paul Minnesota, USA
    Hello,

    I have a richtextbox that I am to be able to type in, I want to be able to select the text and flip the case of the selected string. So... "hello world" would magically be "HELLO WORLD". Here is what I currently have, it does not work, but it does not spit any errors at me. Any ideas?

    Code:
       private void lowerCaseToolStripMenuItem_Click(object sender, EventArgs e)
       {
          RichTextBox rtb = (RichTextBox)tabs.SelectedTab.Controls[0]; ;
          rtb.SelectedText.ToLower();
       }
           
    Thanks
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,336
    Likes Received:
    377
    Trophy Points:
    83
    You are just changing the selected text but if nothing is selected its made not to work.
     
  3. x64

    x64 New Member

    Joined:
    Apr 16, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    St.Paul Minnesota, USA
    Oh sorry, I forgot to add that I do have something selected.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,336
    Likes Received:
    377
    Trophy Points:
    83
    Try something like this
    Code:
    rtb.SelectedText = rtb.SelectedText.ToLower();
    and see if it works.
     
  5. x64

    x64 New Member

    Joined:
    Apr 16, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    St.Paul Minnesota, USA
    Nice! It does work thanks a ton. I can't believe that I didn't think of that myself, it's so simple.
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,336
    Likes Received:
    377
    Trophy Points:
    83
    :D
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice