Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions InfoBox.Designer/InfoBox.Designer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TextEditorForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="TextEditorForm.Designer.cs">
<DependentUpon>TextEditorForm.cs</DependentUpon>
</Compile>
<EmbeddedResource Include="InformationBoxDesigner.resx">
<SubType>Designer</SubType>
<DependentUpon>InformationBoxDesigner.cs</DependentUpon>
Expand All @@ -112,6 +118,10 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="TextEditorForm.resx">
<SubType>Designer</SubType>
<DependentUpon>TextEditorForm.cs</DependentUpon>
</EmbeddedResource>
<None Include="app.config" />
<None Include="InfoBox.Designer_TemporaryKey.pfx" />
<None Include="Properties\app.manifest" />
Expand Down
24 changes: 19 additions & 5 deletions InfoBox.Designer/InformationBoxDesigner.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions InfoBox.Designer/InformationBoxDesigner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,25 @@ public partial class InformationBoxDesigner : Form
/// </summary>
private Color messageFontColor = Color.Empty;

/// <summary>
/// Text editor form instance
/// </summary>
private TextEditorForm textEditorForm = null;

#endregion Attributes

#region Properties

/// <summary>
/// Gets the text content control for data binding.
/// </summary>
public TextBox TextContent
{
get { return this.txbText; }
}

#endregion Properties

#region Constructors

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

#endregion Fonts

/// <summary>
/// Handles the Click event of the btnEditText control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private void BtnEditText_Click(object sender, EventArgs e)
{
if (this.textEditorForm == null || this.textEditorForm.IsDisposed)
{
this.textEditorForm = new TextEditorForm(this);
}

// Update font and color before showing
this.textEditorForm.UpdateFontAndColor(this.messageFont, this.messageFontColor);
this.textEditorForm.Show();
this.textEditorForm.BringToFront();
}

#endregion Event handlers
}
}
67 changes: 67 additions & 0 deletions InfoBox.Designer/TextEditorForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 96 additions & 0 deletions InfoBox.Designer/TextEditorForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
}
}
}
}
Loading
Loading