交互式设计时用户控制

发布于 2024-08-21 17:41:41 字数 354 浏览 1 评论 0原文

如果标题令人困惑,我深表歉意,我花了近 5 分钟才最终想到这个标题...

好吧,您知道如何在 Visual Studio Express 中将 TabControl 添加到表单中,然后您可以单击 TabControl 右上角的右箭头,它会添加一个新的 TabPage,还是删除一个?

好吧,我正在创建一个用户控件,我需要人们能够在面板之间切换(我的用户控件由多个面板组成)。我知道这是可能的,因为我过去使用过功能区Control,并且您可以在设计器视图中添加新按钮等。

有人可以就我如何实现这一目标提供任何建议/建议吗?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不一样的天空 2024-08-28 17:41:41

如果我正确理解你的问题,你正在谈论智能标签

该过程有点复杂,因此我不会尝试发布完整的示例。相反,我会建议您参阅有关该主题的本教程。长话短说,您必须创建一个自定义设计器,并注册一个或多个自定义操作。您可以使用它创建一个列出可用面板的组合框,并在所选项目更改时在它们之间切换。

(注意 - 术语“智能标记”在 Visual Studio 中具有两种不同的含义 - 我具体讨论的是可视化设计器智能标记,而不是代码编辑器中的智能标记)。

If I understand your question correctly, you're talking about smart tags.

The process is a little bit involved, so I'm not going to try to post a complete sample. Instead, I'll refer you to this tutorial on the subject. To make a long story short, you have to create a custom designer, and register one or more custom actions. You can use this to create a combo box listing the available panels and switch between them when the selected item is changed.

(Note - the term "smart tags" has two distinct meanings in Visual Studio - I'm specifically talking about the visual designer smart tags, not smart tags in the code editor).

梦纸 2024-08-28 17:41:41

当您创建一个从 Control 继承的控件时,您必须使用几个属性,例如 IsDesignMode,然后您可以构造事件处理程序,特别是在设计模式中:

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

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

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...
   }
}

另一个我能想到的是'ShouldSerialize' 后跟可公开访问的属性,以便将该属性保留到设计器生成的代码中,例如假设 Control 有一个布尔值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...
}

如果 ShouldSerializeFoo 返回 false,则没有属性被持久化,当 true 时相反,它将被隐藏在 Form.Designer.cs 代码中...

希望这有帮助,
此致,
汤姆.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文