@@ -12,26 +12,66 @@ public class RadioButtonRendererTests : AbstractButtonBaseTests
12
12
[ WinFormsTheory ]
13
13
[ InlineData ( RadioButtonState . CheckedNormal ) ]
14
14
[ InlineData ( RadioButtonState . CheckedPressed ) ]
15
- public void RadioButtonRenderer_DrawRadioButton ( RadioButtonState state )
15
+ public void RadioButtonRenderer_DrawRadioButton ( RadioButtonState rBState )
16
16
{
17
- using Bitmap bitmap = new ( 100 , 100 ) ;
18
- using Graphics graphics = Graphics . FromImage ( bitmap ) ;
19
- Point point = new ( 10 , 20 ) ;
17
+ using Form form = new Form ( ) ;
18
+ using RadioButton control = ( RadioButton ) CreateButton ( ) ;
19
+ form . Controls . Add ( control ) ;
20
20
21
- RadioButtonRenderer . DrawRadioButton ( graphics , point , state ) ;
21
+ form . Handle . Should ( ) . NotBe ( IntPtr . Zero ) ;
22
+
23
+ using EmfScope emf = new ( ) ;
24
+ DeviceContextState state = new ( emf ) ;
25
+ using Graphics graphics = Graphics . FromHdc ( ( IntPtr ) emf . HDC ) ;
26
+
27
+ Point point = new ( control . Location . X , control . Location . Y ) ;
28
+ Rectangle bounds = control . Bounds ;
29
+
30
+ RadioButtonRenderer . DrawRadioButton ( graphics , point , rBState ) ;
31
+
32
+ if ( Application . RenderWithVisualStyles )
33
+ {
34
+ emf . Validate (
35
+ state ,
36
+ Application . RenderWithVisualStyles
37
+ ? Validate . SkipType ( ENHANCED_METAFILE_RECORD_TYPE . EMR_ALPHABLEND )
38
+ : Validate . Repeat ( Validate . SkipType ( ENHANCED_METAFILE_RECORD_TYPE . EMR_STRETCHDIBITS ) , 1 )
39
+ ) ;
40
+ }
22
41
}
23
42
24
43
[ WinFormsTheory ]
25
44
[ InlineData ( RadioButtonState . CheckedNormal ) ]
26
45
[ InlineData ( RadioButtonState . CheckedPressed ) ]
27
- public void RadioButtonRenderer_DrawRadioButton_OverloadWithSizeAndText ( RadioButtonState state )
46
+ public void RadioButtonRenderer_DrawRadioButton_OverloadWithSizeAndText ( RadioButtonState rBState )
28
47
{
29
- using Bitmap bitmap = new ( 100 , 100 ) ;
30
- using Graphics graphics = Graphics . FromImage ( bitmap ) ;
31
- Point point = new ( 10 , 20 ) ;
32
- Rectangle bounds = new ( 10 , 20 , 30 , 40 ) ;
48
+ using Form form = new Form ( ) ;
49
+ using RadioButton control = ( RadioButton ) CreateButton ( ) ;
50
+ form . Controls . Add ( control ) ;
33
51
34
- RadioButtonRenderer . DrawRadioButton ( graphics , point , bounds , "Text" , SystemFonts . DefaultFont , focused : false , state ) ;
52
+ form . Handle . Should ( ) . NotBe ( IntPtr . Zero ) ;
53
+
54
+ using EmfScope emf = new ( ) ;
55
+ DeviceContextState state = new ( emf ) ;
56
+ using Graphics graphics = Graphics . FromHdc ( ( IntPtr ) emf . HDC ) ;
57
+
58
+ Point point = new ( control . Location . X , control . Location . Y ) ;
59
+ Rectangle bounds = control . Bounds ;
60
+ control . Text = "Text" ;
61
+
62
+ RadioButtonRenderer . DrawRadioButton ( graphics , point , bounds , control . Text , SystemFonts . DefaultFont , false , rBState ) ;
63
+
64
+ emf . Validate (
65
+ state ,
66
+ Application . RenderWithVisualStyles
67
+ ? Validate . SkipType ( ENHANCED_METAFILE_RECORD_TYPE . EMR_ALPHABLEND )
68
+ : Validate . Repeat ( Validate . SkipType ( ENHANCED_METAFILE_RECORD_TYPE . EMR_STRETCHDIBITS ) , 1 ) ,
69
+ Validate . TextOut (
70
+ control . Text ,
71
+ bounds : new Rectangle ( 41 , 5 , 20 , 12 ) ,
72
+ State . FontFace ( SystemFonts . DefaultFont . Name )
73
+ )
74
+ ) ;
35
75
}
36
76
37
77
[ WinFormsTheory ]
@@ -40,135 +80,60 @@ public void RadioButtonRenderer_DrawRadioButton_OverloadWithSizeAndText(RadioBut
40
80
[ InlineData ( TextFormatFlags . PreserveGraphicsTranslateTransform , RadioButtonState . CheckedPressed ) ]
41
81
[ InlineData ( TextFormatFlags . TextBoxControl , RadioButtonState . UncheckedNormal ) ]
42
82
public void RadioButtonRenderer_DrawRadioButton_OverloadWithTextFormat ( TextFormatFlags textFormat ,
43
- RadioButtonState state )
83
+ RadioButtonState rBState )
44
84
{
45
- using Bitmap bitmap = new ( 100 , 100 ) ;
46
- using Graphics graphics = Graphics . FromImage ( bitmap ) ;
47
- Point point = new ( 10 , 20 ) ;
48
- Rectangle bounds = new ( 10 , 20 , 30 , 40 ) ;
85
+ using Form form = new Form ( ) ;
86
+ using RadioButton control = ( RadioButton ) CreateButton ( ) ;
87
+ form . Controls . Add ( control ) ;
49
88
50
- RadioButtonRenderer . DrawRadioButton ( graphics , point , bounds , "Text" , SystemFonts . DefaultFont , textFormat , false ,
51
- state ) ;
52
- }
89
+ form . Handle . Should ( ) . NotBe ( IntPtr . Zero ) ;
53
90
54
- [ WinFormsFact ]
55
- public unsafe void CaptureButton ( )
56
- {
57
- using RadioButton radioButton = ( RadioButton ) CreateButton ( ) ;
58
- using EmfScope emf = new ( ) ;
59
- radioButton . PrintToMetafile ( emf ) ;
60
-
61
- List < ENHANCED_METAFILE_RECORD_TYPE > types = [ ] ;
62
- List < string > details = [ ] ;
63
- emf . Enumerate ( ( ref EmfRecord record ) =>
64
- {
65
- types . Add ( record . Type ) ;
66
- details . Add ( record . ToString ( ) ) ;
67
- return true ;
68
- } ) ;
69
- }
70
-
71
- [ WinFormsFact ]
72
- public unsafe void Button_VisualStyles_off_Default_LineDrawing ( )
73
- {
74
- if ( Application . RenderWithVisualStyles )
75
- {
76
- return ;
77
- }
78
-
79
- using RadioButton radioButton = ( RadioButton ) CreateButton ( ) ;
80
91
using EmfScope emf = new ( ) ;
81
92
DeviceContextState state = new ( emf ) ;
82
- Rectangle bounds = radioButton . Bounds ;
93
+ using Graphics graphics = Graphics . FromHdc ( ( IntPtr ) emf . HDC ) ;
83
94
84
- radioButton . PrintToMetafile ( emf ) ;
95
+ Point point = new ( control . Location . X , control . Location . Y ) ;
96
+ Rectangle bounds = control . Bounds ;
97
+ control . Text = "Text" ;
85
98
86
- emf . Validate (
87
- state ,
88
- Validate . Repeat ( Validate . SkipType ( ENHANCED_METAFILE_RECORD_TYPE . EMR_BITBLT ) , 1 ) ,
89
- Validate . LineTo (
90
- new ( bounds . Right - 1 , 0 ) , new ( 0 , 0 ) ,
91
- State . PenColor ( SystemColors . ControlLightLight ) ) ,
92
- Validate . LineTo (
93
- new ( 0 , 0 ) , new ( 0 , bounds . Bottom - 1 ) ,
94
- State . PenColor ( SystemColors . ControlLightLight ) ) ,
95
- Validate . LineTo (
96
- new ( 0 , bounds . Bottom - 1 ) , new ( bounds . Right - 1 , bounds . Bottom - 1 ) ,
97
- State . PenColor ( SystemColors . ControlDarkDark ) ) ,
98
- Validate . LineTo (
99
- new ( bounds . Right - 1 , bounds . Bottom - 1 ) , new ( bounds . Right - 1 , - 1 ) ,
100
- State . PenColor ( SystemColors . ControlDarkDark ) ) ,
101
- Validate . LineTo (
102
- new ( bounds . Right - 2 , 1 ) , new ( 1 , 1 ) ,
103
- State . PenColor ( SystemColors . Control ) ) ,
104
- Validate . LineTo (
105
- new ( 1 , 1 ) , new ( 1 , bounds . Bottom - 2 ) ,
106
- State . PenColor ( SystemColors . Control ) ) ,
107
- Validate . LineTo (
108
- new ( 1 , bounds . Bottom - 2 ) , new ( bounds . Right - 2 , bounds . Bottom - 2 ) ,
109
- State . PenColor ( SystemColors . ControlDark ) ) ,
110
- Validate . LineTo (
111
- new ( bounds . Right - 2 , bounds . Bottom - 2 ) , new ( bounds . Right - 2 , 0 ) ,
112
- State . PenColor ( SystemColors . ControlDark ) ) ) ;
99
+ RadioButtonRenderer . DrawRadioButton ( graphics , point , bounds , control . Text , SystemFonts . DefaultFont , textFormat , false , rBState ) ;
113
100
}
114
101
115
- [ WinFormsFact ]
116
- public unsafe void Button_VisualStyles_off_Default_WithText_LineDrawing ( )
102
+ [ WinFormsTheory ]
103
+ [ BoolData ( ) ]
104
+ public void RadioButtonRenderer_DrawRadioButton_OverloadWithHandle ( bool focus )
117
105
{
118
- if ( Application . RenderWithVisualStyles )
119
- {
120
- return ;
121
- }
106
+ using Form form = new Form ( ) ;
107
+ using RadioButton control = ( RadioButton ) CreateButton ( ) ;
108
+ form . Controls . Add ( control ) ;
109
+ form . Handle . Should ( ) . NotBe ( IntPtr . Zero ) ;
122
110
123
- using RadioButton radioButton = ( RadioButton ) CreateButton ( ) ;
124
- radioButton . Text = "Hello" ;
125
111
using EmfScope emf = new ( ) ;
126
112
DeviceContextState state = new ( emf ) ;
127
- Rectangle bounds = radioButton . Bounds ;
113
+ using Graphics graphics = Graphics . FromHdc ( ( IntPtr ) emf . HDC ) ;
114
+ Point point = new ( control . Location . X , control . Location . Y ) ;
115
+ Rectangle bounds = control . Bounds ;
116
+ control . Text = "Text" ;
128
117
129
- radioButton . PrintToMetafile ( emf ) ;
118
+ RadioButtonRenderer . DrawRadioButton ( graphics , point , bounds , control . Text , SystemFonts . DefaultFont , TextFormatFlags . Default , focus , RadioButtonState . CheckedNormal , HWND . Null ) ;
130
119
131
120
emf . Validate (
132
121
state ,
133
- Validate . SkipType ( ENHANCED_METAFILE_RECORD_TYPE . EMR_BITBLT ) ,
134
- Validate . TextOut ( "Hello" ) ,
135
- Validate . LineTo (
136
- new ( bounds . Right - 1 , 0 ) , new ( 0 , 0 ) ,
137
- State . PenColor ( SystemColors . ControlLightLight ) ) ,
138
- Validate . LineTo (
139
- new ( 0 , 0 ) , new ( 0 , bounds . Bottom - 1 ) ,
140
- State . PenColor ( SystemColors . ControlLightLight ) ) ,
141
- Validate . LineTo (
142
- new ( 0 , bounds . Bottom - 1 ) , new ( bounds . Right - 1 , bounds . Bottom - 1 ) ,
143
- State . PenColor ( SystemColors . ControlDarkDark ) ) ,
144
- Validate . LineTo (
145
- new ( bounds . Right - 1 , bounds . Bottom - 1 ) , new ( bounds . Right - 1 , - 1 ) ,
146
- State . PenColor ( SystemColors . ControlDarkDark ) ) ,
147
- Validate . LineTo (
148
- new ( bounds . Right - 2 , 1 ) , new ( 1 , 1 ) ,
149
- State . PenColor ( SystemColors . Control ) ) ,
150
- Validate . LineTo (
151
- new ( 1 , 1 ) , new ( 1 , bounds . Bottom - 2 ) ,
152
- State . PenColor ( SystemColors . Control ) ) ,
153
- Validate . LineTo (
154
- new ( 1 , bounds . Bottom - 2 ) , new ( bounds . Right - 2 , bounds . Bottom - 2 ) ,
155
- State . PenColor ( SystemColors . ControlDark ) ) ,
156
- Validate . LineTo (
157
- new ( bounds . Right - 2 , bounds . Bottom - 2 ) , new ( bounds . Right - 2 , 0 ) ,
158
- State . PenColor ( SystemColors . ControlDark ) ) ) ;
159
- }
160
-
161
- [ WinFormsFact ]
162
- public unsafe void CaptureButtonOnForm ( )
163
- {
164
- using Form form = new ( ) ;
165
- using RadioButton radioButton = ( RadioButton ) CreateButton ( ) ;
166
- form . Controls . Add ( radioButton ) ;
167
-
168
- using EmfScope emf = new ( ) ;
169
- form . PrintToMetafile ( emf ) ;
170
-
171
- string details = emf . RecordsToString ( ) ;
122
+ Application . RenderWithVisualStyles
123
+ ? Validate . SkipType ( ENHANCED_METAFILE_RECORD_TYPE . EMR_ALPHABLEND )
124
+ : Validate . Repeat ( Validate . SkipType ( ENHANCED_METAFILE_RECORD_TYPE . EMR_STRETCHDIBITS ) , 1 ) ,
125
+ Validate . TextOut (
126
+ control . Text ,
127
+ bounds : new Rectangle ( 3 , 0 , 20 , 12 ) ,
128
+ State . FontFace ( SystemFonts . DefaultFont . Name )
129
+ ) ,
130
+ ( focus
131
+ ? Validate . PolyPolygon16 ( new ( new ( bounds . X , bounds . Y ) , new Size ( - 1 , - 1 ) ) )
132
+ : null ) ! ,
133
+ ( focus
134
+ ? Validate . Repeat ( Validate . SkipType ( ENHANCED_METAFILE_RECORD_TYPE . EMR_STRETCHDIBITS ) , 2 )
135
+ : null ) !
136
+ ) ;
172
137
}
173
138
174
139
protected override ButtonBase CreateButton ( ) => new RadioButton ( ) ;
0 commit comments