{
// set Font Family, size and styles
_richtextBox.SelectionFont = selectedStyle.Font;
}
else if (selectedStyle.PointSize > 0 && _richtextBox.Font.SizeInPoints != selectedStyle.PointSize)
{
// use control's font family, set size and styles
float size = selectedStyle.PointSize > 0.0f ? selectedStyle.PointSize : _richtextBox.Font.SizeInPoints;
_richtextBox.SelectionFont = new Font(_richtextBox.Font.FontFamily.Name, size, selectedStyle.FontStyle);
}
else if (_richtextBox.Font.Style != selectedStyle.FontStyle)
{
// use control's font family and size, set styles
_richtextBox.SelectionFont = new Font(_richtextBox.Font, selectedStyle.FontStyle);
}
}
_richtextBox.AppendText(RenderLoggingEvent(loggingEvent));
}
/// <summary>
/// Remove reference to RichTextBox when container form is closed
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void containerForm_FormClosed(object sender, FormClosedEventArgs e)
{
RichTextBox = null;
}
/// <summary>
/// Remove references to container form
/// </summary>
protected override void OnClose()
{
base.OnClose();
if (_containerForm != null)
{
_containerForm.FormClosed -= new FormClosedEventHandler(containerForm_FormClosed);
_containerForm = null;
}
}
/// <summary>
/// This appender requires a <see cref="Layout"/> to be set.
/// </summary>
/// <value><c>true</c></value>
/// <remarks>
/// <para>
/// This appender requires a <see cref="Layout"/> to be set.
/// </para>
/// </remarks>
protected override bool RequiresLayout
{
get
{
return true;
}
}
#endregion
#region Public Static Methods
/// <summary>
/// Assign a RichTextBox to a RichTextBoxAppender
/// </summary>
/// <param name="richTextBox">Reference to RichTextBox control that will display logging events</param>
/// <param name="appenderName">Name of RichTextBoxAppender (case-sensitive)</param>
/// <returns>True if a RichTextBoxAppender named <code>appenderName</code> was found</returns>
/// <remarks>
/// <para>This method sets the RichTextBox property of the RichTextBoxAppender
/// in the default repository with <code>Name == appenderName</code>.</para>
/// </remarks>
/// <example>
/// <code lang="C#">
/// private void MainForm_Load(object sender, EventArgs e)
/// {
/// log4net.Appender.RichTextBoxAppender.SetRichTextBox(logRichTextBox, "MainFormRichTextAppender");