英語で読む

次の方法で共有


ContainerControl.ActiveControl プロパティ

定義

コンテナー コントロール上のアクティブ コントロールを取得または設定します。

C#
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Control ActiveControl { get; set; }
C#
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Control? ActiveControl { get; set; }

プロパティ値

Control で現在アクティブな ContainerControl

実装

属性

例外

割り当てられた Control をアクティブにできませんでした。

次のコード例では、 ScrollableControl クラスを継承し、 インターフェイスを IContainerControl 実装します。 実装が プロパティと メソッドにActiveControlActivateControl追加されます。

C#
using System;
using System.Windows.Forms;
using System.Drawing;

    public class MyContainer : ScrollableControl, IContainerControl
    {
        private Control activeControl;
        public MyContainer() 
        {
            // Make the container control Blue so it can be distinguished on the form.
            this.BackColor = Color.Blue;
            
            // Make the container scrollable.
            this.AutoScroll = true;
        }

        // Add implementation to the IContainerControl.ActiveControl property.
        public Control ActiveControl
        {
            get
            {
                return activeControl;
            }

            set
            {
                // Make sure the control is a member of the ControlCollection.
                if(this.Controls.Contains(value))
                {
                    activeControl = value;
                }
            }
        }

        // Add implementations to the IContainerControl.ActivateControl(Control) method.
        public bool ActivateControl(Control active)
        {
            if(this.Controls.Contains(active))
            {
                // Select the control and scroll the control into view if needed.
                active.Select();
                this.ScrollControlIntoView(active);
                this.activeControl = active;
                return true;
            }
            return false;
        }
    }

注釈

プロパティは ActiveControl 、コンテナー コントロールのアクティブなコントロールをアクティブ化または取得します。

このプロパティから有効な値を受け取るには、このプロパティを呼び出すオブジェクトに、呼び出しているコントロールが含まれているか、またはコントロールに含まれている必要があります。 あるフォームが別のフォームのプロパティを呼び出そうとすると、未定義の ActiveControl 値を受け取ります。 この場合、このデータを渡すには、フォーム間で独自の通信メカニズムを定義する必要があります。

適用対象

製品 バージョン
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

こちらもご覧ください