Paint paint = new Paint(); paint.Color = Color.Red; paint.StrokeWidth = 5; paint.SetStyle(Paint.Style.Stroke); // set to stroke style canvas.DrawRect(50, 50, 250, 250, paint); // draw rectangle with dimensions and paint object
Paint paint = new Paint(); paint.Color = Color.Blue; paint.SetStyle(Paint.Style.Fill); // set to fill style paint.AntiAlias = true; RectF rectF = new RectF(50, 50, 250, 250); canvas.DrawRoundRect(rectF, 10, 10, paint); // draw rounded rectangle with dimensions, radius, and paint objectIn summary, the Android.Graphics.Canvas.DrawRect method is used to draw rectangular shapes on a canvas. It can be used in C# programming language and is part of the Android.Graphics package library. The examples above demonstrate how to draw rectangles with different styles, colors, and dimensions using the DrawRect method.