Search code examples
c#buttongdi+gdi

How windows form controls draw themselves?


When we use a windows form control like a Button,How it draws itself on the form?

Using GDI+,or System.Drawings for whatever else?

Thanks for your time :D


Solution

  • http://msdn.microsoft.com/en-us/library/system.windows.forms.buttonrenderer(v=vs.110).aspx

    this is button specific but I think it helps get the idea accross.

    Here is an excerpt from that link:

    The ButtonRenderer class provides a set of static methods that can be used to render a button control. Rendering a control refers to drawing the user interface of a control. To draw a button, use one of the DrawButton methods. These methods provide a variety of options, such as drawing text or an image on the button. If visual styles are enabled in the operating system and visual styles are applied to the current application, DrawButton will draw the button with the current visual style. Otherwise, DrawButton will draw the button with the classic Windows style. This is useful if you are drawing a custom control that should automatically match the current visual style setting of the operating system. This class wraps the functionality of a System.Windows.Forms.VisualStyles.VisualStyleRenderer that is set to one of the elements exposed by the System.Windows.Forms.VisualStyles.VisualStyleElement.Button.PushButton class. For more information, see Rendering Controls with Visual Styles.

    Here is some more specific information

    http://msdn.microsoft.com/en-us/library/a36fascx(v=vs.110).aspx

    Execerpt:

    The common language runtime uses an advanced implementation of the Windows Graphics Device Interface (GDI) called GDI+. With GDI+ you can create graphics, draw text, and manipulate graphical images as objects. GDI+ is designed to offer performance and ease of use. You can use GDI+ to render graphical images on Windows Forms and controls. Although you cannot use GDI+ directly on Web Forms, you can display graphical images through the Image Web Server control. In this section, you will find topics that introduce the fundamentals of GDI+ programming. Although not intended to be a comprehensive reference, this section includes information about the Graphics, Pen, Brush, and Color objects, and explains how to perform such tasks as drawing shapes, drawing text, or displaying images. For more information, see "GDI+ Reference" in the MSDN library at http://msdn.microsoft.com/library.