-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathTextEditorForm.cs
More file actions
96 lines (87 loc) · 3.08 KB
/
TextEditorForm.cs
File metadata and controls
96 lines (87 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// <copyright file="TextEditorForm.cs" company="Johann Blais">
// Copyright (c) 2008 All Right Reserved
// </copyright>
// <author>Johann Blais</author>
// <summary>Text editor form for InformationBox content</summary>
namespace InfoBox.Designer
{
using System;
using System.Drawing;
using System.Windows.Forms;
/// <summary>
/// Text editor form for editing InformationBox content.
/// </summary>
public partial class TextEditorForm : Form
{
private readonly InformationBoxDesigner parentDesigner;
private bool isUpdating = false;
/// <summary>
/// Initializes a new instance of the <see cref="TextEditorForm"/> class.
/// </summary>
/// <param name="parentDesigner">The parent designer form.</param>
public TextEditorForm(InformationBoxDesigner parentDesigner)
{
this.parentDesigner = parentDesigner ?? throw new ArgumentNullException(nameof(parentDesigner));
this.InitializeComponent();
this.SetupDataBinding();
}
/// <summary>
/// Sets up data binding between the text editor and parent designer.
/// </summary>
private void SetupDataBinding()
{
// Set up two-way synchronization
this.txtContent.Text = this.parentDesigner.TextContent.Text;
this.txtContent.TextChanged += TxtContent_TextChanged;
this.parentDesigner.TextContent.TextChanged += ParentText_TextChanged;
}
/// <summary>
/// Handles text changes in the editor.
/// </summary>
private void TxtContent_TextChanged(object sender, EventArgs e)
{
if (!isUpdating)
{
isUpdating = true;
this.parentDesigner.TextContent.Text = this.txtContent.Text;
isUpdating = false;
}
}
/// <summary>
/// Handles text changes in the parent designer.
/// </summary>
private void ParentText_TextChanged(object sender, EventArgs e)
{
if (!isUpdating)
{
isUpdating = true;
this.txtContent.Text = this.parentDesigner.TextContent.Text;
isUpdating = false;
}
}
/// <summary>
/// Cleans up event handlers when the form is closed.
/// </summary>
protected override void OnFormClosing(FormClosingEventArgs e)
{
// Unsubscribe from events
this.txtContent.TextChanged -= TxtContent_TextChanged;
this.parentDesigner.TextContent.TextChanged -= ParentText_TextChanged;
base.OnFormClosing(e);
}
/// <summary>
/// Updates the font and color from the parent designer.
/// </summary>
public void UpdateFontAndColor(Font font, Color color)
{
if (font != null)
{
this.txtContent.Font = font;
}
if (color != Color.Empty)
{
this.txtContent.ForeColor = color;
}
}
}
}