请添加以下两个方法:public bool ShouldSerializeTagSource
{
return (s_tag != 一个默认值);// 由对象实例化时的缺省值
// 直接返回 true 也可。
}public void ResetTagSource()
{
s_tag = 默认值;
// Tag_Source = 默认值; // 如果需要引发属性值改变事件或其他处理
}
{
return (s_tag != 一个默认值);// 由对象实例化时的缺省值
// 直接返回 true 也可。
}public void ResetTagSource()
{
s_tag = 默认值;
// Tag_Source = 默认值; // 如果需要引发属性值改变事件或其他处理
}
解决方案 »
- DirectX获取声卡数据无法正常播放问题
- 看看这道题
- 请个位帮我看看这个程序,调试的时候可而已得到结果,但是运行时不知道那里出错了!
- c#中几个不明白!大家快来解答!
- 窗口最大化的问题,急!在线等!
- 关于C#操作excel活见鬼的问题.(注:本人已搜过msdn并学习过相关问答)
- C# winform窗体,form1为软键盘,form2上有textbox,那么如何使用软键盘在form2的textbox内输入数据
- Enumerable.GroupBy ()的问题
- WinForm非常送分的问题!马上给!
- 请回答这个不难的问题,再加100分!!!!(总共200分了)
- 如何拼接GRIDVIEW某列单元格字符串作为SQL查询条件?
- 怎样打印预览自己生成的HTML
http://www.syncfusion.com/FAQ/WinForms/FAQ_c81c.asp#q713q
现在有所进展,但是问题还存在。属性能暂时保存了,但是退出.Net环境或者一运行又丢失了。我把现在的代码贴出来,大虾再看看,问题出在哪?谢谢!
================================
public class TagEditor : System.Drawing.Design.UITypeEditor
{
private object value;
private TagControl Tc;
public TagEditor()
{
} // Indicates whether the UITypeEditor provides a form-based (modal) dialog,
// drop down dialog, or no UI outside of the properties window.
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown ;
} // Displays the UI for value selection.
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if( edSvc != null )
{
// Display an angle selection control and retrieve the value.
if(this.Tc==null)
{
if(value==null)
{
TagProperty p=new TagProperty();
value=p;
}
Tc=new TagControl((TagProperty)value,edSvc);
}
edSvc.DropDownControl(Tc);
return (TagProperty)Tc.tag ;
}
return (TagProperty)Tc.tag ;
}
}
}
================================================
[TypeConverter(typeof(TagConvert))]
public class TagProperty : System.ComponentModel.Component
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private string tagname;
private double d_hi,d_low,d_max,d_min;
public TagProperty(System.ComponentModel.IContainer container)
{
///
/// Windows.Forms 类撰写设计器支持所必需的
///
container.Add(this);
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} public TagProperty()
{
///
/// Windows.Forms 类撰写设计器支持所必需的
///
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
public string TagName
{
get
{
return tagname;
}
set
{
tagname=value;
}
} public double HiValue
{
get
{
return d_hi;
}
set
{
d_hi=value;
}
}
public double LowValue
{
get
{
return d_low;
}
set
{
d_low=value;
}
}
public double MaxValue
{
get
{
return d_max;
}
set
{
d_max=value;
}
}
public double MinValue
{
get
{
return d_min;
}
set
{
d_min=value;
}
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
======================================================
public class TagConvert:ExpandableObjectConverter
{
public override bool GetCreateInstanceSupported(ITypeDescriptorContext context)
{
return true;
}
public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues)
{
TagProperty TagP = new TagProperty();
TagP.TagName= (string)propertyValues[(object)"TagName"];
TagP.HiValue = (double)propertyValues[(object)"HiValue"];
TagP.LowValue = (double)propertyValues[(object)"LowValue"];
TagP.MaxValue = (double)propertyValues[(object)"MaxValue"];
TagP.MinValue = (double)propertyValues[(object)"MinValue"];
return (object)TagP;
} public override bool GetPropertiesSupported(ITypeDescriptorContext context)
{
return true;
}
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
{
System.ComponentModel.PropertyDescriptorCollection propertyDescriptorCollection;
string[] propNames;
propertyDescriptorCollection =
TypeDescriptor.GetProperties(typeof(TagProperty),attributes);
propNames = (string[])new System.String[5];
propNames[0] = @"TagName";
propNames[1] = @"HiValue";
propNames[2] = @"LowValue"; propNames[3] = @"MaxValue"; propNames[4] = @"MinValue";
return propertyDescriptorCollection.Sort(propNames);
} // end of method GetProperties }
=====================================
{ [BrowsableAttribute(true)]
[EditorAttribute(typeof(TagEditor), typeof(System.Drawing.Design.UITypeEditor))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public TagProperty TagSource
{
get
{
return s_tag;
}
set
{
s_tag=value;
}
} public DataLink()
{
// 该调用是 Windows.Forms 窗体设计器所必需的。
InitializeComponent();
this.SetStyle(ControlStyles.UserPaint,true);
components = new System.ComponentModel.Container(); //SetStyle(ControlStyles.SupportsTransparentBackColor, true);
//this.BackColor = Color.Transparent;
s_tag=new TagProperty() ;
}
private void DataLink_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button==MouseButtons.Right )
{
Point p=new Point(e.X,e.Y);
LinkMenu.Show(this,p);
}
} private void menuItem1_Click(object sender, System.EventArgs e)
{
if(this.TagSource !=null)
{
FrmDataSource f1=new FrmDataSource(this.TagSource);
f1.Show();
}
} }
internal class TagControl : System.Windows.Forms.UserControl
{
private TagProperty tag;
public TagControl(TagProperty initial_tag,IWindowsFormsEditorService edSvc)
{
this.tag =initial_tag;
this.edSvc = edSvc;
InitializeComponent();
this.textBox1.Text=this.tag.TagName ;
this.textBox2.Text=System.Convert.ToString(tag.MaxValue);
this.textBox3.Text=System.Convert.ToString(tag.MinValue);
this.textBox4.Text=System.Convert.ToString(tag.HiValue);
this.textBox5.Text=System.Convert.ToString(tag.LowValue);
} public void GetTag()
{
if(tag==null)
{
tag=new TagProperty();
}
this.tag.TagName =this.textBox1.Text.ToString() ;
this.tag.HiValue =System.Convert.ToDouble(this.textBox4.Text) ;
this.tag.LowValue =System.Convert.ToDouble(this.textBox5.Text);
this.tag.MaxValue =System.Convert.ToDouble(this.textBox2.Text);
this.tag.MinValue =System.Convert.ToDouble(this.textBox3.Text); }
private void button1_Click(object sender, EventArgs e)
{
GetTag();
if(edSvc!=null)
{
edSvc.CloseDropDown() ;
}
} }===================
这部分省略了一些定义