ControlCollection.IsReadOnly ControlCollection.IsReadOnly ControlCollection.IsReadOnly ControlCollection.IsReadOnly Property

定義

ControlCollection オブジェクトが読み取り専用かどうかを示す値を取得します。Gets a value indicating whether the ControlCollection object is read-only.

public:
 property bool IsReadOnly { bool get(); };
public bool IsReadOnly { get; }
member this.IsReadOnly : bool
Public ReadOnly Property IsReadOnly As Boolean

プロパティ値

コントロールが読み取り専用の場合は true。それ以外の場合は falsetrue if the control is read-only; otherwise, false. 既定値は、false です。The default is false.

次のコード例では、 ControlCollection Buttonコントロールのコレクションを通じてをmyButton列挙するメソッドを作成します。The following code example creates a method that enumerates through the ControlCollection collection of a Button control, myButton. 列挙子が作成IsSynchronizedされると、プロパティは、操作がスレッドセーフであるかどうかを確認します。そうでない場合はSyncRoot 、プロパティを使用してオブジェクトを取得し、操作スレッドセーフにします。When the enumerator is created, the IsSynchronized property is checked to see if the operation is thread safe, and if it is not, the SyncRoot property is used to obtain an object to make the operation thread safe. 列挙が完了すると、 IsReadOnlyプロパティの値が、含んでいるページのLabelコントロールのTextプロパティとして書き込まれます。When the enumeration is complete, the value of the IsReadOnly property is written as the Text property of a Label control on the containing page.

// Create a method that enuberates through a 
// button//s ControlCollection in a thread-safe manner.  
public void ListControlCollection(object sender, EventArgs e)
{
   IEnumerator myEnumerator = myButton.Controls.GetEnumerator();

   // Check the IsSynchronized property. If False,
   // use the SyncRoot method to get an object that 
   // allows the enumeration of all controls to be 
   // thread safe.
   if (myButton.Controls.IsSynchronized == false)
   {
       lock (myButton.Controls.SyncRoot)
       {
           while (myEnumerator.MoveNext())
           {

               Object myObject = myEnumerator.Current;

               LiteralControl childControl = (LiteralControl)myEnumerator.Current;
               Response.Write("<b><br /> This is the  text of the child Control  </b>: " +
                              childControl.Text);
           }
           msgReadOnly.Text = myButton.Controls.IsReadOnly.ToString();
       }
   }       
}
' Create a method that enuberates through a 
' button's ControlCollection in a thread-safe manner.  
Public Sub ListControlCollection(sender As Object, e As EventArgs)
   Dim myEnumerator As IEnumerator = myButton.Controls.GetEnumerator()

   ' Check the IsSynchronized property. If False,
   ' use the SyncRoot method to get an object that 
   ' allows the enumeration of all controls to be 
   ' thread safe.
   If myButton.Controls.IsSynchronized = False Then
     SyncLock myButton.Controls.SyncRoot
       While (myEnumerator.MoveNext())

       Dim myObject As Object  = myEnumerator.Current
           
         Dim childControl As LiteralControl = CType(myEnumerator.Current, LiteralControl)
         Response.Write("<b><br /> This is the  text of the child Control  </b>: " & _
                        childControl.Text)
       End While
      msgReadOnly.Text = myButton.Controls.IsReadOnly.ToString()
      
      End SyncLock
   End If       
 End Sub

適用対象

こちらもご覧ください