我正在寻找一些关于为什么我的自定义/用户控件不可见的帮助。
我添加控件的代码:
ctlMapIcon mapIcon = new ctlMapIcon();
mapIcon.Name = "name";
mapIcon.LabelText = "dummy map icon";
mapIcon.Parent = picboxRegion1;
mapIcon.Width = 130;
mapIcon.Height = 70;
mapIcon.IconLocation = new Point(100, 100);
this.tabRegion1.Controls.Add(mapIcon);
构建控件的代码: public partial class ctlMapIcon:UserControl { private bool isAlarm;
private Image iconAlarm;
private Image iconOk;
private Image iconInactive;
string lblTextIconName;
public bool SetAlarm
{
set
{
isAlarm = value;
if (isAlarm)
{
picboxIcon.Image = iconAlarm;
}
else
{
picboxIcon.Image = iconOk;
}
}
get
{
return isAlarm;
}
}
public bool SetInactive
{
set
{
if (value)
{
picboxIcon.Image = iconInactive;
}
else
{
picboxIcon.Image = iconOk;
}
}
}
public string LabelText
{
set
{
brdLblIconName.Text = lblTextIconName;
}
get
{
return lblTextIconName;
}
}
public ctlMapIcon()
{
InitializeComponent();
//set all elements of the control to transparent
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.BackColor = Color.Transparent;
picboxIcon.BackColor = Color.Transparent;
brdLblIconName.BackColor = Color.Transparent;
//set icon images
iconAlarm = Properties.Resources.mapicon_inalarm;
iconOk = Properties.Resources.mapicon_ok;
iconInactive = Properties.Resources.mapicon_ok;
//set defaults
picboxIcon.Image = iconOk;
picboxIcon.Width = 40;
picboxIcon.Height = 40;
brdLblIconName.Text = "site";
this.Location = new Point(5, 5);
this.Height = 70;
this.Width = 130;
}
public Point IconLocation
{
get { return this.Location; }
set { this.Location = value; }
}
}
任何帮助都将不胜感激,谢谢。