ControlCollection.IsReadOnly Proprietà

Definizione

Ottiene un valore che indica se l'oggetto ControlCollection è di sola lettura.

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

Valore della proprietà

true se il controllo è di sola lettura, altrimenti false. Il valore predefinito è false.

Esempio

Nell'esempio di codice seguente viene creato un metodo che enumera l'insieme ControlCollection di un Button controllo , myButton. Quando viene creato l'enumeratore, la IsSynchronized proprietà viene controllata per verificare se l'operazione è thread-safe e, in caso contrario, la SyncRoot proprietà viene utilizzata per ottenere un oggetto per rendere thread-safe l'operazione. Al termine dell'enumerazione, il valore della IsReadOnly proprietà viene scritto come Text proprietà di un Label controllo nella pagina contenitore.

// 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

Si applica a

Vedi anche