如何为自定义组件添加一FileName属性,在设计窗口中通过OpenFileDialog得到值,或直接输入得到 如何为自定义组件添加一FileName属性,在设计窗口中通过OpenFileDialog得到值,或直接输入得到就象PictureBox的属性Image一样,通过打开文件得到 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string _mytext; public string MyText { get { return _mytext; } set { _mytext = value; } } 不知道如何做。用File不行,我用窗体继承,File类的属性不可编辑,也不知道为什么. Sample code as follows:[Browsable(true)][Category("Behavior")][DefaultValue(typeof(Image), "None")]public Image MyImage{ get { return m_imgTemp; } set { m_imgTemp = value; this.BackgroundImage = m_imgTemp; }}private Image m_imgTemp; 用FileNameEditor类private string _fileName;[Editor(typeof(FileNameEditor), typeof(System.Drawing.Design.UITypeEditor))]public string FileName{ set { _fileName = value; } get { return _fileName; }} 从System.Drawing.Design.UITypeEditor继承一个新的类就可以了:) 晕死,有现成的FileNameEditor,为什么要从UITypeEditor继承一个新的类。 在父窗体,UserControl或Component中加File类型的属性,在在窗体中继承或调用,在属性编辑框中都不可编辑该属性.不知道这是怎么回事. 回lovvver(www.notsoft.cn),Component的属性一般要求都是要序列化的,即DesignerSerializationVisibility=true [Editor(typeof( System.Windows.Forms.Design.FileNameEditor), typeof(System.Drawing.Design.UITypeEditor))] public string XmlFile { get{return xmlFile;}set{xmlFile=value;} 那也简单啊,写一个继承FileNameEditor的类啊比如,我以前的代码是这样的: [Editor(typeof( XmlFileNameEditor), typeof(System.Drawing.Design.UITypeEditor))] public string XmlFile {get{}set{}}----------------------------- public class XmlFileNameEditor:System.Windows.Forms.Design.FileNameEditor { protected override void InitializeDialog(OpenFileDialog ofd) { ofd.Filter = "Xml 文件 (*.xml)|*.xml|所有文件 (*.*)|*.*"; } } 请问wpf中如何更改webbrowser控件的滚动条样式啊 定时器问题 listview怎么读取execl内容,并写入 谁用过log4net啊? dataGridView使用方法! 请教高手:C/S架构下,如何通知COM PLUS服务程序开始事务? LIB环境变量 简单问题: 如何获得一个DataGrid选中的列(window窗体) “System.Net.Mail.SmtpFailedRecipientsException”类型的未经处理的异常在 System.dll 中发生 多項目問題 动态报表&Reporting Service
public string MyText {
get {
return _mytext;
}
set {
_mytext = value;
}
}
用File不行,我用窗体继承,File类的属性不可编辑,也不知道为什么.
[Browsable(true)]
[Category("Behavior")]
[DefaultValue(typeof(Image), "None")]
public Image MyImage
{
get { return m_imgTemp; }
set
{
m_imgTemp = value;
this.BackgroundImage = m_imgTemp;
}
}
private Image m_imgTemp;
[Editor(typeof(FileNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
public string FileName
{
set
{
_fileName = value;
}
get
{
return _fileName;
}
}
不知道这是怎么回事.
即DesignerSerializationVisibility=true
System.Windows.Forms.Design.FileNameEditor),
typeof(System.Drawing.Design.UITypeEditor))] public string XmlFile
{
get{return xmlFile;}
set{xmlFile=value;}
比如,我以前的代码是这样的:
[Editor(typeof(
XmlFileNameEditor),
typeof(System.Drawing.Design.UITypeEditor))] public string XmlFile
{
get{}
set{}
}
-----------------------------
public class XmlFileNameEditor:System.Windows.Forms.Design.FileNameEditor
{
protected override void InitializeDialog(OpenFileDialog ofd)
{
ofd.Filter = "Xml 文件 (*.xml)|*.xml|所有文件 (*.*)|*.*";
}
}