防止设计人员调用吸气剂(VS 2008,WinForms) [英] prevent the designer from calling a getter (VS 2008, WinForms)

查看:67
本文介绍了防止设计人员调用吸气剂(VS 2008,WinForms)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的UserControl,其中包含一个ComboBox,该ComboBox最初为空.该CB的设置器向其添加项目,而getter返回选定的项目.当将此UC添加到Form中时,设计器会自动为空的CB调用getter.稍后将使用项目填充CB的方法.我可以想到一种或两种方式通过在代码中四处打乱"来绕过此问题.但是在我开始之前,我想问你是否有一种方法可以阻止设计人员调用getter方法.也许具有类似于可浏览"或可绑定"的属性?

I have a simple UserControl containing a ComboBox which is empty at first. The setter for that CB adds items to it and the getter returns the selected item. When adding this UC to a Form, the designer automatically calls the getter for the CB which is empty. The method to fill up the CB with items is called later. I can think of one or two ways to bypass this problem by "messing around" in the code. But before I start that I'd like to ask you if there is a way to stop the designer from calling the getter method. Maybe with a attribute similar to Browsable or Bindable? thx

推荐答案

对我来说,这种吸气剂的外观还不清楚.但是,您要确保设计器不会序列化只能在运行时使用的属性.使用属性执行此操作:

It is not that clear to me what this getter might look like. However, you want to make sure that the designer doesn't serialize properties that should only ever be used at runtime. Do this with an attribute:

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    [Browsable(false)]
    public int SomeProperty { 
        //etc... 
    }

这篇关于防止设计人员调用吸气剂(VS 2008,WinForms)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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