本文整理汇总了C#中System.Windows.Documents.TextRange.GetPositionAtOffset方法的典型用法代码示例。如果您正苦于以下问题:C# TextRange.GetPositionAtOffset方法的具体用法?C# TextRange.GetPositionAtOffset怎么用?C# TextRange.GetPositionAtOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Documents.TextRange
的用法示例。
在下文中一共展示了TextRange.GetPositionAtOffset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessMessage
static void ProcessMessage(MessageData data, Paragraph messageParagraph, bool append, EmojiProvider emojiProvider)
{
List<string> urls = new List<string>();
List<int> indices = new List<int>();
string[] parts = data.Message.Split(' ');
foreach (string part in parts)
{
if (Regex.IsMatch(part, @"^(http|https|ftp|)\://|[a-zA-Z0-9\-\.]+\.[a-zA-Z](:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$"))
urls.Add(part);
}
if (urls.Count > 0)
{
foreach (string url in urls)
{
indices.Add(data.Message.IndexOf(url));
data.Message = data.Message.Replace(url, "");
}
if (!append)
messageParagraph.Inlines.Add(data.Message);
else
messageParagraph.Inlines.Add("\n" + data.Message);
Inline inline = messageParagraph.Inlines.LastInline;
for (int i = indices.Count; i-- > 0; )
{
string url = urls[i];
int index = append ? indices[i] + 1 : indices[i];
Run run = new Run(url);
TextPointer pointer = new TextRange(inline.ContentStart, inline.ContentEnd).Text == "\n" ? inline.ContentEnd : inline.ContentStart;
Hyperlink link = new Hyperlink(run, pointer.GetPositionAtOffset(index));
link.IsEnabled = true;
link.Click += delegate(object sender, RoutedEventArgs args)
{
try { Process.Start(url); }
catch
{
try { Process.Start("http://" + url); }
catch { }
}
};
}
}
else
{
if (!append)
messageParagraph.Inlines.Add(data.Message);
else
messageParagraph.Inlines.Add("\n" + data.Message);
emojiProvider.ParseText(messageParagraph);
}
}
示例2: ProcessMessage
static void ProcessMessage(MessageData data, Paragraph messageParagraph, bool append, bool isBold)
{
List<string> urls = new List<string>();
List<int> indices = new List<int>();
string[] parts = data.Message.Split(' ');
foreach (string part in parts)
{
if (Regex.IsMatch(part, @"(((file|gopher|news|nntp|telnet|http|ftp|https|ftps|sftp)://)|(www\.))+(([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(/[a-zA-Z0-9\&%_\./-~-]*)?", RegexOptions.IgnoreCase)/*Regex.IsMatch(part, @"^(http|https|ftp|)\://|[a-zA-Z0-9\-\.]+\.[a-zA-Z](:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$")*/)
urls.Add(part);
}
if (urls.Count > 0)
{
foreach (string url in urls)
{
indices.Add(data.Message.IndexOf(url));
data.Message = data.Message.Replace(url, "");
}
messageParagraph.AddMessage(data.Message, append, isBold);
Inline inline = messageParagraph.Inlines.LastInline;
for (int i = indices.Count; i-- > 0; )
{
string url = urls[i];
int index = append ? indices[i] + 1 : indices[i];
Run run = new Run(url);
TextPointer pointer = new TextRange(inline.ContentStart, inline.ContentEnd).Text == "\n" ? inline.ContentEnd : inline.ContentStart;
Hyperlink link = new Hyperlink(run, pointer.GetPositionAtOffset(index));
link.IsEnabled = true;
link.Click += delegate(object sender, RoutedEventArgs args)
{
try { Process.Start(url); }
catch { }
};
}
}
else
{
messageParagraph.AddMessage(data.Message, append, isBold);
}
}