2011-03-01 22 views
5

मैं पूरी लाइन का रंग बदलना चाहता हूं, इस पर ध्यान दिए बिना कि पाठ है या नहीं। यहां कुछ समझाई गई छवि है:RichTextBox में कुछ पंक्ति के पृष्ठभूमि रंग को कैसे बदलें?

http://img131.imageshack.us/img131/1802/highlightlineqt2.png

मुझे कुछ समाधान here मिला, लेकिन मुझे उम्मीद है कि एक आसान समाधान है।

+0

+1 महान चित्रण के लिए:] – dotTutorials

उत्तर

0

ठीक है, तो शायद यह (found here):

private void richTextBox1_MouseClick(object sender, MouseEventArgs e, Color color) 
{ 
    int firstcharindex = richTextBox1.GetFirstCharIndexOfCurrentLine(); 
    int currentline = richTextBox1.GetLineFromCharIndex(firstcharindex); 
    string currentlinetext = richTextBox1.Lines[currentline]; 
    richTextBox1.SelectionBackColor = color; 
    richTextBox1.Select(firstcharindex, currentlinetext.Length); 
} 

, तो आप रंग सेट करने के लिए इस स्निपेट आपकी समस्या ;-)

1

नहीं, आप पहली पंक्ति का चयन करने के लिए है का समाधान करना चाहिए :

public void MarkSingleLine() 
{ 
    int firstCharOfLineIndex = myRichTextBox.GetFirstCharIndexOfCurrentLine(); 
    int currentLine = richTextBox1.GetLineFromCharIndex(firstCharOfLineIndex); 
    this.myRichTextBox.Select(firstCharOfLineIndex, currentLine); 
    this.myRichTextBox.SelectionBackColor = Color.Aqua; 
    this.myRichTextBox.Select(0, 0); 
} 
संबंधित मुद्दे