我试图在某些Windows 8.1机器上启用拼写检查时遇到异常(两者都有最新更新,操作系统语言是俄语,.NET框架4.7是俄语)说:
System.Reflection.TargetInvocationException:调用目标抛出了异常.---> System.Runtime.InteropServices.COMException:Windows.Data.Text.WordsSegmenter..ctor处的System.StubHelpers.StubHelpers.GetWinRTFactoryObject(IntPtr pCPCMD)中的注册表值(来自HRESULT的异常:0x80040153(REGDB_E_INVALIDVALUE))无效()字符串语言)---内部异常堆栈跟踪的结束---在System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr,Binder binder)的System.RuntimeMethodHandle.InvokeMethod(Object target,Object []参数,Signature sig,Boolean构造函数)中,对象[]参数,CultureInfo文化)在MS.Internal.WindowsRuntime.Windows.Data.Text.WordsSegmenter..ctor(String language)的MS.Internal.WindowsRuntime.ReflectionHelper.ReflectionNew [TArg1](类型类型,TArg1 arg1)在Syst的System.Windows.Documents.WinRTSpellerInterop.EnsureWordBreakerAndSpellCheckerForCulture(CultureInfo culture,Boolean throwOnError)的MS.Internal.WindowsRuntime.Windows.Data.Text.WordsSegmenter.Create(String language,Boolean shouldPreferNeutralSegmenter)系统.Windows.Documents.WinRTSpellerInterop..ctor()在System.Windows.Documents.SpellerInteropBase.CreateInstance()处于System.Windows.Documents.Speller.EnsureInitialized()处于System.Windows.Documents.Speller.SetCustomDictionaries(CustomDictionarySources dictionaryLocations, System.Windows上的System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)上的System.Windows.Controls.SpellCheck.OnIsEnabledChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)中的System.Windows.Documents.TextEditor.SetCustomDictionaries(Boolean add)处的布尔添加)在System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs参数)在System.Windows.DependencyObject.UpdateEffectiveValue(entryIndex entryIndex,的DependencyProperty DP,PropertyMetadata元数据,EffectiveValueEntry oldEntry,EffectiveValueEntry&newEntry,布尔coerceWithDeferredReference,布尔coerceWithCu .FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs E)System.Windows.DependencyObject.SetValue(DependencyProperty dp,Object value)中的System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp,Object value,PropertyMetadata metadata,Boolean coerceWithDeferredReference,Boolean coerceWithCurrentValue,OperationType operationType,Boolean isInternal)中的rrentValue,OperationType operationType)
此代码可用于重现该问题:
var richTextBox = new RichTextBox();
InputLanguageManager.SetInputLanguage(richTextBox,CultureInfo.GetCultureInfo("en-US"));
richTextBox.SetValue(SpellCheck.IsEnabledProperty, true);
Run Code Online (Sandbox Code Playgroud)
在研究这个问题时,我发现异常是从s_WinRTType描述类型"Windows.Data.Text.WordsSegmenter,Windows,ContentType = WindowsRuntime.WindowsSegmenter似乎是WinRT组件的s_WinRTType.ReflectionNew<string>(language);地方抛出的,所以我看不到里面发生了什么.我想要要知道它为什么抛出REGDB_E_INVALIDVALUE /它寻找的值以及它应该是什么样的?谢谢!
我是Windows Forms的新手.我正在使用VS 2008,C#编写RichTextBox.我想在写入RichTextBox时能够用不同的颜色为每一行着色.有人可以指点我的样品.谢谢
foreach (string file in myfiles)
{
// As I process my files
// richTextBox1.Text += "My processing results";
if(file == "somefileName")
{
// Color above entered line or enter new colored line
}
}
Run Code Online (Sandbox Code Playgroud) RichTextBox我的WPF应用程序中的组件使用a FlowDocument和RichTextBoxs Document属性填充.
rtb.ScrollToEnd();似乎没有做任何事情,我甚至试图调用BringIntoView()添加到构造我的表的最后一行"行" FlowDocument.
有什么建议?谢谢!
我有一点问题.我有一个1 RichTextBox和2个按钮.
我有2个按钮,用于"切换Bold FStyle"和"切换斜体FStyle".
我想在不影响其他FontStyles的情况下切换FontStyles.我希望你能理解我.
下面的代码在组合 FontStyles时有效,但在分离/减去FontStyles时不起作用.
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.SelectionFont = new Font(richTextBox1.Font, (richTextBox1.SelectionFont.Bold == false ? richTextBox1.SelectionFont.Style | FontStyle.Bold : richTextBox1.SelectionFont.Style));
}
private void button2_Click(object sender, EventArgs e)
{
richTextBox1.SelectionFont = new Font(richTextBox1.Font, (richTextBox1.SelectionFont.Italic == false ? richTextBox1.SelectionFont.Style | FontStyle.Italic : richTextBox1.SelectionFont.Style));
}
Run Code Online (Sandbox Code Playgroud)
我正在将很多富文本加载到RichTextBox(WPF)中,我想滚动到内容的结尾:
richTextBox.Document.Blocks.Add(...)
richTextBox.UpdateLayout();
richTextBox.ScrollToEnd();
Run Code Online (Sandbox Code Playgroud)
这不起作用,ScrollToEnd在布局未完成时执行,因此它不会滚动到结尾,它会滚动到文本的前三分之一左右.
有没有办法强制等待,直到RichTextBox完成绘画和布局操作,以便ScrollToEnd实际滚动到文本的末尾?
谢谢.
不起作用的东西:
编辑:我已经尝试过这个LayoutUpdated事件,但它立刻被解雇了,同样的问题:当它被解雇时,控件仍然在richtextbox里面放置更多的文本,所以即使ScrollToEnd它没有工作......我试过这个:
richTextBox.Document.Blocks.Add(...)
richTextBoxLayoutChanged = true;
richTextBox.UpdateLayout();
richTextBox.ScrollToEnd();
Run Code Online (Sandbox Code Playgroud)
并在richTextBox.LayoutUpdated事件处理程序内:
if (richTextBoxLayoutChanged)
{
richTextBoxLayoutChanged = false;
richTextBox.ScrollToEnd();
}
Run Code Online (Sandbox Code Playgroud)
事件被正确触发但是过早,richtextbox在触发时仍然添加更多文本,布局未完成,因此ScrollToEnd再次失败.
编辑2:关注dowhilefor的回答:InvalidateArrange上的MSDN说
失效后,元素将更新其布局,除非随后由UpdateLayout强制,否则将以异步方式进行.
甚至
richTextBox.InvalidateArrange();
richTextBox.InvalidateMeasure();
richTextBox.UpdateLayout();
Run Code Online (Sandbox Code Playgroud)
不要等待:在这些调用之后,richtextbox仍然会添加更多文本并异步地将其放在自身内部.ARG!
全部,我将一个日志文件写入.rtf文件,该文件具有格式下划线,粗体等.我保存了这个文件,并希望RichTextBox稍后再将其读回到持续格式化的文件中.我尝试了以下内容
tmpRichTextBox.LoadFile(@"F:\Path\File.rtf", RichTextBoxStreamType.RichText);
Run Code Online (Sandbox Code Playgroud)
它加载文件,但没有我的原始格式.如果我将.rtf加载到单词中,则会显示格式.我如何阅读.rtf RichTextBox 包括其格式?
谢谢你的时间.
我在WPF窗口上有一个RichTextBox,我使用的类似于控制台输出(仅输出).当我添加NewLine时,如:
rtx_report.AppendText(lclFileInfo.pathOnly + System.Environment.NewLine);
Run Code Online (Sandbox Code Playgroud)
它正确添加了一个新行.(我知道这是从复制文本开始并将其粘贴到其他地方.)但是,在显示中它显示了一个额外的空白行.所以我开始浏览RichTextBox属性,但我不确定哪个设置控制它.
看起来它只是默认为双倍行距的文本,但我没有看到任何控制它的东西.任何人都可以解释如何让它是单间距或不显示额外的线?
TIA,
保罗
==编辑==
PS更多信息按照HatSoft的要求
lclFileInfo.pathOnly的字符串内容是C:\ Users\Paul\Documents\Roadway
但是,所有这些代码行都会出现同样的问题:
rtx_report.AppendText("File Changed:" + System.Environment.NewLine);
rtx_report.AppendText(lclFileInfo.pathOnly + System.Environment.NewLine);
if (lclFileInfo.isDirectory == false)
rtx_report.AppendText(lclFileInfo.fileNameOnly + System.Environment.NewLine);
rtx_report.AppendText("Changed On: " + lclFileInfo.currentTimestamp + System.Environment.NewLine);
Run Code Online (Sandbox Code Playgroud) 在rtb中格式化文本时,我的性能很差:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<Button Click="ApplyFormatClick">ApplyFormat</Button>
<TextBlock x:Name="Time"/>
</StackPanel>
<RichTextBox x:Name="Rtb" Grid.Row="1">
<RichTextBox.Document>
<FlowDocument>
<Paragraph>
<Run>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt …Run Code Online (Sandbox Code Playgroud) 我有一个RichTextBox包含数千行文字的文章.通过做... 我可以很容易地SET通过使用第一条可见线ScrollToCaret()
this.SelectionStart = this.Find(this.Lines[lineIndex], RichTextBoxFinds.NoHighlight);
this.ScrollToCaret();
Run Code Online (Sandbox Code Playgroud)
但我希望能够GET成为第一条可见线.有什么建议?
所以我试图在我的.net 4.5项目中使用David Veeneman的Bindable WPF RichTextBox.添加控件后,ValueConverter在我的代码中,我注意到只会public object Convert()触发但public object ConvertBack()不会触发.
在阅读了对该项目的评论后,我更改了控制源代码的以下部分.
private static void OnDocumentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var thisControl = (EcoRichTextBox)d;
if (thisControl.m_InternalUpdatePending > 0)
{
thisControl.m_InternalUpdatePending--;
return;
}
// Changed:
try
{
thisControl.TextBox.Document = (e.NewValue == null) ? new FlowDocument() : (FlowDocument)e.NewValue;
}
catch { }
thisControl.m_TextHasChanged = false;
}
Run Code Online (Sandbox Code Playgroud)
而这个事件处理程序:
private void OnTextChanged(object sender, TextChangedEventArgs e)
{
// Set the TextChanged flag
m_TextHasChanged = true;
// Changed:
Document = …Run Code Online (Sandbox Code Playgroud) richtextbox ×10
c# ×7
wpf ×6
winforms ×4
.net ×2
flowdocument ×2
scroll ×2
.net-4.5 ×1
fonts ×1
layout ×1
loaded ×1
mvvm ×1
performance ×1
richtext ×1
textbox ×1