using System.Drawing; using System.Drawing.Drawing2D; class Program { static void Main(string[] args) { using (var graphics = Graphics.FromImage(new Bitmap(100, 100))) { using (var hatchBrush = new HatchBrush(HatchStyle.Cross, Color.Black)) { graphics.FillRectangle(hatchBrush, new Rectangle(0, 0, 100, 100)); hatchBrush.Dispose(); // Dispose method called to deallocate resources } } } }
using System.Drawing; using System.Drawing.Drawing2D; class Program { static void Main(string[] args) { using (var graphics = Graphics.FromImage(new Bitmap(100, 100))) { var hatchBrush = new HatchBrush(HatchStyle.Cross, Color.Black); graphics.FillRectangle(hatchBrush, new Rectangle(0, 0, 100, 100)); hatchBrush.Dispose(); // Dispose method called to deallocate resources } } }In this example, we create a hatch brush object and fill a rectangle with it using the Graphics object. After completing the task, we call the Dispose method to release the resources used by the hatch brush. The package/library used in these examples is System.Drawing.