English 中文(简体)
NET 海关控制(ToolStripControlHost) Wreaks Havoc on the Designer
原标题:.NET Custom Control (ToolStripControlHost) Wreaks Havoc on the Designer

我需要把马斯克德泰瑟比奥列入一个工具包,该工具包是因违约而被列入的,因此,我遵循我在网上发现的一些建议,建立了从工具StripControlHost继承下来的习俗控制。 当我管理申请时,我所创造的功劳是巨大的,但是它确实对设计者进行了评估。 通过“评估”,我指的是从工具包中消失的习惯控制(加上其他一些控制)。 此外,我再也不能对《工具包》增加新的控制,我可以选择对《工具包》的现有控制,以对其进行编辑。

这里是我的班子。

[DesignerCategory("code")]
[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.StatusStrip)]
public partial class ToolStripMaskedTextBox : ToolStripControlHost
{
    public MaskedTextBox MaskedTextBox
    {
        get { return Control as MaskedTextBox; }
    }

    public ToolStripMaskedTextBox()
        : base(CreateControlInstance()) { }

    private static Control CreateControlInstance()
    {
        MaskedTextBox mtb = new MaskedTextBox();
        mtb.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
        mtb.MinimumSize = new System.Drawing.Size(100, 16);
        mtb.PasswordChar =  * ;
        return mtb;
    }
}

如果在给设计人一个艰难时期时,我可能会做错事,那么任何帮助都会受到赞赏。

现在,在我向视觉演播室开放我的班子档案时,我收到了一个带有以下错误的警告页:

Constructor on type  System.Windows.Forms.ToolStripControlHost  not found. 

<>http://www.ohchr.org>

问题只是在找到解决办法之后才会发生。 我可以让设计者正确工作,修改表格。 和增加单一空间一样。 从那里,设计商将进行罚款。 直到我找到解决办法。 然后设计员再次冻结。 对表格的管制不得加以编辑。

问题回答

根据例外情况

Constructor on type  System.Windows.Forms.ToolStripControlHost  not found. 

我发现了一些关于MSDN论坛的信息。

This happends because the ToolStripControlHost class does not have a constructor with no parameter.

To solve this problem, you can create your own ToolStripControlHost with a none-parameter constructor and make the ToolStripMaskedTextBox inherited from your ToolStripControlHost. Try something like the following

//Declare a class that inherits from ToolStripControlHost.
[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.StatusStrip)]
public class ToolStripMaskedTextBox : MyCustomToolStripControlHost
{
    // Call the base constructor passing in a MaskedTextBox instance.
    public ToolStripMaskedTextBox() : base(CreateControlInstance()) { }

    public MaskedTextBox MaskedTextBox
    {
        get
        {
            return Control as MaskedTextBox;
        }
    }


    private static Control CreateControlInstance()
    {
        MaskedTextBox mtb = new MaskedTextBox();
        mtb.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
        mtb.MinimumSize = new System.Drawing.Size(100, 16);
        mtb.PasswordChar =  * ;
        return mtb;
    }
}

public class MyCustomToolStripControlHost : ToolStripControlHost
{
    public MyCustomToolStripControlHost()
        : base(new Control())
    {
    }
    public MyCustomToolStripControlHost(Control c)
        : base(c)
    {
    }
}

This will fix the problem with your exception.

表格设计师(ToolStrip MaskedTextBox)的问题在接手之后并不明显,但你可以关闭设计师,再次打开档案。

Then you can go on without any problems.

www.un.org/Depts/DGACM/index_spanish.htm 希望这一帮助

I ve used dknaack s solution, but placed MyCustomToolStripControlHost class in a separate file in System.Windows.Forms namespace. And...

First: it works - no exception. Then: my control is visible in designer as well, so it s a jackpot.

FWIW:我还成功地找到了上面的 d子解决办法,但只有在我意识到,我是在错误的地方寻找习惯工具Strip Control。 海关控制在工具箱本身中显示。 相反,它显示了在选择(设计人)时在工具包上出现的“补充工具StripButton”下各组成部分的下调清单。

I found a solution of designer s problem. https://dobon.net/vb/dotnet/control/tschdesigneravail.html#tips_comment (Japanese)

你们所需要的只是从工具包中挑选出一个类别,代之以。

class DesignerFriendlyToolStrip : ToolStrip { }

var ts = new DesignerFriendlyToolStrip();
ts.Items.Add(toolStripMaskedTextBox);
form.Controls.Add(ts);

我不知道为什么这样做是有效的。 任何人都知道......?





相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签