* UIAvatar:更改图片显示
This commit is contained in:
parent
dd60d86959
commit
79a0cd8bfc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -246,6 +246,8 @@ namespace Sunny.UI
|
|||||||
[DefaultValue(0), Description("垂直偏移"), Category("SunnyUI")]
|
[DefaultValue(0), Description("垂直偏移"), Category("SunnyUI")]
|
||||||
public int OffsetY { get; set; } = 0;
|
public int OffsetY { get; set; } = 0;
|
||||||
|
|
||||||
|
public event PaintEventHandler PaintAgain;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// OnPaint
|
/// OnPaint
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -259,9 +261,9 @@ namespace Sunny.UI
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int size = Math.Min(Width, Height) - 3;
|
|
||||||
if (Icon == UIIcon.Image)
|
if (Icon == UIIcon.Image)
|
||||||
{
|
{
|
||||||
|
int size = avatarSize;
|
||||||
if (Image == null)
|
if (Image == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -274,21 +276,21 @@ namespace Sunny.UI
|
|||||||
(int)(Image.Height * 1.0 / Math.Min(sc1, sc2) + 0.5));
|
(int)(Image.Height * 1.0 / Math.Min(sc1, sc2) + 0.5));
|
||||||
|
|
||||||
Bitmap bmp = scaleImage.Split(size, Shape);
|
Bitmap bmp = scaleImage.Split(size, Shape);
|
||||||
e.Graphics.DrawImage(bmp, 1, 1);
|
e.Graphics.DrawImage(bmp, (Width - avatarSize) / 2 + 1 + OffsetX, (Height - avatarSize) / 2 + 1 + OffsetY);
|
||||||
bmp.Dispose();
|
bmp.Dispose();
|
||||||
scaleImage.Dispose();
|
scaleImage.Dispose();
|
||||||
e.Graphics.SetHighQuality();
|
e.Graphics.SetHighQuality();
|
||||||
|
|
||||||
using (Pen pn = new Pen(BackColor, 2))
|
using (Pen pn = new Pen(BackColor, 4))
|
||||||
{
|
{
|
||||||
if (Shape == UIShape.Circle)
|
if (Shape == UIShape.Circle)
|
||||||
{
|
{
|
||||||
e.Graphics.DrawEllipse(pn, 1, 1, size, size);
|
e.Graphics.DrawEllipse(pn, (Width - avatarSize) / 2 + 1 + OffsetX, (Height - avatarSize) / 2 + 1 + OffsetY, size, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Shape == UIShape.Square)
|
if (Shape == UIShape.Square)
|
||||||
{
|
{
|
||||||
e.Graphics.DrawRoundRectangle(pn, 1, 1, size, size, 5);
|
e.Graphics.DrawRoundRectangle(pn, (Width - avatarSize) / 2 + 1 + OffsetX, (Height - avatarSize) / 2 + 1 + OffsetY, size, size, 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,6 +307,8 @@ namespace Sunny.UI
|
|||||||
SizeF sf = e.Graphics.MeasureString(Text, Font);
|
SizeF sf = e.Graphics.MeasureString(Text, Font);
|
||||||
e.Graphics.DrawString(Text, Font, foreColor, (Width - sf.Width) / 2.0f + OffsetX, (Height - sf.Height) / 2.0f + 1 + OffsetY);
|
e.Graphics.DrawString(Text, Font, foreColor, (Width - sf.Width) / 2.0f + OffsetX, (Height - sf.Height) / 2.0f + 1 + OffsetY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PaintAgain?.Invoke(this, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user