Independent visual style

Using C # winforms, I want to create custom controls that look like real ones.

There are many classes that you can use to draw controls that look like real: ControlPaint, VisualStyleRenderer, ButtonRenderer, CheckBoxRenderer, ComboBoxRenderer, GroupBoxRenderer, ProgressBarRenderer, RadioButtonRenderer, ScrollBarRenderer, TabRenderer, TextBoxRenderer, TextRenderer, ToolStripProfessionalRenderer, ToolStripRenderer, ToolStripSystemRenderer, TrackBarRenderer.

Challenges when considering visual styles: I want visual styles to be independent. Meaning: I don't like if the user allows visual styles or not, I want it to work. if the user has enabled visual styles, I want to draw it using visual styles, otherwise I want to draw it without visual styles.

The MSDN documentation only class, independent of visual styles, are ButtonRenderer, CheckBoxRenderer, GroupBoxRenderer, RadioButtonRenderer. This means that for all other cases I need to check myself if visual styles are allowed and use different code to paint the details.

Suppose I want to draw Tab controls myself. TabRendererthe class has all the necessary functions for this, but it only works if the user has visual styles. otherwise I need to use the class ControlPaintto draw, but it uses a completely different model, there is no method ControlPaint.DrawTab()or something like that, and I need to figure out what types of rectangles I need to draw so that it looks like a real tab. it is annoying.

Built-in controls, including the Tab control, already have this functionality for drawing with or without styles. Why doesn't Microsoft disclose this functionality to the creators of user control? Why do creators of user control suffer?

+3
1

, , . , , Microsoft WinForm, Application.RenderWithVisualStyes Control.UseVisualStyleBackColor. .

, , MyControlRenderer.cs. , . NET REF, , VisualStyleRenderer System.Windows.Forms.VisualStyles, .

, . .

, .

0

Source: https://habr.com/ru/post/1759675/


All Articles