SolidBrush Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Definisce un pennello di un singolo colore. I pennelli vengono usati per riempire forme grafiche, ad esempio rettangoli, ellissi, pie, poligoni e percorsi. La classe non può essere ereditata.
public ref class SolidBrush sealed : System::Drawing::Brush
public sealed class SolidBrush : System.Drawing.Brush
type SolidBrush = class
inherit Brush
Public NotInheritable Class SolidBrush
Inherits Brush
- Ereditarietà
Esempio
Nell'esempio di codice seguente viene aggiunta un'ombreggiatura a un ListBox oggetto usando un oggetto SolidBrush.
Questo esempio è progettato per essere usato con un Windows Form. Per eseguire questo esempio, incollare questo codice in una maschera e chiamare il metodo quando si gestisce l'evento AddShadow del Paint modulo. Assicurarsi che il modulo contenga un ListBox oggetto denominato listBox1.
private:
void AddShadow( PaintEventArgs^ e )
{
// Create two SizeF objects.
SizeF shadowSize = listBox1->Size;
SizeF addSize = SizeF(10.5F,20.8F);
// Add them together and save the result in shadowSize.
shadowSize = shadowSize + addSize;
// Get the location of the ListBox and convert it to a PointF.
PointF shadowLocation = listBox1->Location;
// Add two points to get a new location.
shadowLocation = shadowLocation + System::Drawing::Size( 5, 5 );
// Create a rectangleF.
RectangleF rectFToFill = RectangleF(shadowLocation,shadowSize);
// Create a custom brush using a semi-transparent color, and
// then fill in the rectangle.
Color customColor = Color::FromArgb( 50, Color::Gray );
SolidBrush^ shadowBrush = gcnew SolidBrush( customColor );
array<RectangleF>^ temp0 = {rectFToFill};
e->Graphics->FillRectangles( shadowBrush, temp0 );
// Dispose of the brush.
delete shadowBrush;
}
private void AddShadow(PaintEventArgs e)
{
// Create two SizeF objects.
SizeF shadowSize = listBox1.Size;
SizeF addSize = new SizeF(10.5F, 20.8F);
// Add them together and save the result in shadowSize.
shadowSize = shadowSize + addSize;
// Get the location of the ListBox and convert it to a PointF.
PointF shadowLocation = listBox1.Location;
// Add two points to get a new location.
shadowLocation = shadowLocation + new Size(5, 5);
// Create a rectangleF.
RectangleF rectFToFill =
new RectangleF(shadowLocation, shadowSize);
// Create a custom brush using a semi-transparent color, and
// then fill in the rectangle.
Color customColor = Color.FromArgb(50, Color.Gray);
SolidBrush shadowBrush = new SolidBrush(customColor);
e.Graphics.FillRectangles(shadowBrush, new RectangleF[]{rectFToFill});
// Dispose of the brush.
shadowBrush.Dispose();
}
Private Sub AddShadow(ByVal e As PaintEventArgs)
' Create two SizeF objects.
Dim shadowSize As SizeF = Size.op_Implicit(listBox1.Size)
Dim addSize As New SizeF(10.5F, 20.8F)
' Add them together and save the result in shadowSize.
shadowSize = SizeF.op_Addition(shadowSize, addSize)
' Get the location of the ListBox and convert it to a PointF.
Dim shadowLocation As PointF = Point.op_Implicit(listBox1.Location)
' Add a Size to the Point to get a new location.
shadowLocation = PointF.op_Addition(shadowLocation, New Size(5, 5))
' Create a rectangleF.
Dim rectFToFill As New RectangleF(shadowLocation, shadowSize)
' Create a custom brush using a semi-transparent color, and
' then fill in the rectangle.
Dim customColor As Color = Color.FromArgb(50, Color.Gray)
Dim shadowBrush As SolidBrush = New SolidBrush(customColor)
e.Graphics.FillRectangles(shadowBrush, _
New RectangleF() {rectFToFill})
' Dispose of the brush.
shadowBrush.Dispose()
End Sub
Commenti
Questa classe eredita dalla Brush classe .
Annotazioni
In .NET 6 e versioni successive il pacchetto System.Drawing.Common, che include questo tipo, è supportato solo nei sistemi operativi Windows. L'uso di questo tipo nelle app multipiattaforma causa avvisi in fase di compilazione ed eccezioni in fase di esecuzione. Per altre informazioni, vedere System.Drawing.Common supportato solo in Windows.
Costruttori
| Nome | Descrizione |
|---|---|
| SolidBrush(Color) |
Inizializza un nuovo SolidBrush oggetto del colore specificato. |
Proprietà
| Nome | Descrizione |
|---|---|
| Color |
Ottiene o imposta il colore dell'oggetto SolidBrush . |
Metodi
| Nome | Descrizione |
|---|---|
| Clone() |
Crea una copia esatta di questo SolidBrush oggetto. |
| CreateObjRef(Type) |
Crea un oggetto che contiene tutte le informazioni pertinenti necessarie per generare un proxy utilizzato per comunicare con un oggetto remoto. (Ereditato da MarshalByRefObject) |
| Dispose() |
Rilascia tutte le risorse usate da questo Brush oggetto. (Ereditato da Brush) |
| Dispose(Boolean) |
Rilascia le risorse non gestite usate da Brush e, facoltativamente, rilascia le risorse gestite. (Ereditato da Brush) |
| Equals(Object) |
Determina se l'oggetto specificato è uguale all'oggetto corrente. (Ereditato da Object) |
| GetHashCode() |
Funge da funzione hash predefinita. (Ereditato da Object) |
| GetLifetimeService() |
Recupera l'oggetto servizio di durata corrente che controlla i criteri di durata per questa istanza. (Ereditato da MarshalByRefObject) |
| GetType() |
Ottiene il Type dell'istanza corrente. (Ereditato da Object) |
| InitializeLifetimeService() |
Ottiene un oggetto servizio di durata per controllare i criteri di durata per questa istanza. (Ereditato da MarshalByRefObject) |
| MemberwiseClone() |
Crea una copia superficiale del Objectcorrente. (Ereditato da Object) |
| MemberwiseClone(Boolean) |
Crea una copia superficiale dell'oggetto corrente MarshalByRefObject . (Ereditato da MarshalByRefObject) |
| SetNativeBrush(IntPtr) |
In una classe derivata imposta un riferimento a un oggetto pennello GDI+. (Ereditato da Brush) |
| ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |