📄 wroxtoolbardesigner.cs
字号:
using System;
using System.IO;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
namespace WroxDesign.Design
{
public class WroxToolBarDesigner : ControlDesigner
{
public override DesignerVerbCollection Verbs
{
get
{
DesignerVerb[] verbs = new DesignerVerb[] {
new DesignerVerb("Wrox Format...", new System.EventHandler(OnWroxFormat)),
new DesignerVerb("Edit Buttons...", new System.EventHandler(OnEditButtons))};
return new DesignerVerbCollection(verbs);
}
}
public void OnWroxFormat(object sender, EventArgs e)
{
WroxToolBar wb = Component as WroxToolBar;
//Apply a formatting style.
wb.BackColor = Color.LightSkyBlue;
wb.BorderColor = Color.Black;
wb.Font.Name = "Tahoma";
wb.Font.Size = new FontUnit("8pt");
wb.ForeColor = Color.White;
wb.BorderStyle = BorderStyle.Solid;
wb.BorderWidth = new Unit(1, UnitType.Point);
//Notify the environment we have changed the component.
RaiseComponentChanged(null, null, null);
UpdateDesignTimeHtml();
}
public void OnEditButtons(object sender, EventArgs e)
{
WroxToolBar wb = Component as WroxToolBar;
WroxToolBarButtonsForm form = new WroxToolBarButtonsForm(wb.Buttons);
if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
wb.Buttons = form.Buttons;
RaiseComponentChanged(null, null, null);
UpdateDesignTimeHtml();
}
}
private void TransferAttributes(WebControl source, WebControl destination)
{
destination.CopyBaseAttributes(source);
destination.Style.Remove("POSITION");
destination.Style.Remove("LEFT");
destination.Style.Remove("TOP");
destination.Font.CopyFrom(source.Font);
destination.BackColor = source.BackColor;
destination.BorderColor = source.BorderColor;
destination.ForeColor = source.ForeColor;
}
public override string GetPersistInnerHtml()
{
StringWriter text = new StringWriter();
HtmlTextWriter writer = new HtmlTextWriter(text);
WroxToolBar tbr = Component as WroxToolBar;
writer.WriteFullBeginTag("buttons");
foreach (WroxButton btn in tbr.Buttons)
{
//We won't persist other attributes, which will be copied
//from the toolbar settings.
writer.WriteBeginTag("button");
writer.WriteAttribute("ID", btn.ID);
writer.WriteAttribute("Text", btn.Text);
writer.WriteAttribute("ImageUrl", btn.ImageUrl);
writer.Write(" />");
}
writer.WriteEndTag("buttons");
return text.ToString();
}
public override string GetDesignTimeHtml()
{
try
{
WroxToolBar wb = (WroxToolBar) base.Component;
if (wb.Buttons.Count == 0)
return GetEmptyDesignTimeHtml();
//Returns just the same runtime layout.
return base.GetDesignTimeHtml();
}
catch (Exception e)
{
return GetErrorDesignTimeHtml(e);
}
}
protected override string GetEmptyDesignTimeHtml()
{
//Render design time warning if there's nothing to display.
string text= "Please add WroxButtons to the toolbar.";
return CreatePlaceHolderDesignTimeHtml(text);
}
protected override string GetErrorDesignTimeHtml(Exception e)
{
string text = string.Format("{0}{1}{2}{3}",
"There was an error and the control can't be displayed.",
"<BR>", "Exception: ", e.Message);
return CreatePlaceHolderDesignTimeHtml(text);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -