/// <summary> /// Returns a target attached to a given RichTextBox control /// </summary> /// <param name="control">a RichTextBox control for which the target is to be returned</param> /// <returns>A RichTextBoxTarget attached to a given control or <code>null</code> if no target is attached</returns> public static RichTextBoxTarget GetTargetByControl(RichTextBox control) { foreach (Target target in LogManager.Configuration.AllTargets) { RichTextBoxTarget textboxTarget = target as RichTextBoxTarget; if (textboxTarget != null && textboxTarget.TargetRichTextBox == control) { return(textboxTarget); } } return(null); }
/// <summary> /// Attempts to attach existing targets that have yet no textboxes to controls that exist on specified form if appropriate /// </summary> /// <remarks> /// Setting <see cref="AllowAccessoryFormCreation"/> to true (default) actually causes target to always have a textbox /// (after having <see cref="InitializeTarget"/> called), so such targets are not affected by this method. /// </remarks> /// <param name="form">a Form to check for RichTextBoxes</param> public static void ReInitializeAllTextboxes(Form form) { InternalLogger.Info("Executing ReInitializeAllTextboxes for Form {0}", form); foreach (Target target in LogManager.Configuration.AllTargets) { RichTextBoxTarget textboxTarget = target as RichTextBoxTarget; if (textboxTarget != null && textboxTarget.FormName == form.Name) { //can't use InitializeTarget here as the Application.OpenForms would not work from Form's constructor RichTextBox textboxControl = FormHelper.FindControl <RichTextBox>(textboxTarget.ControlName, form); if (textboxControl != null && !textboxControl.IsDisposed) { if (textboxTarget.TargetRichTextBox == null || textboxTarget.TargetRichTextBox.IsDisposed || textboxTarget.TargetRichTextBox != textboxControl ) { textboxTarget.AttachToControl(form, textboxControl); } } } } }