ControlCollection.IsReadOnly Propiedad

Definición

Obtiene un valor que indica si el objeto ControlCollection es de solo lectura.

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

Valor de propiedad

Es true si el control es de solo lectura; en caso contrario, es false. De manera predeterminada, es false.

Ejemplos

En el ejemplo de código siguiente se crea un método que enumera a través de la ControlCollection colección de un Button control , myButton. Cuando se crea el enumerador, la IsSynchronized propiedad se comprueba para ver si la operación es segura para subprocesos y, si no es así, la SyncRoot propiedad se usa para obtener un objeto para que el subproceso de la operación sea seguro. Una vez completada la enumeración, el valor de la IsReadOnly propiedad se escribe como la Text propiedad de un Label control en la página contenedora.

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

Se aplica a

Consulte también