本文整理汇总了C#中System.Windows.Controls.RichTextBox.Focus方法的典型用法代码示例。如果您正苦于以下问题:C# RichTextBox.Focus方法的具体用法?C# RichTextBox.Focus怎么用?C# RichTextBox.Focus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.RichTextBox
的用法示例。
在下文中一共展示了RichTextBox.Focus方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormatRichText
public FormatRichText()
{
Title = "Format Rich Text";
// Create DockPanel as content of window.
DockPanel dock = new DockPanel();
Content = dock;
// Create ToolBarTray docked at top of client area.
ToolBarTray tray = new ToolBarTray();
dock.Children.Add(tray);
DockPanel.SetDock(tray, Dock.Top);
// Create RichTextBox.
txtbox = new RichTextBox();
txtbox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
// Call methods in other files.
AddFileToolBar(tray, 0, 0);
AddEditToolBar(tray, 1, 0);
AddCharToolBar(tray, 2, 0);
AddParaToolBar(tray, 2, 1);
AddStatusBar(dock);
// Fill rest of client area with RichTextBox and give it focus.
dock.Children.Add(txtbox);
txtbox.Focus();
}
示例2: EditSomeRichTest
public EditSomeRichTest()
{
Title = "Edit Some Rich Text";
txtBox = new RichTextBox();
txtBox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
Content = txtBox;
txtBox.Focus();
}
示例3: InsertPhrase
protected void InsertPhrase(RichTextBox rtb, string phraseCategory)
{
string phrase = PickListControl.ShowPickList(User, PickListType.Phrase, phraseCategory, TraitCategoryType.Taxon);
if (phrase != null) {
var tr = new TextRange(rtb.Selection.Start, rtb.Selection.End);
tr.Text = phrase;
rtb.Focus();
}
}
示例4: SelectText
public static void SelectText(RichTextBox myRichTextBox, string input)
{
TextPointer textPointer = (TextPointer) null;
string str = input;
if (string.IsNullOrEmpty(str))
return;
for (TextPointer position1 = myRichTextBox.Document.ContentStart; position1 != null && position1.CompareTo(myRichTextBox.Document.ContentEnd) < 0; position1 = position1.GetNextInsertionPosition(LogicalDirection.Forward) ?? myRichTextBox.Document.ContentStart)
{
TextPointer position2 = position1;
for (int index = 0; position2 != null && index < str.Length; ++index)
position2 = position2.GetNextInsertionPosition(LogicalDirection.Forward);
if (position2 != null)
{
TextRange textRange = new TextRange(position1, position2);
if (textRange.Text == str)
{
myRichTextBox.Focus();
myRichTextBox.Selection.Select(textRange.Start, textRange.End);
textPointer = position2.GetNextInsertionPosition(LogicalDirection.Forward);
break;
}
}
}
}
示例5: CraftTheToolbar
public CraftTheToolbar()
{
Title = "Craft the Toolbar";
RoutedUICommand[] comm =
{
ApplicationCommands.New, ApplicationCommands.Open,
ApplicationCommands.Save, ApplicationCommands.Print,
ApplicationCommands.Cut, ApplicationCommands.Copy,
ApplicationCommands.Paste, ApplicationCommands.Delete
};
string[] strImages =
{
"NewDocumentHS.png", "openHS.png", "saveHS.png",
"PrintHS.png", "CutHS.png", "CopyHS.png",
"PasteHS.png", "DeleteHS.png"
};
// Create DockPanel as content of window.
DockPanel dock = new DockPanel();
dock.LastChildFill = false;
Content = dock;
// Create Toolbar docked at top of window.
ToolBar toolbar = new ToolBar();
dock.Children.Add(toolbar);
DockPanel.SetDock(toolbar, Dock.Top);
RichTextBox txtbox = new RichTextBox();
dock.Children.Add(txtbox);
txtbox.Focus();
// Create the Toolbar buttons.
for (int i = 0; i < 8; i++)
{
if (i == 4)
toolbar.Items.Add(new Separator());
// Create the Button.
Button btn = new Button();
btn.Command = comm[i];
toolbar.Items.Add(btn);
// Create an Image as content of the Button.
Image img = new Image();
img.Source = new BitmapImage(
new Uri("pack://application:,,/Images/" + strImages[i]));
img.Stretch = Stretch.None;
btn.Content = img;
//StackPanel stack = new StackPanel();
//stack.Orientation = Orientation.Horizontal;
//btn.Content = stack;
//TextBlock txtblk = new TextBlock();
//txtblk.Text = comm[i].Text;
//stack.Children.Add(img);
//stack.Children.Add(txtblk);
// Create a ToolTip based on the UICommand text.
ToolTip tip = new ToolTip();
tip.Content = comm[i].Text;
btn.ToolTip = tip;
// �̺�Ʈ �ڵ鷯�� RoutedUICommand ��ü�� �����ϱ� ���� Ŀ�ǵ� ���ε� �÷��ǿ� Ŀ��Ʈ ��ü�� �߰����ش�.
CommandBindings.Add(
new CommandBinding(comm[i], ToolBarButtonOnClick));
}
}
示例6: SetRichTextBoxData
//.........这里部分代码省略.........
SetImageBindBox(box, imageByte); //控件绑定
x = (int)endleng + 1024;
if (x == RichBoxData.Length - 2)
{
x++;
}
} // 处理文字信息
else
{
byte[] textByte = null;
if (starleng == 0 && isendtext == true) //所有都是文字处理方式
{
textByte = new byte[RichBoxData.Length - x];
if (RichBoxData.Length == x)
{
break;
}
Array.Copy(RichBoxData, x, textByte, 0, (int)(RichBoxData.Length - x));
}
if (starleng > x - 1024) // 当前位置小于开始图片位置
{
textByte = new byte[starleng - x + 1024];
Array.Copy(RichBoxData, x, textByte, 0, (int)(starleng - x + 1024));
}
SetTextBindBox(box, textByte, 1);
//using (MemoryStream stream = new MemoryStream(textByte))
//{
// using (StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8))
// {
// string Xaml = reader.ReadToEnd();
// Run myRun = new Run();
// myRun.Text = Xaml;
// box.Selection.Insert(myRun);
// }
//}
if (starleng == 0) //所有都是文字处理方式 没有图片时跳出循环
{
x = RichBoxData.Length - 1;
break;
}
if (starleng > x - 1024) //当当前位置
{
x = 1024 + (int)starleng;
byte[] imageByte = new byte[endleng - starleng];
Array.Copy(RichBoxData, x, imageByte, 0, (int)(endleng - starleng));
SetImageBindBox(box, imageByte); //控件绑定
x = (int)endleng + 1024;
if (x == RichBoxData.Length - 2)
{
x++;
}
}
}
}
}
else
{
#region 判断没有图片的时候
if (starleng == 0 && endleng == 0)
{
byte[] strByte = new byte[RichBoxData.Length - 1024];
Array.Copy(RichBoxData, 1024, strByte, 0, RichBoxData.Length - 1024);
SetTextBindBox(box, strByte, 1);
break;
}
#endregion
}
}
}
else
{
//SetTextBindBox(box, RichBoxData,1);
using (MemoryStream stream = new MemoryStream(RichBoxData))
{
using (StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8))
{
string Xaml = reader.ReadToEnd();
Run myRun = new Run();
myRun.Text = Xaml;
box.Selection.Insert(myRun);
}
}
}
//box.SelectAll();
//box.Selection.ApplyPropertyValue(Run.FontSizeProperty, "12");
TextPointer startPointer = box.ContentStart.GetNextInsertionPosition(LogicalDirection.Forward);
TextPointer MyTP1 = startPointer.GetPositionAtOffset(0, LogicalDirection.Forward);
box.Selection.Select(startPointer, MyTP1);
box.Focus();
}
示例7: ReturnFocus
private static void ReturnFocus(RichTextBox box)
{
if (box != null)
box.Focus();
}
示例8: EditRecord_Click
private void EditRecord_Click(object sender, RoutedEventArgs e)
{
MenuItem menuItem = e.Source as MenuItem;
if (menuItem == null)
return;
ContextMenu contextMenu = menuItem.Parent as ContextMenu;
if (contextMenu == null)
return;
DockPanel activePanel = contextMenu.PlacementTarget as DockPanel;
if (activePanel == null)
return;
int id = 0;
if (int.TryParse(activePanel.Tag.ToString(), out id))
{
FlowDocumentScrollViewer textViewer = activePanel.Children.OfType<FlowDocumentScrollViewer>().FirstOrDefault();
if (textViewer == null)
return;
//copy document from selected record to newPost RichTextBox
RichTextBox updatedPost = new RichTextBox();
updatedPost.Tag = id.ToString();
updatedPost.LostFocus += UpdatedPost_LostFocus;
TextRange tr = new TextRange(textViewer.Document.ContentStart, textViewer.Document.ContentEnd);
MemoryStream ms = new MemoryStream();
tr.Save(ms, DataFormats.Rtf);
TextRange range2 = new TextRange(updatedPost.Document.ContentEnd, updatedPost.Document.ContentEnd);
range2.Load(ms, DataFormats.Rtf);
activePanel.Children.Remove(textViewer);
activePanel.Children.Add(updatedPost);
updatedPost.Focus();
}
}
示例9: ReturnFocus
private void ReturnFocus(RichTextBox textBox)
{
if (textBox != null)
textBox.Focus();
}
示例10: SetRichTextBoxValue
private void SetRichTextBoxValue(RichTextBox varControl, string text)
{
if (varControl.Dispatcher.CheckAccess())
{
varControl.Document = new FlowDocument(new Paragraph(new Run(text)));
varControl.Focus();
}
else
{
varControl.Dispatcher.Invoke(new Action<RichTextBox, string>((c, t) => SetRichTextBoxValue(varControl, text)), new object[] { varControl, text });
}
}