本文整理汇总了C#中System.Windows.Forms.RichTextBox.Cut方法的典型用法代码示例。如果您正苦于以下问题:C# RichTextBox.Cut方法的具体用法?C# RichTextBox.Cut怎么用?C# RichTextBox.Cut使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.RichTextBox
的用法示例。
在下文中一共展示了RichTextBox.Cut方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AppendInternal
public static void AppendInternal(RichTextBox richTextBox, Color colorFore, Color colorBack, FontStyle newStyle, string text)
{
if(richTextBox != null && !string.IsNullOrEmpty(text) && !richTextBox.IsDisposed)
{
if(richTextBox.InvokeRequired)
{
richTextBox.BeginInvoke(new MethodInvoker(delegate() { AppendInternal(richTextBox, colorFore, colorBack, newStyle, text); }));
}
else
{
lock(richTextBox)
{
richTextBox.SuspendLayout();
//Truncate as necessary
if(richTextBox.Text.Length + text.Length > _maxConsoleTextLength)
{
int truncateLength = _maxConsoleTextLength / 4;
int endmarker = richTextBox.Text.IndexOf('\n', truncateLength) + 1;
if(endmarker < truncateLength)
endmarker = truncateLength;
richTextBox.Select(0, endmarker);
richTextBox.Cut();
}
int originalTextEnd = richTextBox.Text.Length;
richTextBox.AppendText(text);
richTextBox.Select(originalTextEnd, text.Length);
if(colorFore != Color.Empty)
richTextBox.SelectionColor = colorFore;
if(colorBack != Color.Empty)
richTextBox.SelectionBackColor = colorBack;
//if(newStyle != richTextBox.Font.Style)
richTextBox.SelectionFont = new Font(richTextBox.Font, newStyle);
richTextBox.SelectionLength = 0;
richTextBox.ScrollToCaret();
richTextBox.ResumeLayout();
richTextBox.Update();
}
}
}
}
示例2: Update
internal static void Update(RichTextBox box)
{
if (appendQueue.IsEmpty) return;
var start = box.SelectionStart;
var len = box.SelectionLength;
var scroll = box.TextLength == start;
LogLine result;
box.Select(box.TextLength, 0);
while (appendQueue.TryDequeue(out result)) {
box.SelectionColor = result.color;
box.AppendText(result.line+"\r\n");
writer.WriteLine(result.line);
lines++;
}
writer.Flush();
if (lines > maxLines) {
box.ReadOnly = false;
while (lines > maxLines) {
var lineLen = box.Text.IndexOf('\n') + 1;
box.Select(0, lineLen);
box.Cut();
start -= lineLen;
lines--;
}
box.ReadOnly = true;
}
if (scroll) {
box.Select(box.TextLength, 0);
box.ScrollToCaret();
} else if (start + len > 0) {
if (start < 0) {
len += start;
start = 0;
}
box.Select(start, len);
}
}
示例3: Gui
//.........这里部分代码省略.........
};
options.MenuItems.Add(copy);
chatBox.ContextMenu = options;
}
};
//input send panel, split from chat panel
//anchored to only bottom, left, right to make height constant during scaling
inputSendPanel.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
//contains the input box and send button
inputSendPanel.Controls.Add(sendButton);
inputSendPanel.Controls.Add(inputBox);
inputSendPanel.Location = new Point(0, 500);
inputSendPanel.Name = "InputSendPanel";
inputSendPanel.Size = new Size(400, 100);
inputSendPanel.TabIndex = 1;
//input box, split from the send button
//anchored ot all sides to maintain proportional scaling
inputBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
inputBox.Location = new Point(0, 0);
inputBox.Name = "InputBox";
inputBox.Size = new Size(300, 100);
inputBox.TabIndex = 2;
inputBox.Text = "";
//right mouse click will pull up the option to cut/copy/paste the input box with the clipboard
inputBox.MouseUp += (sender, args) =>
{
if (args.Button == MouseButtons.Right)
{
ContextMenu options = new ContextMenu();
MenuItem cut = new MenuItem("Cut");
cut.Click += (cutSender, cutArgs) =>
{
inputBox.Cut();
};
options.MenuItems.Add(cut);
MenuItem copy = new MenuItem("Copy");
copy.Click += (copySender, copyArgs) =>
{
Clipboard.SetData(DataFormats.Rtf, inputBox.SelectedRtf);
};
options.MenuItems.Add(copy);
MenuItem paste = new MenuItem("Paste");
paste.Click += (pasteSender, pasteArgs) =>
{
if (Clipboard.ContainsText(TextDataFormat.Rtf))
{
inputBox.SelectedRtf = Clipboard.GetData(DataFormats.Rtf).ToString();
}
};
options.MenuItems.Add(paste);
inputBox.ContextMenu = options;
}
};
//send button, split from input box
//anchored to only top, bottom, right to make width constant during scaling
sendButton.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
sendButton.Location = new Point(300, 0);
sendButton.Name = "SendButton";
示例4: RichTextBoxContextMenu
private void RichTextBoxContextMenu(RichTextBox richTextBox)
{
ContextMenu cm = new ContextMenu();
MenuItem mi = new MenuItem("Cut");
mi.Click += (a, b) => { richTextBox.Cut(); };
cm.MenuItems.Add(mi);
mi = new MenuItem("Copy");
mi.Click += (a, b) =>
{
richTextBox.Copy();
};
cm.MenuItems.Add(mi);
mi = new MenuItem("Paste");
mi.Click += (a, b) =>
{
richTextBox.Paste(DataFormats.GetFormat(DataFormats.UnicodeText));
};
cm.MenuItems.Add(mi);
richTextBox.ContextMenu = cm;
}
示例5: ReadingPassageONQuestion
public string ReadingPassageONQuestion(int questionNO, int spiltQuestionNO)
{
RichTextBox box = new RichTextBox();
if (spiltQuestionNO != 0)
{
string text;
string str2;
RichTextBox box2 = new RichTextBox();
int num = 0;
int index = 0;
if (questionNO <= spiltQuestionNO)
{
box2.Rtf = this.FullRTF;
text = box2.Text;
num = text.IndexOf("<PASSAGE1>") + 10;
index = text.IndexOf("</PASSAGE1>");
box2.SelectionStart = num;
box2.SelectionLength = index - num;
box.Rtf = box2.SelectedRtf;
box2.Rtf = this.FullTranslation;
str2 = box2.Text;
num = str2.IndexOf("<TRANSLATION1>") + 14;
index = str2.IndexOf("</TRANSLATION1>");
box2.SelectionStart = num;
box2.SelectionLength = index - num;
this.Translation = box2.SelectedRtf;
}
else
{
box2.Rtf = this.FullRTF;
text = box2.Text;
num = text.IndexOf("<PASSAGE2>") + 10;
index = text.IndexOf("</PASSAGE2>");
box2.SelectionStart = num;
box2.SelectionLength = index - num;
box.Rtf = box2.SelectedRtf;
box2.Rtf = this.FullTranslation;
str2 = box2.Text;
num = str2.IndexOf("<TRANSLATION2>") + 14;
index = str2.IndexOf("</TRANSLATION2>");
box2.SelectionStart = num;
box2.SelectionLength = index - num;
this.Translation = box2.SelectedRtf;
}
}
else
{
box.Rtf = this.FullRTF;
this.Translation = this.FullTranslation;
}
for (int i = 1; i < ConstantValues.MAXQUESTIONCOUNT; i++)
{
string str3;
string str4;
int num4;
int num5;
if (i == questionNO)
{
str3 = "<" + i.ToString() + ">";
str4 = "</" + i.ToString() + ">";
num4 = box.Text.IndexOf(str3);
num5 = box.Text.IndexOf(str4);
RichTextBox box3 = new RichTextBox();
while ((num4 >= 0) && (num5 >= 0))
{
box.SelectionStart = num4;
box.SelectionLength = str3.Length;
box.Cut();
box.SelectedRtf = "";
box.SelectionStart = num5 - str3.Length;
box.SelectionLength = str4.Length;
box.Cut();
box.SelectedRtf = "";
num4 = box.Text.IndexOf(str3);
num5 = box.Text.IndexOf(str4);
}
str3 = "[" + i.ToString() + "]";
str4 = "[/" + i.ToString() + "]";
num4 = box.Text.IndexOf(str3);
num5 = box.Text.IndexOf(str4);
if (num4 >= 0)
{
box.SelectionStart = num4;
box.SelectionLength = str3.Length;
box.Cut();
box.SelectedRtf = "";
}
if (num5 >= 0)
{
box.SelectionStart = num5 - str3.Length;
box.SelectionLength = str4.Length;
box.Cut();
box.SelectedRtf = "";
}
str3 = "{" + i.ToString() + "}";
str4 = "{/" + i.ToString() + "}";
num4 = box.Text.IndexOf(str3);
num5 = box.Text.IndexOf(str4);
while ((num4 >= 0) || (num5 >= 0))
{
//.........这里部分代码省略.........
示例6: GetCurrentRichTextBox
public void 剪切TToolStripMenuItem_Click(object sender, EventArgs e)
{
r = GetCurrentRichTextBox();
if (r.SelectedText == "")
return;
else
r.Cut();
}