交互设计时用户控制 [英] Interactive Design-Time User Control

查看:210
本文介绍了交互设计时用户控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果标题很混乱,我们深表歉意,我花了将近5分钟才终于想到这个标题的标题...



好的,你知道如何当您向表单添加 TabControl 时,Visual Studio Express,您可以单击 TabControl ,它会添加一个新的 TabPage 或删除一个?



一个用户控制,我需要人们能够在面板之间切换(我的用户控制是由几个面板组成)。我知道这是可能的,因为我在过去使用过一个功能区 Control ,您可以在Designer视图中添加新的按钮等。



有人可以提供任何建议/建议,了解我如何去实现这个目标?



谢谢

Control
的控件时,你必须使用几个属性,例如: IsDesignMode ,那么您可以构造事件处理程序,特别是在设计模式中:

 
if(IsDesignMode){
//在设计模式下处理交互性,例如更改
// Properties工具箱上的属性
}

假设控件有一个事件,例如 MouseClick ,你可以这样做:

 
private void control_MouseClick(object sender,MouseEventArgs e){
if(IsDesignMode){
//根据Designer中的Click事件b} else {
//这是在运行时...
}
}

另一个我可以想到的是 ShouldSerialize '之后是一个可公开访问的属性,以便将属性持久化到设计器生成的代码,假设例如一个Control有一个布尔属性 Foo

 
public bool Foo {
get {return this._foo; }
set {if(this._foo!= value){
this._foo = value;
}
}
}

public bool ShouldSerializeFoo(){
return true; //该属性将保留在设计器生成的代码中
//检入Form.Designer.cs ...
}

如果 ShouldSerializeFoo 返回false,则不会保留任何属性,如果为true,则会隐藏在Form.Designer.cs代码中...



希望有帮助,
最好的问候,
汤姆。


I apologise if the title was confusing, it took me nearly 5 minutes to finally think of a title for this one...

Okay, you know how in Visual Studio Express when you add a TabControl to the Form, and you can click on the right-arrow on the top right of the TabControl and it will add a new TabPage, or remove one?

Well, I'm creating a User Control where I need people to be able to switch between Panels (my user control is made up of several Panels). I know this is possible as I've used a Ribbon Control in the past and you could add new buttons etc in the Designer View.

Can somebody please provide any suggestions/advice on how I might go about acheiving this?

Thank you

解决方案

When you make a control that is inherited from Control, you have to make use of a couple of properties such as IsDesignMode, you can then construct event handlers especially for within Design Mode:

if (IsDesignMode){
   // Handle the interactivity in Design mode, such as changing a property on the
   // Properties toolbox
}

Suppose the control has an event such as MouseClick, you can do this:

private void control_MouseClick(object sender, MouseEventArgs e){
   if (IsDesignMode){
       // Do something here depending on the Click event within the Designer
   }else{
       // This is at run-time...
   }
}

Another I can think of is 'ShouldSerialize' followed by a publicly accessible property in order to persist the property to the designer-generated code, suppose for example a Control has a boolean property Foo

public bool Foo{
    get{ return this._foo; }
    set{ if (this._foo != value){ 
                this._foo = value; 
         }
       }
}

public bool ShouldSerializeFoo(){
    return true; // The property will be persisted in the designer-generated code
                 // Check in Form.Designer.cs...
}

If ShouldSerializeFoo returned false, no property is persisted, its the opposite when true, it will be buried within the Form.Designer.cs code...

Hope this helps, Best regards, Tom.

这篇关于交互设计时用户控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆