SolidBrush Class

Definition

Defines a brush of a single color.Defines a brush of a single color. Brushes are used to fill graphics shapes, such as rectangles, ellipses, pies, polygons, and paths.Brushes are used to fill graphics shapes, such as rectangles, ellipses, pies, polygons, and paths. This class cannot be inherited.This class cannot be inherited.

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
Inheritance

Examples

  • Следующий пример кода добавляет тень в ListBox с помощью SolidBrush.The following code example adds a shadow to a ListBox using a SolidBrush.

Этот пример предназначен для использования с Windows Form.This example is designed to be used with a Windows Form. Чтобы выполнить этот пример, вставьте этот код в форму и вызовите метод AddShadow при обработке события Paint формы.To run this example, paste this code into a form and call the AddShadow method when handling the form's Paint event. Убедитесь, что форма содержит ListBox с именем listBox1.Make sure the form contains a ListBox named 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

Remarks

Этот класс наследуется от класса Brush.This class inherits from the Brush class.

Constructors

SolidBrush(Color)

Initializes a new SolidBrush object of the specified color.Initializes a new SolidBrush object of the specified color.

Properties

Color

Gets or sets the color of this SolidBrush object.Gets or sets the color of this SolidBrush object.

Methods

Clone()

Creates an exact copy of this SolidBrush object.Creates an exact copy of this SolidBrush object.

CreateObjRef(Type)

Создает объект, который содержит всю необходимую информацию для создания прокси-сервера, используемого для взаимодействия с удаленным объектом.Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose()

Освобождает все ресурсы, используемые этим объектом Brush.Releases all resources used by this Brush object.

(Inherited from Brush)
Dispose(Boolean)

Освобождает неуправляемые ресурсы, используемые Brush, и дополнительно освобождает управляемые ресурсы.Releases the unmanaged resources used by the Brush and optionally releases the managed resources.

(Inherited from Brush)
Equals(Object)

Определяет, равен ли заданный объект текущему объекту.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Служит хэш-функцией по умолчанию.Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()

Извлекает объект обслуживания во время существования, который управляет политикой времени существования данного экземпляра.Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetType()

Возвращает объект Type для текущего экземпляра.Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService()

Получает объект службы времени существования для управления политикой времени существования для этого экземпляра.Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone()

Создает неполную копию текущего объекта Object.Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Создает неполную копию текущего объекта MarshalByRefObject.Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
SetNativeBrush(IntPtr)

В производном классе определяет ссылку на объект-кисть GDI+GDI+.In a derived class, sets a reference to a GDI+GDI+ brush object.

(Inherited from Brush)
ToString()

Возвращает строку, представляющую текущий объект.Returns a string that represents the current object.

(Inherited from Object)

Applies to