I have created a C# User Control in Visual Studio 2019. It has a property called "BoundLayout".
public Layout BoundLayout
{
get
{
return _Layout;
}
set
{
_Layout = value as Layout;
if (_Layout == null)
{
MessageBox.Show("Value submitted is not of type 'LAYOUT'","Invalid Value",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
else
{
InitializeControl();
}
}
}
If a program attempts to assign an incompatible value to the property an error message is displayed in a MessageBox. This works correctly.
What is very strange is that when ever I BUILD (not RUN) the project this error message is displayed in its modal MessageBox which must be acknowledged before you can return to Visual Studio. This occurs when building in both Debug and Release modes. A break point added to the property set code does not get triggered. The build completes successfully without errors or warnings and I can run the application.
The application, including this User Control operates as intended. I have never encountered this behavior before. Has anyone else?
The complete (still in development) code for the User Control:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Dispatcher
{
public partial class DivisionModuleGrid : UserControl
{
private Layout _Layout = null;
private ObservableListSource<LayoutDivision> _LayoutDivisions;
private DivisionModulesList _activeDivision = null;
private int _divisionCount;
public Layout BoundLayout
{
get
{
return _Layout;
}
set
{
_Layout = value as Layout;
if (_Layout == null)
{
MessageBox.Show("Value submitted is not of type 'LAYOUT'","Invalid Value",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
else
{
InitializeControl();
}
}
}
public DivisionModulesList ActiveDivision
{
get
{
return _activeDivision;
}
set
{
_activeDivision = value as DivisionModulesList;
if (_activeDivision != null)
{
lbl_ActiveDivision.Text = _activeDivision.DivisionName;
}
else
{
lbl_ActiveDivision.Text = "-No Active Division-";
}
}
}
public DivisionModuleGrid()
{
InitializeComponent();
}
private void InitializeControl()
{
_LayoutDivisions = _Layout.LayoutDivisions;
_divisionCount = _LayoutDivisions.Count;
tbx_LayoutName.Text = _Layout.LayoutName;
// Grid Layout divide into Rows & Columns
int tlp_rows = _divisionCount / 3;
TableLayoutPanel tlp = (TableLayoutPanel)(Controls.Find("tlp_DivisionGrid", false)[0]);
DivisionModulesList dml;
foreach (LayoutDivision ld in _LayoutDivisions)
{
dml = new DivisionModulesList(ld);
dml.BoundDivision = ld;
tlp.Controls.Add(dml);
}
}
private void Tlp_DivisionGrid_Paint(object sender, PaintEventArgs e)
{
}
}
}