本文整理汇总了C#中System.Windows.Forms.RichTextBox.SelectAll方法的典型用法代码示例。如果您正苦于以下问题:C# RichTextBox.SelectAll方法的具体用法?C# RichTextBox.SelectAll怎么用?C# RichTextBox.SelectAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.RichTextBox
的用法示例。
在下文中一共展示了RichTextBox.SelectAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HighlightText
/// <summary>
/// Highlight all words that matches.
/// </summary>
/// <param name="myRtb">Source text box</param>
/// <param name="word">Word to match.</param>
public void HighlightText(RichTextBox myRtb, string word)
{
myRtb.SelectAll();
myRtb.SelectionBackColor = Color.White;
myRtb.SelectionColor = Color.Black;
myRtb.DeselectAll();
if (word == "")
{
return;
}
int s_start = myRtb.SelectionStart, startIndex = 0, index;
while ((index = myRtb.Text.IndexOf(word, startIndex)) != -1)
{
myRtb.Select(index, word.Length);
myRtb.SelectionColor = Color.White;
myRtb.SelectionBackColor = Color.Green;
startIndex = index + word.Length;
}
myRtb.SelectionStart = s_start;
myRtb.SelectionLength = 0;
myRtb.SelectionColor = Color.Black;
myRtb.SelectionBackColor = Color.White;
}
示例2: setFontStyle
private void setFontStyle(RichTextBox rtb, FontStyle style)
{
if (rtb.SelectionLength == 0)
setCharFontStyle(rtb, style);
else
{
// to avoid screen refreshing, we create a fake RichTextBox
using (RichTextBox a = new RichTextBox())
{
a.SuspendLayout();
a.SelectedRtf = rtb.SelectedRtf;
a.SelectAll();
int selectionStart = a.SelectionStart;
int selectionLength = a.SelectionLength;
int selectionEnd = selectionStart + selectionLength;
for (int x = selectionStart; x < selectionEnd; ++x)
{
// Set temporary selection
a.Select(x, 1);
// Toggle font style of the selection
setCharFontStyle(a, style);
}
// Restore the original selection
a.SelectAll();
rtb.SelectedRtf = a.SelectedRtf;
}
}
}
示例3: Paint
public void Paint(int StartLine, int FinalLine, RichTextBox RTB)
{
if(StartLine < 0 || FinalLine < 0)
{
Console.WriteLine("错误:着色起始或终止行号 < 0");
return;
}
int OriSelectionStart = RTB.SelectionStart; //记录光标位置
RTB.SelectionChanged -= new System.EventHandler(mainform.richTextBox1_SelectionChanged);//注销选区改变事件,以免处理过程中多次触发、
RTB.TextChanged -= new System.EventHandler(mainform.richTextBox1_TextChanged); //注销文字改变事件
SendMessage(RTB.Handle, 0x0B, 0, 0); //第一轮加工开始,禁止组件重画,避免闪烁问题
RTB.SelectAll();
RTB.SelectionFont = Defines.TextBoxFont;
RTB.DeselectAll();
RTB.SelectionStart = OriSelectionStart;
SendMessage(RTB.Handle, 0x0B, 1, 0); //第一轮加工结束,允许组件重画
RTB.Refresh(); //组件刷新
SendMessage(RTB.Handle, 0x0B, 0, 0); //第二轮加工开始,禁止组件重画,避免着色闪烁问题
if (RTB.Lines.Length > 0 )
{
for (int i = StartLine; i <= FinalLine; i++) this.PaintLine(i, ref RTB); //对每行着色
}
RTB.SelectionLength = 0;
RTB.SelectionStart = OriSelectionStart; //光标归位
RTB.SelectionColor = Color.Black;
SendMessage(RTB.Handle, 0x0B, 1, 0); //第二轮加工结束,允许组件重画
RTB.TextChanged += new System.EventHandler(mainform.richTextBox1_TextChanged); //恢复事件
RTB.SelectionChanged += new System.EventHandler(mainform.richTextBox1_SelectionChanged); //恢复事件
RTB.Refresh();
}
示例4: FormattedAnswer
public string FormattedAnswer()
{
RichTextBox rtb = new RichTextBox();
rtb.Text = Answer;
rtb.Font = new Font("Segoe UI", 10);
if (IsCorrect) {
rtb.Select(0, Answer.Length);
rtb.SelectionColor = Color.Green;
rtb.SelectionAlignment = HorizontalAlignment.Center;
rtb.DeselectAll();
return rtb.Rtf;
}
rtb.Text += " " + RightAnswer;
rtb.Select(0, Answer.Length);
rtb.SelectionFont = new Font(rtb.SelectionFont, FontStyle.Strikeout);
rtb.Select(Answer.Length + 1, RightAnswer.Length);
rtb.SelectionColor = Color.Green;
rtb.SelectAll();
rtb.SelectionAlignment = HorizontalAlignment.Center;
rtb.DeselectAll();
return rtb.Rtf;
}
示例5: SqlConnection
void 中译英入题目表()
{
SqlConnection conn = new SqlConnection(login.sqlName);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "new_教师英语词组_中译英";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("timuWenBen", SqlDbType.VarChar).Value = textBox2.Text.Trim() + textBox1.Text.Trim();
cmd.Parameters.Add("teacherName", SqlDbType.NVarChar).Value = login.teacherName;
//cmd.Parameters.Add("wentiYinPin", SqlDbType.NVarChar).Value = "无";
cmd.Parameters.Add("cizuID", SqlDbType.NVarChar).Value = cizuID;
cmd.Parameters.Add("nianji", SqlDbType.NVarChar).Value = comboBox1.Text;
cmd.Parameters.Add("danyuan", SqlDbType.NVarChar).Value = comboBox2.Text;
cmd.Parameters.Add("zhongYiyingID", SqlDbType.Int).Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
id中译英 = (int)cmd.Parameters["zhongYiyingID"].Value;
conn.Dispose();
cmd.Dispose();
RichTextBox rtb问题 = new RichTextBox();
rtb问题.Font = new Font("微软雅黑", 30);
rtb问题.Text = textBox2.Text;
rtb问题.SelectAll();
rtb问题.SaveFile(login.qfold + id中译英, RichTextBoxStreamType.RichText);
RichTextBox rtb答案 = new RichTextBox();
rtb答案.Font = new Font("微软雅黑", 35);
rtb答案.ForeColor = Color.Red;
rtb答案.Text = textBox1.Text + "\n";
rtb答案.SelectAll();
RichTextBox eg1Eng = new RichTextBox();
eg1Eng.Font = new Font("微软雅黑", 20);
eg1Eng.Text = textBox3.Text;
RichTextBox eg1Ch = new RichTextBox();
eg1Ch.Font = new Font("楷体", 15);
eg1Ch.ForeColor = Color.Gray;
eg1Ch.Text = textBox4.Text + "\n";
RichTextBox eg2Eng = new RichTextBox();
eg2Eng.Font = new Font("微软雅黑", 20);
eg2Eng.Text = textBox5.Text;
RichTextBox eg2Ch = new RichTextBox();
eg2Ch.Font = new Font("楷体", 15);
eg2Ch.ForeColor = Color.Gray;
eg2Ch.Text = textBox6.Text;
RichTextBox rtb合并 = new RichTextBox();
rtb合并.SelectedRtf = rtb问题.Rtf;
rtb合并.SelectedRtf = rtb答案.Rtf;
rtb合并.SelectedRtf = eg1Eng.Rtf;
rtb合并.SelectedRtf = eg1Ch.Rtf;
rtb合并.SelectedRtf = eg2Eng.Rtf;
rtb合并.SelectedRtf = eg2Ch.Rtf;
rtb合并.SaveFile(login.afold + id中译英, RichTextBoxStreamType.RichText);
}
示例6: calibrateTextView
public void calibrateTextView(RichTextBox textView)
{
int i = textView.SelectionStart;
//margins
textView.SelectAll();
textView.SelectionIndent = 9;
textView.SelectionRightIndent = 9;
textView.SelectionLength = 0;
textView.SelectionBackColor = textView.BackColor;
textView.SelectionStart = i;
if (goodFont != null) {
textView.Font = goodFont;
//winforms bag. If new forecolor is equal to old the text will not be redraw.
textView.ForeColor = Color.Gold;
textView.ForeColor = Color.White;
}
}
示例7: RichTextBox
void 听录音存入数据库()
{
RichTextBox rtb7 = new RichTextBox();
//存英中文答案
rtb7.Text = textBox3.Text +"\n"+ textBox1.Text;
rtb7.SelectAll();
rtb7.SelectionFont = new Font("微软雅黑", 35);
rtb7.SelectionColor = Color.Red;
RichTextBox rtb9 = new RichTextBox();
rtb9.SelectedRtf = rtb7.Rtf;
rtb9.SelectedRtf = this.richTextBox1.Rtf;
//存入数据库
SqlConnection conn = new SqlConnection(login.sqlName);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "new_教师录英语词汇_单词中译英";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("teacherName", SqlDbType.NVarChar).Value = login.teacherName;
cmd.Parameters.Add("tixing", SqlDbType.NVarChar).Value = "听录音,默写英文和中文";
cmd.Parameters.Add("wentiYinPin", SqlDbType.NVarChar).Value = audioStr;
cmd.Parameters.Add("zhangjie", SqlDbType.NVarChar).Value = str章节;
cmd.Parameters.Add("daanYinPin", SqlDbType.NVarChar).Value = "无";
cmd.Parameters.Add("题目文本", SqlDbType.NVarChar).Value = rtb7.Text.Trim();
cmd.Parameters.Add("id", SqlDbType.Int).Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
questionID听录音 = (int)cmd.Parameters["id"].Value;
//题号存入词汇表
cmd.CommandType = CommandType.Text;
cmd.CommandText = string.Format("update 英语词汇表 set 听录音ID = {0} where id = {1}", questionID听录音, 词汇ID);
cmd.ExecuteNonQuery();
//存储文件
rtb8.SaveFile(login.qfold + questionID听录音, RichTextBoxStreamType.RichText);
rtb9.SaveFile(login.afold + questionID听录音, RichTextBoxStreamType.RichText);
}
示例8: AddTextToRTB
/// <summary>
/// Adds the text to RTB.
/// </summary>
/// <param name="richTextBox">The rich text box.</param>
/// <param name="stackCard">The stack card.</param>
/// <remarks>Documented by Dev08, 2009-05-12</remarks>
private void AddTextToRTB(RichTextBox richTextBox, StackCard stackCard)
{
richTextBox.SuspendLayout();
AnswerResult result = stackCard.Promoted ? AnswerResult.Correct : (stackCard.Result == AnswerResult.Almost ? AnswerResult.Almost : AnswerResult.Wrong);
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"<[^>]*>"); //to replace html code if any
bool questionRTL = stackCard.QuestionCulture.TextInfo.IsRightToLeft;
bool answerRTL = stackCard.AnswerCulture.TextInfo.IsRightToLeft;
richTextBox.BackColor = StackCardBackColors.ContainsKey(result) ? StackCardBackColors[result] : SystemColors.Window;
richTextBox.ForeColor = this.ForeColor;
string text = Environment.NewLine;
string questionRLE = (questionRTL ? Convert.ToString(Convert.ToChar(RLE)) : string.Empty);
text += questionRLE + regex.Replace(stackCard.Question, String.Empty) + Environment.NewLine;
text += questionRLE + regex.Replace(stackCard.QuestionExample, String.Empty) + Environment.NewLine;
text += Environment.NewLine;
string answerRLE = (answerRTL ? Convert.ToString(Convert.ToChar(RLE)) : string.Empty);
if (stackCard.LearnMode == MLifter.BusinessLayer.LearnModes.Sentence && stackCard.AnswerExample.Length > 0)
{
text += answerRLE + regex.Replace(stackCard.AnswerExample, String.Empty) + Environment.NewLine;
text += answerRLE + regex.Replace(stackCard.Answer, String.Empty) + Environment.NewLine;
}
else
{
text += answerRLE + regex.Replace(stackCard.Answer, String.Empty) + Environment.NewLine;
text += answerRLE + regex.Replace(stackCard.AnswerExample, String.Empty) + Environment.NewLine;
}
richTextBox.Visible = true;
richTextBox.Text = text;
richTextBox.Font = this.Font;
richTextBox.SelectAll();
richTextBox.SelectionFont = this.Font;
richTextBox.Select(0, 0);
richTextBox.ResumeLayout();
}
示例9: prepareTextView
public void prepareTextView(RichTextBox textView)
{
//margins
textView.SelectAll();
textView.SelectionIndent = 9;
textView.SelectionRightIndent = 9;
textView.SelectionLength = 0;
textView.SelectionBackColor = textView.BackColor;
//params
float currSize = textView.Font.Size; //default text size
float textConst = 0.89F; //magic const
int ipodLineSymbolsCount = 27; //how many symbols fiited in ipod line
int textViewLineSymbolsCount = 39; //textview line
// get new size
float fontSize = ((textViewLineSymbolsCount * currSize) / ipodLineSymbolsCount) * textConst;
//set new font
goodFont = new Font("Arial", fontSize);
textView.Font = goodFont;
textView.SelectionStart = textView.Text.Length;
}
示例10: colorizeCode
private static void colorizeCode(RichTextBox rtb)
{
string[] keywords = {"as", "do", "if", "in", "is", "for", "int", "new", "out", "ref", "try", "base",
"bool", "byte", "case", "char", "else", "enum", "goto", "lock", "long", "null",
"this", "true", "uint", "void", "break", "catch", "class", "const", "event", "false",
"fixed", "float", "sbyte", "short", "throw", "ulong", "using", "where", "while",
"yield", "double", "extern", "object", "params", "public", "return", "sealed",
"sizeof", "static", "string", "struct", "switch", "typeof", "unsafe", "ushort",
"checked", "decimal", "default", "finally", "foreach", "partial", "private",
"virtual", "abstract", "continue", "delegate", "explicit", "implicit", "internal",
"operator", "override", "readonly", "volatile",
"interface", "namespace", "protected", "unchecked",
"stackalloc",
"from", "in", "where", "select", "join", "equals", "let", "on", "group", "by",
"into", "orderby", "ascending", "descending", "var"};
string text = rtb.Text;
rtb.SelectAll();
rtb.SelectionColor = rtb.ForeColor;
foreach (String keyword in keywords)
{
int keywordPos = rtb.Find(keyword, RichTextBoxFinds.MatchCase | RichTextBoxFinds.WholeWord);
while (keywordPos != -1)
{
int commentPos = text.LastIndexOf("//", keywordPos, StringComparison.OrdinalIgnoreCase);
int newLinePos = text.LastIndexOf("\n", keywordPos, StringComparison.OrdinalIgnoreCase);
int quoteCount = 0;
int quotePos = text.IndexOf("\"", newLinePos + 1, keywordPos - newLinePos, StringComparison.OrdinalIgnoreCase);
while (quotePos != -1)
{
quoteCount++;
quotePos = text.IndexOf("\"", quotePos + 1, keywordPos - (quotePos + 1),StringComparison.OrdinalIgnoreCase);
}
if (newLinePos >= commentPos && quoteCount % 2 == 0)
rtb.SelectionColor = Color.Blue;
keywordPos = rtb.Find(keyword, keywordPos + rtb.SelectionLength, RichTextBoxFinds.MatchCase | RichTextBoxFinds.WholeWord);
}
}
rtb.Select(0, 0);
}
示例11: button2_Click
// Copy to clipboard
private void button2_Click(object sender, EventArgs e)
{
ListView listView1 = (ListView)tabControl1.TabPages[tabControl1.SelectedIndex].Controls[0];
RichTextBox textBox = new RichTextBox();
foreach (ListViewItem item in listView1.Items)
{
textBox.Text += item.Text + ": " + item.SubItems[1].Text + "\n";
}
textBox.SelectAll();
textBox.Copy();
ManagedMessageBox.ShowMessage(Program.ResourceManager.GetString("Message_Done"));
}
示例12: ColourCompounds
protected void ColourCompounds(RichTextBox box)
{
int oldSelectionStart = box.SelectionStart;
int oldSelectionLength = box.SelectionLength;
box.SelectAll();
box.SelectionBackColor = box.BackColor;
box.SelectionColor = box.ForeColor;
Dictionary<int, int> unparseable = CheckCompounds(box.Text);
foreach (KeyValuePair<int, int> kvp in unparseable)
{
box.Select(kvp.Key, kvp.Value);
box.SelectionBackColor = Color.DarkRed;
box.SelectionColor = Color.White;
}
box.Select(oldSelectionStart, oldSelectionLength);
}
示例13: formatUnform
private void formatUnform(RichTextBox rtb)
{
format(rtb, Util.REF, Util.TRANSFONT, ResolvedRefrainForegroundColor, 0, "Refrain :" + Util.RTNL, "");
format(rtb, Util.SPEC, new Font(Util.SPECFONT.FontFamily, Util.TRANSFONT.Size, Util.SPECFONT.Style),
ResolvedForegroundColor, 0, "", "");
formatBlock(rtb);
format(rtb, Util.BOLD, Util.TRANSFONT, ResolvedForegroundColor, 0, "", "");
format(rtb, Util.ITALIC, Util.TRANSFONT, ResolvedForegroundColor, 0, "", "");
rtb.SelectAll();
rtb.SelectionFont = Util.TRANSFONT;
}
示例14: UpdateLineNumbers
void UpdateLineNumbers(RichTextBox lineNumbers, RichTextBox thisRtb)
{
//getLinefromCharindex isn't the same as line number when dealing with wordwrap
// string[] textLines = thisRtb.Text.Split('\n');
int topLine = lineFromCharIndex(thisRtb.Text, (thisRtb.GetCharIndexFromPosition(new Point(0,0))));
int bottomLine = thisRtb.GetLineFromCharIndex(thisRtb.GetCharIndexFromPosition(new Point(1, thisRtb.Height)));
int currentLine = 0;
lineNumbers.Text = "";
int lastLine = 0;
for (int i = topLine; i <= bottomLine; i++)
{
currentLine = lineFromCharIndex(thisRtb.Text, thisRtb.GetFirstCharIndexFromLine(i-1));
if (lastLine != currentLine)
{
lineNumbers.AppendText(currentLine + "");
lastLine = currentLine;
}
lineNumbers.AppendText("\n");
}
lineNumbers.SelectAll();
lineNumbers.SelectionAlignment = HorizontalAlignment.Right;
}
示例15: SqlConnection
void 中译英入题目表()
{
SqlConnection conn = new SqlConnection(login.sqlName);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "new_教师英语单词_中译英";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("timuWenBen", SqlDbType.VarChar).Value = textBox2.Text.Trim()+textBox1.Text.Trim();
cmd.Parameters.Add("teacherName", SqlDbType.NVarChar).Value = login.teacherName;
//cmd.Parameters.Add("wentiYinPin", SqlDbType.NVarChar).Value = "无";
cmd.Parameters.Add("danciID", SqlDbType.NVarChar).Value = wordID;
cmd.Parameters.Add("zhongYiyingID", SqlDbType.Int).Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
id中译英 = (int)cmd.Parameters["zhongYiyingID"].Value;
conn.Dispose();
cmd.Dispose();
RichTextBox rtbQ = new RichTextBox();
rtbQ.Text = textBox2.Text + "\n";
rtbQ.SelectAll();
rtbQ.SelectionFont = new Font("微软雅黑", 35);
rtbQ.SaveFile(login.qfold + id中译英, RichTextBoxStreamType.RichText);
RichTextBox rtbA = new RichTextBox();
rtbA.Font = new Font("微软雅黑", 45);
rtbA.ForeColor = Color.Red;
rtbA.Text = textBox1.Text;
RichTextBox rtbYinBiao = new RichTextBox();
rtbYinBiao.Font = new Font("Lucida Sans Unicode", 20);
rtbYinBiao.ForeColor = Color.Gray;
rtbYinBiao.Text = textBox7.Text + "\n";
RichTextBox eg1Eng = new RichTextBox();
eg1Eng.Font = new Font("微软雅黑", 20);
eg1Eng.Text = textBox3.Text;
RichTextBox eg1Ch = new RichTextBox();
eg1Ch.Font = new Font("楷体", 15);
eg1Ch.ForeColor = Color.Gray;
eg1Ch.Text = textBox4.Text + "\n";
RichTextBox eg2Eng = new RichTextBox();
eg2Eng.Font = new Font("微软雅黑", 20);
eg2Eng.Text = textBox5.Text;
RichTextBox eg2Ch = new RichTextBox();
eg2Ch.Font = new Font("楷体", 15);
eg2Ch.ForeColor = Color.Gray;
eg2Ch.Text = textBox6.Text ;
RichTextBox rtbZong = new RichTextBox();
rtbZong.SelectedRtf = rtbQ.Rtf;
rtbZong.SelectedRtf = rtbA.Rtf;
rtbZong.SelectedRtf = rtbYinBiao.Rtf;
rtbZong.SelectedRtf = eg1Eng.Rtf;
rtbZong.SelectedRtf = eg1Ch.Rtf;
rtbZong.SelectedRtf = eg2Eng.Rtf;
rtbZong.SelectedRtf = eg2Ch.Rtf;
rtbZong.SaveFile(login.afold + id中译英, RichTextBoxStreamType.RichText);
}