Skip to content

Commit f7a0630

Browse files
authored
54 expand the designer text textbox and display the text in the selected font (#58)
* Added simple elipsis form for the content * Simplified the designer side window
1 parent 2dc3696 commit f7a0630

File tree

7 files changed

+391
-48
lines changed

7 files changed

+391
-48
lines changed

InfoBox.Designer/InfoBox.Designer.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@
9898
</Compile>
9999
<Compile Include="Program.cs" />
100100
<Compile Include="Properties\AssemblyInfo.cs" />
101+
<Compile Include="TextEditorForm.cs">
102+
<SubType>Form</SubType>
103+
</Compile>
104+
<Compile Include="TextEditorForm.Designer.cs">
105+
<DependentUpon>TextEditorForm.cs</DependentUpon>
106+
</Compile>
101107
<EmbeddedResource Include="InformationBoxDesigner.resx">
102108
<SubType>Designer</SubType>
103109
<DependentUpon>InformationBoxDesigner.cs</DependentUpon>
@@ -112,6 +118,10 @@
112118
<DependentUpon>Resources.resx</DependentUpon>
113119
<DesignTime>True</DesignTime>
114120
</Compile>
121+
<EmbeddedResource Include="TextEditorForm.resx">
122+
<SubType>Designer</SubType>
123+
<DependentUpon>TextEditorForm.cs</DependentUpon>
124+
</EmbeddedResource>
115125
<None Include="app.config" />
116126
<None Include="InfoBox.Designer_TemporaryKey.pfx" />
117127
<None Include="Properties\app.manifest" />

InfoBox.Designer/InformationBoxDesigner.Designer.cs

Lines changed: 19 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

InfoBox.Designer/InformationBoxDesigner.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,25 @@ public partial class InformationBoxDesigner : Form
4040
/// </summary>
4141
private Color messageFontColor = Color.Empty;
4242

43+
/// <summary>
44+
/// Text editor form instance
45+
/// </summary>
46+
private TextEditorForm textEditorForm = null;
47+
4348
#endregion Attributes
4449

50+
#region Properties
51+
52+
/// <summary>
53+
/// Gets the text content control for data binding.
54+
/// </summary>
55+
public TextBox TextContent
56+
{
57+
get { return this.txbText; }
58+
}
59+
60+
#endregion Properties
61+
4562
#region Constructors
4663

4764
/// <summary>
@@ -861,6 +878,24 @@ private void BtnMessageColor_Click(object sender, EventArgs e)
861878

862879
#endregion Fonts
863880

881+
/// <summary>
882+
/// Handles the Click event of the btnEditText control.
883+
/// </summary>
884+
/// <param name="sender">The source of the event.</param>
885+
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
886+
private void BtnEditText_Click(object sender, EventArgs e)
887+
{
888+
if (this.textEditorForm == null || this.textEditorForm.IsDisposed)
889+
{
890+
this.textEditorForm = new TextEditorForm(this);
891+
}
892+
893+
// Update font and color before showing
894+
this.textEditorForm.UpdateFontAndColor(this.messageFont, this.messageFontColor);
895+
this.textEditorForm.Show();
896+
this.textEditorForm.BringToFront();
897+
}
898+
864899
#endregion Event handlers
865900
}
866901
}

InfoBox.Designer/TextEditorForm.Designer.cs

Lines changed: 67 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

InfoBox.Designer/TextEditorForm.cs

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

0 commit comments

Comments
 (0)