using System.Windows.Forms.VisualStyles; using System.Drawing; public class CustomButton : Button { protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (Application.RenderWithVisualStyles) { VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal); renderer.DrawBackground(e.Graphics, ClientRectangle); } } }
using System.Windows.Forms.VisualStyles; using System.Drawing; public class CustomProgressBar : ProgressBar { protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (Application.RenderWithVisualStyles) { ProgressBarRenderer.DrawHorizontalBar(e.Graphics, ClientRectangle); Rectangle progressRect = new Rectangle(ClientRectangle.Left, ClientRectangle.Top, (int)(ClientRectangle.Width * ((double)Value / Maximum)), ClientRectangle.Height); ProgressBarRenderer.DrawHorizontalChunks(e.Graphics, progressRect); } } }In both examples, the VisualStyleRenderer class is used to draw the visual style of the control. In the first example, the PushButton.Normal element is used, while in the second example, the HorizontalBar and HorizontalChunks elements are used. Overall, the System.Windows.Forms.VisualStyles namespace contains classes that allow .NET applications to utilize the visual styles of the operating system.