一个圆角Panel,基于四个裁剪的圆角图片,内部用Table布局
/// <summary>
/// 需要的数据如下:
/// 圆角图片,是要用圆角图片的四个角做为 圆角Panel 的四个角. 具有裁剪效果.
/// 上下图片,是用上下图片横向铺开来连接上两角和下两角.
/// 左右图片,是用左右图片竖向铺开来连接左两角和右两角.
/// 半径, 是指 圆角图片所属圆的半径. 也可以是 圆角图片边长的一半.
/// 背景色.
/// </summary>
[ToolboxData("<{0}:MyPanel runat=server></{0}:MyPanel>")]
public class MyPanel : Panel
{
public MyPanel()
{ }
public void Bind()
{
this.ChildControlsCreated = false;
this.EnsureChildControls();
}
public void Bind(string CircleImagUrl, string TopBottomImageUrl, string LeftRightImageUrl)
{
this.CircleImageUrl = CircleImagUrl;
this.TopBottomImageUrl = TopBottomImageUrl;
this.LeftRightImageUrl = LeftRightImageUrl;
Bind();
}
public void Bind(string CircleImagUrl, string TopBottomImageUrl, string LeftRightImageUrl, int CircleDiaii, Color BackColor)
{
this.CircleImageUrl = CircleImagUrl;
this.TopBottomImageUrl = TopBottomImageUrl;
this.LeftRightImageUrl = LeftRightImageUrl;
this.CircleDiaii = CircleDiaii;
this.BackColor = BackColor;
Bind();
}
/// <summary>
///
/// </summary>
/// <param name="CircleImagUrl"></param>
/// <param name="TopBottomImageUrl"></param>
/// <param name="LeftRightImageUrl"></param>
/// <param name="CircleDiaii"></param>
/// <param name="BackColor"></param>
[Obsolete("请用后期 Bind 方法")]
public MyPanel(string CircleImagUrl, string TopBottomImageUrl, string LeftRightImageUrl, int CircleDiaii, Color BackColor)
{
this.CircleImageUrl = CircleImagUrl;
this.TopBottomImageUrl = TopBottomImageUrl;
this.LeftRightImageUrl = LeftRightImageUrl;
this.CircleDiaii = CircleDiaii;
this.BackColor = BackColor;
}
public virtual string CircleImageUrl
{
get
{
return ViewState["CircleImageUrl"].GetString();
}
set
{
ViewState["CircleImageUrl"] = value;
}
}
public virtual string TopBottomImageUrl
{
get
{
return ViewState["TopBottomImageUrl"].GetString();
}
set
{
ViewState["TopBottomImageUrl"] = value;
}
}
public virtual string LeftRightImageUrl
{
get
{
return ViewState["LeftRightImageUrl"].GetString();
}
set
{
ViewState["LeftRightImageUrl"] = value;
}
}
public virtual int CircleDiaii
{
get
{
return ViewState["CircleDiaii"].GetInt();
}
set
{
ViewState["CircleDiaii"] = value;
}
}
public override void RenderBeginTag(HtmlTextWriter writer)
{
System.Drawing.Image map = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(this.CircleImageUrl.GetVirtualPathFull()));
if (this.BackColor.IsEmpty)
{
Bitmap m = new Bitmap(map);
this.BackColor = m.GetPixel(map.Width/2 - 1, map.Height/2 - 1);
}
if (this.CircleDiaii == 0)
{
this.CircleDiaii = Math.Min(map.Width, map.Height) / 2;
}
writer.Write(string.Format(@"<div style=""{5} white-space: nowrap;background-color:{0};{8}"" class=""{7}"">
<div style=""background: {0} url({3}) repeat-x scroll 0px 0px; white-space: nowrap;width: 100%;height:{1}px"">
<label style=""float: left; background: {0} url({2}) no-repeat scroll 0px 0px;width: {1}px; height: {1}px; font-size: 1px;""></label>
<label style=""float: right; background: {0} url({2}) no-repeat scroll -{6}px 0px;width: {1}px; height: {1}px; font-size: 1px;""></label>
</div>
<table style=""width: 100%;height:100%"" cellpadding=""0px"" cellspacing=""0px"">
<tr>
<td style=""width: {1}px; background: {0} url({4}) repeat-y scroll 0px 0px;""></td>
<td style=""word-wrap: break-word; word-break: break-all;background-color:{0};height:100%;"" valign=""top"">"
, this.BackColor.ToHexColorString()
, this.CircleDiaii.ToString()
, this.CircleImageUrl.GetUrlFull()
, this.TopBottomImageUrl.GetUrlFull()
, this.LeftRightImageUrl.GetUrlFull()
, this.Width.IsEmpty ? "" : "width:" + this.Width.ToString() + "px;"
, map.Width - CircleDiaii
, this.CssClass
, this.Attributes["style"]
));
}
public override void RenderEndTag(HtmlTextWriter writer)
{
System.Drawing.Image map = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(this.CircleImageUrl.GetVirtualPathFull()));
writer.Write(string.Format(@"</td>
<td style=""width: {1}px; background: {0} url({4}) repeat-y scroll -{6}px 0px;"">
</td>
</tr>
</table>
<div style=""background: {0} url({3}) repeat-x scroll 0px -{6}px; white-space: nowrap;width: 100%;height:{1}px"">
<label style=""float: left; background: {0} url({2}) no-repeat scroll 0px -{6}px;width: {1}px; height: {1}px; font-size: 1px;""></label>
<label style=""float: right; background: {0} url({2}) no-repeat scroll -{6}px -{6}px;width: {1}px; height: {1}px; font-size: 1px;""></label>
</div>
</div>"
, this.BackColor.ToHexColorString()
, this.CircleDiaii.ToString()
, this.CircleImageUrl.GetUrlFull()
, this.TopBottomImageUrl.GetUrlFull()
, this.LeftRightImageUrl.GetUrlFull()
, this.Width.ToString()
, map.Width - CircleDiaii
, this.Width.Value - CircleDiaii
));
}
/// 需要的数据如下:
/// 圆角图片,是要用圆角图片的四个角做为 圆角Panel 的四个角. 具有裁剪效果.
/// 上下图片,是用上下图片横向铺开来连接上两角和下两角.
/// 左右图片,是用左右图片竖向铺开来连接左两角和右两角.
/// 半径, 是指 圆角图片所属圆的半径. 也可以是 圆角图片边长的一半.
/// 背景色.
/// </summary>
[ToolboxData("<{0}:MyPanel runat=server></{0}:MyPanel>")]
public class MyPanel : Panel
{
public MyPanel()
{ }
public void Bind()
{
this.ChildControlsCreated = false;
this.EnsureChildControls();
}
public void Bind(string CircleImagUrl, string TopBottomImageUrl, string LeftRightImageUrl)
{
this.CircleImageUrl = CircleImagUrl;
this.TopBottomImageUrl = TopBottomImageUrl;
this.LeftRightImageUrl = LeftRightImageUrl;
Bind();
}
public void Bind(string CircleImagUrl, string TopBottomImageUrl, string LeftRightImageUrl, int CircleDiaii, Color BackColor)
{
this.CircleImageUrl = CircleImagUrl;
this.TopBottomImageUrl = TopBottomImageUrl;
this.LeftRightImageUrl = LeftRightImageUrl;
this.CircleDiaii = CircleDiaii;
this.BackColor = BackColor;
Bind();
}
/// <summary>
///
/// </summary>
/// <param name="CircleImagUrl"></param>
/// <param name="TopBottomImageUrl"></param>
/// <param name="LeftRightImageUrl"></param>
/// <param name="CircleDiaii"></param>
/// <param name="BackColor"></param>
[Obsolete("请用后期 Bind 方法")]
public MyPanel(string CircleImagUrl, string TopBottomImageUrl, string LeftRightImageUrl, int CircleDiaii, Color BackColor)
{
this.CircleImageUrl = CircleImagUrl;
this.TopBottomImageUrl = TopBottomImageUrl;
this.LeftRightImageUrl = LeftRightImageUrl;
this.CircleDiaii = CircleDiaii;
this.BackColor = BackColor;
}
public virtual string CircleImageUrl
{
get
{
return ViewState["CircleImageUrl"].GetString();
}
set
{
ViewState["CircleImageUrl"] = value;
}
}
public virtual string TopBottomImageUrl
{
get
{
return ViewState["TopBottomImageUrl"].GetString();
}
set
{
ViewState["TopBottomImageUrl"] = value;
}
}
public virtual string LeftRightImageUrl
{
get
{
return ViewState["LeftRightImageUrl"].GetString();
}
set
{
ViewState["LeftRightImageUrl"] = value;
}
}
public virtual int CircleDiaii
{
get
{
return ViewState["CircleDiaii"].GetInt();
}
set
{
ViewState["CircleDiaii"] = value;
}
}
public override void RenderBeginTag(HtmlTextWriter writer)
{
System.Drawing.Image map = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(this.CircleImageUrl.GetVirtualPathFull()));
if (this.BackColor.IsEmpty)
{
Bitmap m = new Bitmap(map);
this.BackColor = m.GetPixel(map.Width/2 - 1, map.Height/2 - 1);
}
if (this.CircleDiaii == 0)
{
this.CircleDiaii = Math.Min(map.Width, map.Height) / 2;
}
writer.Write(string.Format(@"<div style=""{5} white-space: nowrap;background-color:{0};{8}"" class=""{7}"">
<div style=""background: {0} url({3}) repeat-x scroll 0px 0px; white-space: nowrap;width: 100%;height:{1}px"">
<label style=""float: left; background: {0} url({2}) no-repeat scroll 0px 0px;width: {1}px; height: {1}px; font-size: 1px;""></label>
<label style=""float: right; background: {0} url({2}) no-repeat scroll -{6}px 0px;width: {1}px; height: {1}px; font-size: 1px;""></label>
</div>
<table style=""width: 100%;height:100%"" cellpadding=""0px"" cellspacing=""0px"">
<tr>
<td style=""width: {1}px; background: {0} url({4}) repeat-y scroll 0px 0px;""></td>
<td style=""word-wrap: break-word; word-break: break-all;background-color:{0};height:100%;"" valign=""top"">"
, this.BackColor.ToHexColorString()
, this.CircleDiaii.ToString()
, this.CircleImageUrl.GetUrlFull()
, this.TopBottomImageUrl.GetUrlFull()
, this.LeftRightImageUrl.GetUrlFull()
, this.Width.IsEmpty ? "" : "width:" + this.Width.ToString() + "px;"
, map.Width - CircleDiaii
, this.CssClass
, this.Attributes["style"]
));
}
public override void RenderEndTag(HtmlTextWriter writer)
{
System.Drawing.Image map = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(this.CircleImageUrl.GetVirtualPathFull()));
writer.Write(string.Format(@"</td>
<td style=""width: {1}px; background: {0} url({4}) repeat-y scroll -{6}px 0px;"">
</td>
</tr>
</table>
<div style=""background: {0} url({3}) repeat-x scroll 0px -{6}px; white-space: nowrap;width: 100%;height:{1}px"">
<label style=""float: left; background: {0} url({2}) no-repeat scroll 0px -{6}px;width: {1}px; height: {1}px; font-size: 1px;""></label>
<label style=""float: right; background: {0} url({2}) no-repeat scroll -{6}px -{6}px;width: {1}px; height: {1}px; font-size: 1px;""></label>
</div>
</div>"
, this.BackColor.ToHexColorString()
, this.CircleDiaii.ToString()
, this.CircleImageUrl.GetUrlFull()
, this.TopBottomImageUrl.GetUrlFull()
, this.LeftRightImageUrl.GetUrlFull()
, this.Width.ToString()
, map.Width - CircleDiaii
, this.Width.Value - CircleDiaii
));
}
作者:NewSea 出处:http://newsea.cnblogs.com/
QQ,MSN:iamnewsea@hotmail.com 如无特别标记说明,均为NewSea原创,版权私有,翻载必纠。欢迎交流,转载,但要在页面明显位置给出原文连接。谢谢。 |