Navigation Bar Custom Painting Specifics
- 2 minutes to read
Custom drawing provides specially designed events, allowing you to take full control over the painting process. The custom draw events are raised every time the corresponding elements need to be painted. An event handler receives an object whose properties specify an element’s bounds, the appearance settings used to paint the element and the view information specific to the painted element.
There are two main scenarios for using custom draw events:
You can perform the overall painting of an element using the drawing methods of a Graphics object.
In this instance, you don’t need to render the entire element yourself, instead you can simply change the information (appearance, contents, bounds) used to draw it. The element will then be painted after the event handler has been executed.
Performing complete element painting
Custom draw events allow you to perform complete painting of the NavBar‘s elements. An event’s CustomDrawObjectEventArgs.Graphics parameter represents the graphic surface, and this provides the drawing methods, used to render the control’s elements. To prevent the element’s default painting from being performed set the event’s CustomDrawObjectEventArgs.Handled parameter to true. This indicates that the event was handled and that no default actions are required. If this property is set to false, the element will be painted using the default drawing mechanism after the event handler has been executed.
Customizing the display information of elements
Using custom draw events, you can customize an element’s display information, and then invoke the default painting procedure. This allows the element’s appearance to be controlled dynamically. The event’s CustomDrawObjectEventArgs.Handled parameter must be left set to false. The element will be painted using the specified information, after your event is handled.