PDA

View Full Version : حرفه ای: تغییر رنگ نوشته ها در RichTextBox بعد از اینترزدن



hashtgerd2
یک شنبه 26 اردیبهشت 1395, 06:53 صبح
تو ریچ تکس باکس وقتی دکمه هارو میزنم هر حرف به رنگ خاصی به نمایش در میاد
ولی وقتی دکمه باتن اینتر رو می زنم همه نوشته ها یک دست یک رنگ میشن
140426

بعد از زدن باتن اینتر
140427

کلید اینتر خود کیبورد رو میزنی این مشکل رو نداره ولی دکمه رو میزنی این مشکل هست رنگ همه یکی میشه
کد مربوط به اینتر
// برای پاک کردن قسمت انتخاب شده
if (TextBox1.SelectionLength > 0)
TextBox1.SelectedText = "";

// برای بردن به خط جدید از جایی که کلیک شده است
string removedSelection = TextBox1.Text;
int selectionStartIndex = TextBox1.SelectionStart;
TextBox1.Text = removedSelection.Insert(selectionStartIndex, Environment.NewLine);
TextBox1.SelectionStart = selectionStartIndex + 1;
// TextBox1.Focus();

Mahmoud.Afrad
یک شنبه 26 اردیبهشت 1395, 18:59 عصر
باید با rtf کار کنید.
این متد رو تست کنید
private void InsertEnter(RichTextBox richtxt)
{
int selectionStartIndex = richtxt.SelectionStart;
int selectionLength = richtxt.SelectionLength;

richtxt.SelectionStart = 0;
richtxt.SelectionLength = selectionStartIndex;
int indexForInsert = richtxt.SelectedRtf.LastIndexOf('}');
string rtfPart1 = richtxt.SelectedRtf;

richtxt.SelectionStart = selectionStartIndex + selectionLength;
richtxt.SelectionLength = richtxt.TextLength - (selectionStartIndex + selectionLength);
string rtfPart2 = richtxt.SelectedRtf;


richtxt.Text = string.Empty;
richtxt.SelectedRtf = rtfPart1.Insert(indexForInsert , "\\par");
richtxt.SelectionStart = richtxt.Text.Length;
richtxt.SelectedRtf = rtfPart2;

richtxt.SelectionStart = selectionStartIndex + 1;
richtxt.Focus();
}

hashtgerd2
یک شنبه 26 اردیبهشت 1395, 22:06 عصر
بله دستتون درد نکنه این کار کرد درست شد
اینجور چیزا رو چطوری میتونم یاد بگیرم هر چقدر سرچ کردم نتونستم حتی کدی که به درستی به خط بعدی ببره رو پیدا کنم