using DrawGraph; using System; using System.Reflection; using System.Windows.Forms; namespace DrawGraphManagement.MyUserControl { public class UCAttrib : UCBase { //PackObjBase selectPoB = null; public UCAttrib(PackObjBase pob) { selectPoB = pob; } public override Panel GreatPropertyPanel(PropertyInfo info) { if (selectPoB == null) return null; System.Windows.Forms.Panel panel; System.Windows.Forms.TextBox textBox; System.Windows.Forms.Label label; label = new System.Windows.Forms.Label(); textBox = new System.Windows.Forms.TextBox(); object[] bookarr = info.GetCustomAttributes(typeof(ClassAttributs), false); textBox.Leave -= new EventHandler(txt_Leave); // // label1 // label.AutoSize = true; label.Dock = System.Windows.Forms.DockStyle.Left; label.Location = new System.Drawing.Point(0, 0); string cName = info.Name; if (bookarr.Length > 0) { ClassAttributs bookattribute1 = (ClassAttributs)bookarr[0]; if (bookattribute1.CName != null) { cName = bookattribute1.CName; } if (bookattribute1.Description != null) { toolTip1.SetToolTip(label, bookattribute1.Description.ToString()); } } label.Name = "label" + selectPoB.PackTag; label.Size = new System.Drawing.Size(41, 12); label.TabIndex = 0; label.Text = cName; // // textBox1 // textBox.Dock = System.Windows.Forms.DockStyle.Left; textBox.Location = new System.Drawing.Point(41, 0); textBox.Name = "textBox" + info.Name; textBox.Size = new System.Drawing.Size(156, 21); textBox.Tag = info.Name; textBox.MaxLength = 32767; textBox.TabIndex = 1; textBox.Text = info.GetValue(selectPoB, null).ToString(); textBox.Leave += new EventHandler(txt_Leave); if (bookarr.Length > 0) { ClassAttributs bookattribute1 = (ClassAttributs)bookarr[0];//获取属性类的第一个成员 if (bookattribute1.Message == "readOnly") { textBox.ReadOnly = true; } } // // panel5 // panel = new System.Windows.Forms.Panel(); panel.Dock = DockStyle.Top; panel.Controls.Add(textBox); 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; } public void Clear() { selectPoB = null; } void txt_Leave(object sender, EventArgs e) { if (selectPoB == null) return; //先清除,因为Tag修改后会有重复 selectPoB.Clear(); TextBox txtser = (sender as TextBox); try { foreach (PropertyInfo p in selectPoB.GetType().GetProperties()) { if (txtser.Tag.ToString() == p.Name) { MovePackObjCommand cmd = new MovePackObjCommand(CommandManage.GetInstance.AreaManage, selectPoB); cmd.PreExecute(); //先拿到改变前的值 float width = selectPoB.Width; float height = selectPoB.Height; p.SetValue(selectPoB, Convert.ChangeType(txtser.Text.TrimEnd(), p.PropertyType), null); if (p.Name.ToLower() == "x") { selectPoB.EndX = selectPoB.X + width; } if (p.Name.ToLower() == "y") { selectPoB.EndY = selectPoB.Y + height; } cmd.LastExecute(); CommandManage.GetInstance.AddCommand(cmd); break; } } } catch (Exception ) { } finally { if (selectPoB != null) { selectPoB.Draw(); onChangeValue(selectPoB, e); } } } } }