1

Windows フォーム用の UserControl があります。どうすればそれをコンポーネントに変換できますか? 私がやりたいのは、VSツールボックスに追加し、デザインタイムにドラッグアンドドロップでフォームに追加し、プロパティウィンドウを使用して場所とドックのプロパティを変更することです。これを行うには何を探す必要がありますか?

以前に似たようなものを作成したことがありますが、それは Component クラスでした。VS ツールボックスに追加し、ドラッグ アンド ドロップでフォームに追加し、[プロパティ] ウィンドウを使用してカスタム プロパティを変更できますが、これはコンポーネントであるため、下部のコンポーネント領域に表示され、デザイン時のサポートはありません。

4

1 に答える 1

1

AUserControl ですComponent。そうするために余分なことをする必要はありません。

VS 内で新規作成するUserControlと、目的の動作が自動的に行われます。ツールボックスからフォームにドラッグし、[プロパティ] パネルでプロパティを変更します。

このコードは、ツールボックスに表示される機能するコントロールを作成し、そのプロパティを変更できるようにします。

public class TestUserControl : UserControl
{
    public TestUserControl() {
        InitializeComponent();
    }
    /// <summary> 
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary> 
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing) {
        if (disposing && (components != null)) {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Component Designer generated code

    /// <summary> 
    /// Required method for Designer support - do not modify 
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent() {
        this.label1 = new System.Windows.Forms.Label();
        this.SuspendLayout();
        // 
        // label1
        // 
        this.label1.AutoEllipsis = true;
        this.label1.Dock = System.Windows.Forms.DockStyle.Fill;
        this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.label1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
        this.label1.Location = new System.Drawing.Point(0, 0);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(231, 51);
        this.label1.TabIndex = 0;
        this.label1.Text = "This is a test user control";
        this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
        // 
        // TestUserControl
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.BackColor = System.Drawing.SystemColors.ActiveCaption;
        this.Controls.Add(this.label1);
        this.Name = "TestUserControl";
        this.Size = new System.Drawing.Size(231, 51);
        this.ResumeLayout(false);

    }

    #endregion

    private System.Windows.Forms.Label label1;
}

おそらく、このクラスに機能を追加して、それが機能するかどうかを確認できます。

于 2009-09-20T12:12:03.347 に答える