
这一节给大家演示下怎样使属性值以d出式对话框的形式显示出来 先来看下效果图
这里我们定义一个用户控件 并为用户控件设置一个属性 使用d出式对话框为属性设置值
定义属性ShowPropery
代码如下
public partial class UCLab : UserControl { public UCLab() { InitializeComponent(); } private string showpropery; [Description( d出属性 )] [Editor(typeof(ShowTypeDialogEditor) typeof(UITypeEditor))] public string ShowPropery { get { return showpropery; } set { showpropery = value; } }
}
然后我们为属性设置d出式属性编辑器 需要继承UITypeEditor类 代码如下
/// <summary> /// d出式编辑器 /// </summary> public class ShowTypeDialogEditor : UITypeEditor { public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) { if (context!=null&&context Instance!=null) { return UITypeEditorEditStyle Modal;//显示一个省略号 } return base GetEditStyle(context); } public override object EditValue(ITypeDescriptorContext context IServiceProvider provider object value) { System Windows Forms Design IWindowsFormsEditorService editorService = null; if (context!=null&&context Instance!=null&&provider!=null) { editorService =(System Windows Forms Design IWindowsFormsEditorService)provider GetService(typeof(System Windows Forms Design IWindowsFormsEditorService)); if (editorService!=null) { UCLab uclab =(UCLab)context Instance; ShowForm sf = new ShowForm(uclab ShowPropery); if (sf ShowDialog()==DialogResult OK) { value = sf Result; return value; } } } //return base EditValue(context provider value); return value; } }
这样我们把用户控件拖到界面上 就可以设置属性了
lishixinzhi/Article/program/ASP/201311/21730
你把100个按钮的Click事件都指定成同一个,比如Button_Click
然后再这个事件里的sender就是触发这个事件的按钮,
做个强制类型转换。
(sender as Button)Name
就可以了。。。
把代码贴全点,不是很清楚你要做什么;
看懂了我语文退化阿
public class ToolBarItemConverter: ExpandableObjectConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return false;
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
return false;
}
}
[Category("集合"),Description("菜单项集合"),TypeConverter(typeof(ToolBarItemConverter))]
public ToolBarItem C_Items
{
get;
set;
}
或者 ------------------------------------------------
class ToolBarItemEditor: UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyleModal;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
ToolBarItem item = (value as ToolBarItem);
if (item == null) return value;
FormToolBarItem form = new FormToolBarItem(item); //假定一个用来表示toolbaritem
if(formShowDialog() == DialogResultOK)
return formItem;
return item;
}
}
[Category("集合"),Description("菜单项集合"), [Editor(typeof(ToolBarItemEditor), typeof(UITypeEditor))]
public ToolBarItem C_Items
{
get;
set;
}
^^ 童鞋给钱
你可以在打开之前将 新窗口记录进ArrayList 中
然后再点一个按钮遍历 这个ArrayList 找到你所需要的
按照你举的例子,代码如下:
using SystemCollections;
public partial class Form1 : Form
{
int i;
public Form1()
{
i = 1;
InitializeComponent();
}
ArrayList list = new ArrayList();
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
((TextBox)f2Controls["txt"])Text = iToString();
i++;
f2Show();
listAdd(f2);
}
private void button2_Click(object sender, EventArgs e)
{
foreach (Form f in list)
{
if (((TextBox)fControls["txt"])Text == "2")
{
((TextBox)fControls["txt"])Text = "a";
}
}
}
}
以上就是关于.net WinForm用户控件开发:用户控件d出式属性设置全部的内容,包括:.net WinForm用户控件开发:用户控件d出式属性设置、winform中如何获取鼠标所点击的控件名称、winform用户控件自定义属性问题等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)