📄 toolbardropdownlist.cs
字号:
}
color = BackColor;
if (!color.IsEmpty)
{
style += "background-color:" + ColorTranslator.ToHtml(color) + ";";
}
#if false
color = BorderColor;
if (!color.IsEmpty)
{
style += "border-color:" + ColorTranslator.ToHtml(color) + ";";
}
BorderStyle bs = BorderStyle;
Unit unit = BorderWidth;
if (bs != BorderStyle.NotSet)
{
style += "border-style:" + Enum.Format(typeof(BorderStyle), bs, "G") + ";";
}
if (!unit.IsEmpty)
{
style += "border-width:" + unit.ToString(CultureInfo.InvariantCulture) + ";";
if ((bs == BorderStyle.NotSet) && (unit.Value != 0.0))
{
style += "border-style:solid;";
}
}
#endif
FontInfo font = Font;
string[] names = font.Names;
if (names.Length > 0)
{
style += "font-family:";
for (int i = 0; i < names.Length; i++)
{
if (i > 0)
{
style += ",";
}
style += names[i];
}
style += ";";
}
FontUnit fu = font.Size;
if (!fu.IsEmpty)
{
style += "font-size:" + fu.ToString(CultureInfo.InvariantCulture) + ";";
}
if (font.Bold)
{
style += "font-weight:bold;";
}
if (font.Italic)
{
style += "font-style:italic;";
}
bool underline = font.Underline;
bool overline = font.Overline;
bool strikeout = font.Strikeout;
string td = String.Empty;
if (underline)
td = "underline";
if (overline)
td += " overline";
if (strikeout)
td += " line-through";
if (td.Length > 0)
style += "text-decoration:" + td + ";";
#if false
unit = Height;
if (!unit.IsEmpty)
{
style += "height:" + unit.ToString(CultureInfo.InvariantCulture) + ";";
}
#endif
Unit unit = Width;
if (!unit.IsEmpty)
{
style += "width:" + unit.ToString(CultureInfo.InvariantCulture) + ";";
}
style += Style.CssText;
writer.WriteAttribute("style", style);
if (Enabled)
{
string script = "if ((event.propertyName!=null)&&(event.propertyName.toLowerCase()=='selectedindex')){window.document.all." + HelperID + ".value=options[selectedIndex].value;";
Toolbar parent = ParentToolbar;
if (AutoPostBack && (parent != null))
{
script += "if (" + parent.ClientID + ".getAttribute('_submitting') == null){" + parent.ClientID + ".setAttribute('_submitting', 'true');window.setTimeout('" + parent.Page.GetPostBackEventReference(_List).Replace("'", "\\'") + "', 0, 'JScript');}";
}
script += "}";
writer.WriteAttribute("onpropertychange", script);
}
}
/// <summary>
/// Renders the item's contents
/// </summary>
/// <param name="writer">The HtmlTextWriter object that receives the content.</param>
protected override void UpLevelContent(HtmlTextWriter writer)
{
ResolveSelectedIndex();
writer.WriteLine();
writer.Indent++;
foreach (ListItem item in _List.Items)
{
writer.WriteBeginTag("option");
if (item.Selected)
{
writer.WriteAttribute("selected", "selected", false);
}
writer.WriteAttribute("value", item.Value, true);
writer.Write(HtmlTextWriter.TagRightChar);
HttpUtility.HtmlEncode(item.Text, writer);
writer.WriteEndTag("option");
writer.WriteLine();
}
writer.Indent--;
}
/// <summary>
/// Renders the item's contents
/// </summary>
/// <param name="inlineWriter">The HtmlTextWriter object that receives the content.</param>
protected override void DownLevelContent(HtmlTextWriter inlineWriter)
{
HtmlTextWriter writer = (HtmlTextWriter)inlineWriter.InnerWriter;
ResolveSelectedIndex();
Toolbar parent = ParentToolbar;
if (Enabled && AutoPostBack && (parent != null) && (parent.Page != null))
{
writer.AddAttribute(HtmlTextWriterAttribute.Onchange, parent.Page.GetPostBackEventReference(_List));
}
if (Font.Names.Length == 0)
{
string font = CurrentStyle["font"];
string fontFamily = CurrentStyle["font-family"];
string fontSize = CurrentStyle["font-size"];
string fontWeight = CurrentStyle["font-weight"];
string fontStyle = CurrentStyle["font-style"];
if (font != null)
{
_List.Style["font"] = font;
}
if (fontFamily != null)
{
_List.Style["font-family"] = fontFamily;
}
if (fontSize != null)
{
_List.Style["font-size"] = fontSize;
}
if (fontWeight != null)
{
_List.Style["font-weight"] = fontWeight;
}
if (fontStyle != null)
{
_List.Style["font-style"] = fontStyle;
}
}
_List.RenderControl(writer);
}
/// <summary>
/// Renders the item's contents
/// </summary>
/// <param name="writer">The HtmlTextWriter object that receives the content.</param>
protected override void DesignerContent(HtmlTextWriter writer)
{
ResolveSelectedIndex();
bool empty = (_List.Items.Count == 0);
if (empty)
{
ListItem msg = new ListItem();
msg.Text = Util.GetStringResource("Unbound");
_List.Items.Add(msg);
}
bool UndoFont = false;
bool UndoFontFamily = false;
bool UndoFontSize = false;
bool UndoFontWeight = false;
bool UndoFontStyle = false;
if (Font.Names.Length == 0)
{
string font = CurrentStyle["font"];
string fontFamily = CurrentStyle["font-family"];
string fontSize = CurrentStyle["font-size"];
string fontWeight = CurrentStyle["font-weight"];
string fontStyle = CurrentStyle["font-style"];
if ((font != null) && (_List.Style["font"] == null))
{
_List.Style["font"] = font;
UndoFont = true;
}
if ((fontFamily != null) && (_List.Style["font-family"] == null))
{
_List.Style["font-family"] = fontFamily;
UndoFontFamily = true;
}
if ((fontSize != null) && (_List.Style["font-size"] == null))
{
_List.Style["font-size"] = fontSize;
UndoFontSize = true;
}
if ((fontWeight != null) && (_List.Style["font-weight"] == null))
{
_List.Style["font-weight"] = fontWeight;
UndoFontWeight = true;
}
if ((fontStyle != null) && (_List.Style["font-style"] == null))
{
_List.Style["font-style"] = fontStyle;
UndoFontStyle = true;
}
}
_List.RenderControl(writer);
if (UndoFont)
{
_List.Style.Remove("font");
}
if (UndoFontFamily)
{
_List.Style.Remove("font-family");
}
if (UndoFontSize)
{
_List.Style.Remove("font-size");
}
if (UndoFontWeight)
{
_List.Style.Remove("font-weight");
}
if (UndoFontStyle)
{
_List.Style.Remove("font-style");
}
if (empty)
{
_List.Items.Clear();
}
}
/// <summary>
/// Loads the item's previously saved view state.
/// </summary>
/// <param name="savedState">An Object that contains the saved view state values for the item.</param>
protected override void LoadViewState(object savedState)
{
if (savedState != null)
{
object[] state = (object[])savedState;
base.LoadViewState(state[0]);
// Restore state of items
if (state.Length > 1)
{
_List.LoadVS(state[1]);
}
}
}
/// <summary>
/// Saves the changes to the item's view state to an object.
/// </summary>
/// <returns>The object that contains the view state changes.</returns>
protected override object SaveViewState()
{
object baseState = base.SaveViewState();
object list = _List.SaveVS();
if (list != null)
{
return new object[2] { baseState, list };
}
else if (baseState != null)
{
return new object[1] { baseState };
}
return null;
}
/// <summary>
/// Instructs the control to track changes to its view state.
/// </summary>
protected override void TrackViewState()
{
base.TrackViewState();
_IsTrackingVS = true;
_List.TrackVS();
}
}
/// <summary>
/// Internal DropDownList class to give us access to certain methods
/// </summary>
internal class InternalDropDownList : DropDownList
{
/// <summary>
/// Internal access to ViewState
/// </summary>
internal StateBag VS
{
get { return ViewState; }
}
/// <summary>
/// TrackViewState
/// </summary>
internal void TrackVS()
{
TrackViewState();
}
/// <summary>
/// SaveViewState
/// </summary>
/// <returns></returns>
internal object SaveVS()
{
return SaveViewState();
}
/// <summary>
/// LoadViewState
/// </summary>
/// <param name="state">State object</param>
internal void LoadVS(object state)
{
LoadViewState(state);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -