private void button1_Click(object sender, EventArgs e) { Graphics g = this.CreateGraphics(); Rectangle r = button1.Bounds; r.Inflate(1, 1); ControlPaint.DrawFocusRectangle(g, r, Color.Black, Color.Transparent); }In this example, we are using the CreateGraphics method to get a reference to the graphics context of the form, creating a rectangle that is slightly larger than the bounds of the button, and then using the DrawFocusRectangle method to draw the dotted rectangle around the button's bounds. This code is part of the System.Drawing package, which is part of the .NET Framework class library.