Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何隐藏我在添加到项目后在创建的项模板中编写的方法和属性?_C#_Winforms - Fatal编程技术网

C# 如何隐藏我在添加到项目后在创建的项模板中编写的方法和属性?

C# 如何隐藏我在添加到项目后在创建的项模板中编写的方法和属性?,c#,winforms,C#,Winforms,我有个问题。我创建了一个自定义用户控件。我的CustomUserControl是从UserControl继承的。我在CustomUserControl中添加了一些自定义方法和属性。我想将CustomUserControl添加到VisualStudio for Project中的“添加新项” 为此,我使用了“项目模板”并创建了一个模板。重新启动VisualStudio后,一切都很好,我可以通过在项目中使用“添加新项”来添加CustomUserControl 只是我在向项目中添加CustomUser

我有个问题。我创建了一个自定义用户控件。我的CustomUserControl是从UserControl继承的。我在CustomUserControl中添加了一些自定义方法和属性。我想将CustomUserControl添加到VisualStudio for Project中的“添加新项”

为此,我使用了“项目模板”并创建了一个模板。重新启动VisualStudio后,一切都很好,我可以通过在项目中使用“添加新项”来添加CustomUserControl

只是我在向项目中添加CustomUserControl时遇到了一个问题,我添加到模板文件中的方法和属性是appeare,我可以更改它们。如何在模板中隐藏方法和属性?我不想在将CustomUserControl添加到项目后看到方法和属性

注意:当我添加我的CustomUserControl项目时,“CustomUserControl1”被创建,它继承自UserControl而不是我的CustomUserControl

我的模板是:

public partial class CustomUserControl : UserControl
{

    private string _Version;

    [Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
    public string Version
    {
        get { return _Version; }
        private set { _Version = value; }
    }

    private void InitRequirements()
    {
        try
        {

            // ... My Code

        }
        catch (Exception exp)
        {

            throw exp;
        }
    }


}
添加到项目后:

应该是这样的:

多谢各位
致以最诚挚的问候,

您可以尝试使用
new
关键字隐藏不想显示的属性

例如,如果要隐藏属性
文本
,可以添加以下内容:

[Bindable(false)]
[Browsable(false)]
public new string Text { get; set; }
编辑


如果要在其他项目中重用控件,而不是“项模板”,则可能需要创建库或程序集并在项目中引用它。这样,您就可以使用它并从中继承,而无需查看代码。当您使用项目模板时,它只会基于保存在模板上的代码创建一个新的
UserControl
,但您不会重用
UserControl
本身。如果您想处理版本控制等,还可以创建一个NuGet包。

您能举个例子说明您想要隐藏什么吗?从你的问题来看,我似乎不太清楚。谢谢你的回答。我在我的问题中添加了一个例子。我创建了CustomUserControl并编写了一些插入它的方法。通过使用导出模板并选择ItemTemplate,我将模板放入VisualStudio模板。当我在项目上使用AddNewItem时,我可以看到并选择CustomUserControl,但当我添加它时,我也可以看到方法和属性,并且可以更改它。感谢您的回答,我编辑了我的问题,并将示例添加到我的问题中,我还需要隐藏MethodsOrry,但您上次的编辑我不清楚,我以为你想在设计器中隐藏属性。不确定您想要做什么以及为什么它不起作用,您应该能够继承CustomUserControl而不显示子类中的方法和属性,这是默认行为以及封装的工作方式。不,这是正常的UserControl。我创建了CustomUserControl并编写了一些插入它的方法。通过使用导出模板并选择ItemTemplate,我将模板放入VisualStudio模板。当我在项目上使用AddNewItem时,我可以看到并选择CustomUserControl,但当我添加它时,我也可以看到方法和属性,我可以更改它。好的,我现在明白了,请看我的编辑,项模板不是您尝试执行的操作的好解决方案。非常感谢,它解决了我的问题。谢谢
public partial class CustomUserControl1 : CustomUserControl
{
    // Without showing methods and properties
}
[Bindable(false)]
[Browsable(false)]
public new string Text { get; set; }