|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Note: This control is totally standalone. If you've downloaded it before, please do again as I accidenly left some third party references in the demo project. IntroductionThis article was prompted by comments about Rich Parson's RichTextBoxExtended Control. This is a very useful control that includes a tool bar to augment the existing
The comments from users were very positive, but there was a desire to be able to set the content of a rich text control via the Minor ChangesI made a few minor changes unconnected with persistence that I hope won't be controversial.
GotyasWhen working with the existing How to get the Rtf property to workIn order for consumers of the We must ensure that this event is triggered whenever the content has been updated. The obvious case is when the user has updated the content directly. This, we check in a [Category("Property Changed")]
public event EventHandler RtfChanged;
[
System.ComponentModel.Description("Contents in Rtf format"),
RecommendedAsConfigurable(true),
Category("Data"),
Bindable(true),
Editor(typeof(Design.RichTextBoxExtendedEditor),
typeof(System.Drawing.Design.UITypeEditor))
]
public string Rtf
{
get
{ return rtb1.Rtf;
}
set
{ rtb1.Rtf= value;
if (RtfChanged!=null)
RtfChanged(this,EventArgs.Empty);
}
}
#endregion
private void rtb1_TextChanged(object sender, System.EventArgs e)
{
if (RtfChanged!=null)
RtfChanged(this,EventArgs.Empty);
}
private void rtb1_Leave(object sender, System.EventArgs e)
{
if (this.rtb1.Modified && RtfChanged!=null)
RtfChanged(this,EventArgs.Empty);
}
Providing a Property Editor for the Rtf PropertyThere's a pleasing recursion here, as the
Implementing a property editor is accomplished by adding the class RichTextBoxExtendedRtfEditor:System.Drawing.Design.UITypeEditor
{
public override System.Drawing.Design.UITypeEditorEditStyle
GetEditStyle(ITypeDescriptorContext context)
{
if (context==null)
return base.GetEditStyle(null);
return System.Drawing.Design.UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider, object value)
{
if (context!=null && provider!=null)
{
IWindowsFormsEditorService edSrv=
(IWindowsFormsEditorService)
provider.GetService(typeof(IWindowsFormsEditorService));
if (edSrv!=null)
{
RichTextBoxExtendedRtfEditorForm dialog=
new RichTextBoxExtendedRtfEditorForm();
if (value is String)
dialog.Value= (string)value;
if (edSrv.ShowDialog(dialog)==
System.Windows.Forms.DialogResult.OK)
value= dialog.Value;
dialog.Dispose();
dialog= null;
}
}
return value;
}
}
Data Binding and Automatic BindingOnce persistence of A standalone solution (RichTextExtended.sln) has been provided in the demo project. If you use AgileStudio, a solution has also been included (RichTextBoxExtended2.sln) that implements automatic binding. In fact, I used this mechanism to knock together the demo app really quickly. ConclusionThis modified However, if you want to go one step further, the automatic binding in AgileStudio makes it really fly as this automatically builds the SQL Server database and builds the stored procedures, typed datasets, and bindings when you just drop the
|
||||||||||||||||||||||