@@ -406,11 +406,101 @@ private void InvalidateWindow()
406
406
}
407
407
private void Rtl_Paint ( object sender , PaintEventArgs e )
408
408
{
409
- if ( BackgroundImage != null )
409
+ e . Graphics . Clear ( BackColor ) ;
410
+ if ( RightToLeftLayout && RightToLeft == RightToLeft . Yes )
410
411
{
411
- e . Graphics . DrawBackgroundImage ( BackgroundImage , BackColor , BackgroundImageLayout , ClientRectangle , ClientRectangle , Point . Empty , RightToLeft ) ;
412
+ e . Graphics . Transform = new Matrix ( - 1 , 0 , 0 , 1 , Width - 17 , 0 ) ;
413
+
414
+ }
415
+ var clipRectangle = e . ClipRectangle . RtlRectangle ( Width - 17 ) ;
416
+ if ( ( HScroll || VScroll ) && BackgroundImage != null &&
417
+ ( BackgroundImageLayout == ImageLayout . Zoom || BackgroundImageLayout == ImageLayout . Stretch ||
418
+ BackgroundImageLayout == ImageLayout . Center ) )
419
+ {
420
+ if ( IsImageTransparent ( BackgroundImage ) )
421
+ PaintTransparentBackground ( e , clipRectangle ) ;
422
+ e . Graphics . DrawBackgroundImage ( BackgroundImage , BackColor , BackgroundImageLayout , clipRectangle ,
423
+ clipRectangle , clipRectangle . Location , RightToLeft ) ;
424
+ }
425
+ else
426
+ {
427
+
428
+ PaintBackground ( e , clipRectangle , BackColor ) ;
429
+ }
430
+ }
431
+ private void PaintBackground ( PaintEventArgs e , Rectangle rectangle , Color backColor )
432
+ {
433
+ if ( BackColor == Color . Transparent )
434
+ PaintTransparentBackground ( e , rectangle ) ;
435
+ if ( BackgroundImage != null && ! SystemInformation . HighContrast )
436
+ {
437
+ if ( BackgroundImageLayout == ImageLayout . Tile && IsImageTransparent ( BackgroundImage ) )
438
+ PaintTransparentBackground ( e , rectangle ) ;
439
+ e . Graphics . DrawBackgroundImage ( BackgroundImage , backColor , BackgroundImageLayout , ClientRectangle ,
440
+ ClientRectangle , Point . Empty , RightToLeft ) ;
441
+ }
442
+
443
+ }
444
+
445
+ private void PaintTransparentBackground ( PaintEventArgs e , Rectangle rectangle , Region transparentRegion = null )
446
+ {
447
+ Graphics graphics = e . Graphics ;
448
+ Control parentInternal = Parent ;
449
+ if ( parentInternal != null )
450
+ {
451
+ if ( Application . RenderWithVisualStyles /*&& parentInternal.RenderTransparencyWithVisualStyles*/ )
452
+ {
453
+ GraphicsState gstate = null ;
454
+ if ( transparentRegion != null )
455
+ gstate = graphics . Save ( ) ;
456
+ try
457
+ {
458
+ if ( transparentRegion != null )
459
+ graphics . Clip = transparentRegion ;
460
+ ButtonRenderer . DrawParentBackground ( graphics , rectangle , this ) ;
461
+ }
462
+ finally
463
+ {
464
+ if ( gstate != null )
465
+ graphics . Restore ( gstate ) ;
466
+ }
467
+ }
468
+ else
469
+ {
470
+ Rectangle rectangle1 = new Rectangle ( - Left , - Top , parentInternal . Width , parentInternal . Height ) ;
471
+ Rectangle clipRect = new Rectangle ( rectangle . Left + Left , rectangle . Top + Top , rectangle . Width , rectangle . Height ) ;
472
+ using ( Graphics windowsGraphics = graphics )
473
+ {
474
+ windowsGraphics . TranslateTransform ( - Left , - Top ) ;
475
+ using ( PaintEventArgs e1 = new PaintEventArgs ( windowsGraphics , clipRect ) )
476
+ {
477
+ if ( transparentRegion != null )
478
+ {
479
+ e1 . Graphics . Clip = transparentRegion ;
480
+ e1 . Graphics . TranslateClip ( - rectangle1 . X , - rectangle1 . Y ) ;
481
+ }
482
+ try
483
+ {
484
+ InvokePaintBackground ( parentInternal , e1 ) ;
485
+ InvokePaint ( parentInternal , e1 ) ;
486
+ }
487
+ finally
488
+ {
489
+ if ( transparentRegion != null )
490
+ e1 . Graphics . TranslateClip ( rectangle1 . X , rectangle1 . Y ) ;
491
+ }
492
+ }
493
+ }
494
+ }
412
495
}
496
+ else
497
+ graphics . FillRectangle ( SystemBrushes . Control , rectangle ) ;
498
+ }
413
499
500
+
501
+ private static bool IsImageTransparent ( Image backgroundImage )
502
+ {
503
+ return backgroundImage != null && ( backgroundImage . Flags & 2 ) > 0 ;
414
504
}
415
505
private void ResetNcTracking ( IntPtr hwnd )
416
506
{
0 commit comments