2022-08-23 21:12:59 +08:00

102 lines
3.4 KiB
C#

using DrawGraph;
using System;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
namespace DrawGraphManagement.MyUserControl
{
public class UCColor : UCBase
{
public UCColor(PackObjBase pob)
{
selectPoB = pob;
}
public override Panel GreatPropertyPanel(PropertyInfo info)
{
if (selectPoB == null) return null;
System.Windows.Forms.Panel panel;
System.Windows.Forms.Label label;
System.Windows.Forms.Label labelColor;
panel = new System.Windows.Forms.Panel();
label = new System.Windows.Forms.Label();
labelColor = new System.Windows.Forms.Label();
labelColor.AutoSize = true;
labelColor.Dock = System.Windows.Forms.DockStyle.Left;
labelColor.Name = "label" + selectPoB.PackTag;
labelColor.Size = new System.Drawing.Size(41, 12);
labelColor.TabIndex = 0;
labelColor.Text = " ";
labelColor.BackColor = (Color)info.GetValue(selectPoB, null);
labelColor.Tag = info.Name;
labelColor.Click += new EventHandler(labColor_Click);
label.AutoSize = true;
label.Dock = System.Windows.Forms.DockStyle.Left;
label.Name = "label" + selectPoB.PackTag;
label.Size = new System.Drawing.Size(41, 12);
label.TabIndex = 0;
label.Text = info.Name;
object[] bookarr = info.GetCustomAttributes(typeof(ClassAttributs), false);
if (bookarr.Length > 0)
{
ClassAttributs bookattribute1 = (ClassAttributs)bookarr[0];//获取属性类的第一个成员
if (bookattribute1.Description != null)
{
base.toolTip1.SetToolTip(label, bookattribute1.Description.ToString());
}
}
panel = new System.Windows.Forms.Panel();
panel.Dock = DockStyle.Top;
panel.Controls.Add(labelColor);
panel.Controls.Add(label);
panel.Location = new System.Drawing.Point(3, 6);
panel.Name = "panel" + selectPoB.PackTag; ;
panel.Size = new System.Drawing.Size(200, 27);
panel.TabIndex = 0;
return panel;
}
void labColor_Click(object sender, EventArgs e)
{
if (selectPoB == null) return;
System.Windows.Forms.Label lab = (sender as System.Windows.Forms.Label);
try
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
foreach (PropertyInfo p in selectPoB.GetType().GetProperties())
{
if (lab.Tag.ToString() == p.Name)
{
lab.BackColor = colorDialog1.Color;
p.SetValue(selectPoB, Convert.ChangeType(colorDialog1.Color, p.PropertyType), null);
break;
}
}
}
}
catch (Exception)
{
}
finally
{
if (selectPoB != null)
{
selectPoB.Draw();
onChangeValue(selectPoB, e);
}
}
}
}
}