Skip to content

Commit 193edfb

Browse files
committed
Fix back color
1 parent e71cbf8 commit 193edfb

File tree

2 files changed

+101
-13
lines changed

2 files changed

+101
-13
lines changed

SkinFramWorkCore/Extensions.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -355,18 +355,7 @@ public static void DrawBackgroundImage(this Graphics g, Image backgroundImage, C
355355
backgroundImageRectangle.X += clipRect.Width - backgroundImageRectangle.Width;
356356
if (rightToLeft == RightToLeft.Yes)
357357
{
358-
359358
g.Transform = new Matrix(-1, 0, 0, 1, bounds.Width, 0);
360-
Region reg = g.Clip;
361-
Rectangle r = bounds;
362-
reg.Exclude(r);
363-
//using (var solidBrush = new SolidBrush(backColor))
364-
365-
366-
367-
//g.FillRectangle(solidBrush, clipRect);
368-
reg.Union(r); ;
369-
g.Clip = reg;
370359

371360
}
372361
if (!clipRect.Contains(backgroundImageRectangle))
@@ -407,6 +396,15 @@ public static void DrawBackgroundImage(this Graphics g, Image backgroundImage, C
407396
}
408397
}
409398

399+
public static Rectangle RtlRectangle(this Rectangle rectangle, int width)
400+
{
401+
return new Rectangle(
402+
width - rectangle.Width - rectangle.X,
403+
rectangle.Y,
404+
rectangle.Width,
405+
rectangle.Height);
406+
}
407+
410408
public static bool IsDrawMaximizeBox(this Form form)
411409
{
412410
return form.MaximizeBox && form.FormBorderStyle != FormBorderStyle.SizableToolWindow &&

SkinFramWorkCore/NonClientTheme.cs

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,101 @@ private void InvalidateWindow()
406406
}
407407
private void Rtl_Paint(object sender, PaintEventArgs e)
408408
{
409-
if (BackgroundImage != null)
409+
e.Graphics.Clear(BackColor);
410+
if (RightToLeftLayout && RightToLeft == RightToLeft.Yes)
410411
{
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+
}
412495
}
496+
else
497+
graphics.FillRectangle(SystemBrushes.Control, rectangle);
498+
}
413499

500+
501+
private static bool IsImageTransparent(Image backgroundImage)
502+
{
503+
return backgroundImage != null && (backgroundImage.Flags & 2) > 0;
414504
}
415505
private void ResetNcTracking(IntPtr hwnd)
416506
{

0 commit comments

Comments
 (0)