Advertisement
Guest User

Untitled

a guest
Jul 4th, 2011
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1.    private void button1_Click(object sender, EventArgs e)
  2.         {
  3.             int selstart = textBox1.SelectionStart;
  4.  
  5.             //get previous newline...
  6.             int linestart = textBox1.Text.LastIndexOf(Environment.NewLine,selstart);
  7.             if (linestart == -1) linestart = 0; else linestart += Environment.NewLine.Length;
  8.             int lineend = textBox1.Text.IndexOf(Environment.NewLine, selstart);
  9.             if(lineend==-1) lineend = textBox1.Text.Length;
  10.             String theline = textBox1.Text.Substring(linestart, lineend - linestart);
  11.            
  12.            
  13.             Debug.Print("line was: " + theline);
  14.             //select the line...
  15.             textBox1.SelectionStart = linestart;
  16.             textBox1.SelectionLength = theline.Length;
  17.             textBox1.SelectedText = "#" + theline;
  18.             textBox1.SelectionStart = selstart + 1;
  19.  
  20.  
  21.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement