大佬教程收集整理的这篇文章主要介绍了尝试使用C#SpellCheck类,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
您必须使用WPF TextBox才能进行拼写检查。您可以使用ElementHost控件将其嵌入windows窗体表单中。它的工作原理与UserControl非常相似。这是一个您可以直接从工具箱中放下的控件。首先,您需要Project + Add Reference,然后选择windowsFormsIntegration,System.Design和WPF程序集PresentationCore,PresentationFramework和windowsBase。
将新类添加到您的项目中,然后粘贴以下代码。编译。将SpellBox控件从工具箱的顶部拖放到窗体上。它支持TextChanged事件以及Multiline和WorDWrap属性。字体存在困扰,没有简单的方法可以将WF字体映射到WPF字体属性。最简单的解决方法是将窗体的Font设置为WPF的默认“ Segoe UI”。
using System;
using System.ComponentModel;
using System.ComponentModel.Design.serialization;
using System.windows;
using System.windows.Controls;
using System.windows.Forms.Integration;
using System.windows.Forms.Design;
[Designer(typeof(ControlDesigner))]
//[Designerserializer("System.windows.Forms.Design.ControlCodeDomserializer, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.serialization.CodeDomserializer, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
class SpellBox : ElementHost {
public SpellBox() {
Box = new TextBox();
base.Child = Box;
Box.TextChanged += (s, E) => OntextChanged(EventArgs.Empty);
Box.Spellcheck.IsEnabled = true;
Box.VerticalScrollbarVisibility = ScrollbarVisibility.auto;
this.Size = new System.Drawing.Size(100, 20);
}
public overrIDe String Text {
get { return Box.Text; }
set { Box.Text = value; }
}
[DefaultValue(false)]
public bool Multiline {
get { return Box.AcceptsReturn; }
set { Box.AcceptsReturn = value; }
}
[DefaultValue(false)]
public bool WorDWrap {
get { return Box.textwrapPing != textwrapPing.nowrap; }
set { Box.textwrapPing = value ? textwrapPing.Wrap : textwrapPing.nowrap; }
}
[DesignerserializationVisibility(DesignerserializationVisibility.HIDden)]
public new System.windowS.UIElement Child {
get { return base.Child; }
set { /* Do nothing to solve a problem with the serializer !! */ }
}
private TextBox Box;
}
根据普遍的需求,此代码的VB.NET版本避免使用lambda:
imports System
imports System.ComponentModel
imports System.ComponentModel.Design.serialization
imports System.windows
imports System.windows.Controls
imports System.windows.Forms.Integration
imports System.windows.Forms.Design
<Designer(GetType(ControlDesigner))> _
Class SpellBox
inherits ElementHost
Public Sub New()
Box = New TextBox()
MyBase.Child = Box
AddHandler Box.TextChanged, AddressOf Box_TextChanged
Box.Spellcheck.IsEnabled = True
Box.VerticalScrollbarVisibility = ScrollbarVisibility.auto
Me.Size = New System.Drawing.Size(100, 20)
End Sub
Private Sub Box_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
OntextChanged(EventArgs.Empty)
End Sub
Public OverrIDes Property Text() As String
Get
Return Box.Text
End Get
Set(ByVal value As String)
Box.Text = value
End Set
End Property
<DefaultValue(false)> _
Public Property Multiline() As @R_772_8487@an
Get
Return Box.AcceptsReturn
End Get
Set(ByVal value As @R_772_8487@an)
Box.AcceptsReturn = value
End Set
End Property
<DefaultValue(false)> _
Public Property WorDWrap() As @R_772_8487@an
Get
Return Box.textwrapPing <> textwrapPing.nowrap
End Get
Set(ByVal value As @R_772_8487@an)
If value Then
Box.textwrapPing = textwrapPing.Wrap
Else
Box.textwrapPing = textwrapPing.nowrap
End If
End Set
End Property
<DesignerserializationVisibility(DesignerserializationVisibility.HIDden)> _
Public Shadows Property Child() As System.windowS.UIElement
Get
Return MyBase.Child
End Get
Set(ByVal value As System.windowS.UIElement)
'' Do nothing to solve a problem with the serializer !!
End Set
End Property
Private Box As TextBox
End Class
以上是大佬教程为你收集整理的尝试使用C#SpellCheck类全部内容,希望文章能够帮你解决尝试使用C#SpellCheck类所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。