@@ -140,6 +140,7 @@ public string Title
140
140
private const string NotAvailable = "n/a" ;
141
141
private const int CanvasSizeWarningThreshold = 1280 ;
142
142
private Size sizeHint ;
143
+ private object lastChangedCtrl ;
143
144
144
145
#endregion
145
146
@@ -153,7 +154,7 @@ public SvgImportDialog()
153
154
canvash . KeyUp += Canvas_KeyUp ;
154
155
canvasw . ValueChanged += CanvasW_ValueChanged ;
155
156
canvash . ValueChanged += CanvasH_ValueChanged ;
156
- cbKeepAR . CheckedChanged += CanvasW_ValueChanged ;
157
+ cbKeepAR . CheckedChanged += KeepAR_CheckedChanged ;
157
158
linkLabel1 . Click += BtnUseOriginal_Click ;
158
159
linkGitHub . LinkClicked += LinkGitHub_LinkClicked ;
159
160
btnOk . Click += BtnOk_Click ;
@@ -177,21 +178,43 @@ private void SetDefaults()
177
178
178
179
private void UpdateCanvasH ( )
179
180
{
181
+ decimal newHeight ;
180
182
if ( KeepAspectRatio )
181
183
{
182
- canvash . Value = canvasw . Value * sizeHint . Height / sizeHint . Width ;
184
+ newHeight = canvasw . Value * sizeHint . Height / sizeHint . Width ;
185
+ }
186
+ else
187
+ {
188
+ newHeight = canvash . Value ;
189
+ }
190
+
191
+ if ( newHeight < 1 )
192
+ {
193
+ newHeight = canvasw . Minimum ;
183
194
}
184
195
185
- warningBox . Visible = canvash . Value > CanvasSizeWarningThreshold ;
196
+ canvash . Value = newHeight ;
197
+ warningBox . Visible = newHeight > CanvasSizeWarningThreshold ;
186
198
}
187
199
188
200
private void UpdateCanvasW ( )
189
201
{
202
+ decimal newWidth ;
190
203
if ( KeepAspectRatio )
191
204
{
192
- canvasw . Value = canvash . Value * sizeHint . Width / sizeHint . Height ;
205
+ newWidth = canvash . Value * sizeHint . Width / sizeHint . Height ;
206
+ }
207
+ else
208
+ {
209
+ newWidth = canvasw . Value ;
210
+ }
211
+
212
+ if ( newWidth < 1 )
213
+ {
214
+ newWidth = canvash . Minimum ;
193
215
}
194
216
217
+ canvasw . Value = newWidth ;
195
218
warningBox . Visible = canvasw . Value > CanvasSizeWarningThreshold ;
196
219
}
197
220
@@ -265,16 +288,32 @@ public void InitSizeHint()
265
288
266
289
private void CanvasW_ValueChanged ( object sender , EventArgs e )
267
290
{
291
+ lastChangedCtrl = sender ;
268
292
UpdateCanvasH ( ) ;
269
293
}
270
294
271
295
private void CanvasH_ValueChanged ( object sender , EventArgs e )
272
296
{
297
+ lastChangedCtrl = sender ;
273
298
UpdateCanvasW ( ) ;
274
299
}
275
300
301
+ private void KeepAR_CheckedChanged ( object sender , EventArgs e )
302
+ {
303
+ if ( ReferenceEquals ( lastChangedCtrl , canvasw ) )
304
+ {
305
+ UpdateCanvasH ( ) ;
306
+ }
307
+ else
308
+ {
309
+ UpdateCanvasW ( ) ;
310
+ }
311
+ }
312
+
276
313
private void Canvas_KeyUp ( object sender , KeyEventArgs e )
277
314
{
315
+ lastChangedCtrl = sender ;
316
+
278
317
if ( e . KeyValue >= '0' || e . KeyValue <= '9' ||
279
318
e . KeyCode == Keys . Delete || e . KeyCode == Keys . Back )
280
319
{
0 commit comments