在复合控件里增加自定义事件啊 如: public event EventHandler SelectedColorChanged; protected override void OnMouseDown(MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (this.m_SelectedIndex >= 0) { this.m_ColorCombs[this.m_SelectedIndex].Selected = false; base.Invalidate(this.m_ColorCombs[this.m_SelectedIndex].Bounds); } this.m_SelectedIndex = -1; if (this.m_MouseOverIndex >= 0) { this.m_SelectedIndex = this.m_MouseOverIndex; this.m_ColorCombs[this.m_SelectedIndex].Selected = true; if (this.SelectedColorChanged != null) { this.SelectedColorChanged(this, new EventArgs()); } base.Invalidate(this.m_ColorCombs[this.m_SelectedIndex].Bounds); } } base.OnMouseDown(e); }
[Browsable(true)] public event EventHandler CnjTicketCountChanged;将此控件拖入到form中即可在工具栏中看到改事件
设计时自定义控件,你先要定义一个类,继承ControlDesigner,然后在你自定义控件上加上 [Designer(typeof(你定义的那个类))]给你一个例子吧: [Designer(typeof(ButtonDesigner))] [ToolboxItem(true),ToolboxBitmap(typeof(Boffin.Windows.Controls.Button),"button.ico")] public class Button :System.Windows.Forms.Button { //这个是自定义按钮类 }//这是设计时,点右键出来的菜单 internal class ButtonDesigner : ControlDesigner { ButtonDesigner() { } private DesignerVerbCollection m_Verbs; public override DesignerVerbCollection Verbs { get { if (m_Verbs == null) { // Create and initialize the collection of verbs m_Verbs = new DesignerVerbCollection(); m_Verbs.Add( new DesignerVerb("带图标(&W)",new EventHandler(OnWithImage)) );
自定义的事件并没有和windows消息关联,
要关联就得重写WndProc函数,在里面处理消息;
如:
public event EventHandler SelectedColorChanged; protected override void OnMouseDown(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (this.m_SelectedIndex >= 0)
{
this.m_ColorCombs[this.m_SelectedIndex].Selected = false;
base.Invalidate(this.m_ColorCombs[this.m_SelectedIndex].Bounds);
}
this.m_SelectedIndex = -1;
if (this.m_MouseOverIndex >= 0)
{
this.m_SelectedIndex = this.m_MouseOverIndex;
this.m_ColorCombs[this.m_SelectedIndex].Selected = true;
if (this.SelectedColorChanged != null)
{
this.SelectedColorChanged(this, new EventArgs());
} base.Invalidate(this.m_ColorCombs[this.m_SelectedIndex].Bounds);
}
}
base.OnMouseDown(e);
}
public event EventHandler CnjTicketCountChanged;将此控件拖入到form中即可在工具栏中看到改事件
[Designer(typeof(你定义的那个类))]给你一个例子吧:
[Designer(typeof(ButtonDesigner))]
[ToolboxItem(true),ToolboxBitmap(typeof(Boffin.Windows.Controls.Button),"button.ico")]
public class Button
:System.Windows.Forms.Button
{
//这个是自定义按钮类
}//这是设计时,点右键出来的菜单
internal class ButtonDesigner : ControlDesigner
{
ButtonDesigner()
{
} private DesignerVerbCollection m_Verbs; public override DesignerVerbCollection Verbs
{
get
{
if (m_Verbs == null)
{
// Create and initialize the collection of verbs
m_Verbs = new DesignerVerbCollection();
m_Verbs.Add( new DesignerVerb("带图标(&W)",new EventHandler(OnWithImage)) );
m_Verbs[0].Checked=((Button)this.Control).WithImage;
}
return m_Verbs;
}
} private void OnWithImage(object sender,EventArgs e)
{
if(this.Control==null || m_Verbs==null || m_Verbs.Count==0)
return; ((Button)this.Control).WithImage=m_Verbs[0].Checked=!m_Verbs[0].Checked;
}}
配置文件更没有问题了,看你是读取你特定的配置文件还是程序默认的配置了....
反正都可以
[align=center]***********************************************************
欢迎使用 CSDN 小秘书
.Net 学习QQ群,欢迎加入: 67784580
***********************************************************
[/align]