📄 popupwin.cs
字号:
[Bindable(true),Category("Design"),Description("Ligh Gradient color.")]
public Color GradientLight
{
get { return ColorFromString(gradientEnd); }
set { ColorStyle=PopupColorStyle.Custom; gradientEnd=ColorToString(value); }
}
/// <summary>
/// Get or set dark gradient color (Background in Mozilla)
/// </summary>
[Bindable(true),Category("Design"),Description("Dark gradient color (Background in Mozilla).")]
public Color GradientDark
{
get { return ColorFromString(gradientStart); }
set { ColorStyle=PopupColorStyle.Custom;popupBackground=cntBackground=gradientStart=ColorToString(value); }
}
/// <summary>
/// Get or set text color
/// </summary>
[Bindable(true),Category("Design"),Description("Text color.")]
public Color TextColor
{
get { return ColorFromString(textColor); }
set { ColorStyle=PopupColorStyle.Custom;textColor=ColorToString(value); }
}
/// <summary>
/// Get or set light shadow color
/// </summary>
[Bindable(true),Category("Design"),Description("Light shadow color.")]
public Color LightShadow
{
get { return ColorFromString(popupBorderLight); }
set { ColorStyle=PopupColorStyle.Custom;popupBorderLight=cntBorderLight=ColorToString(value); }
}
/// <summary>
/// Get or set dark shadow color
/// </summary>
[Bindable(true),Category("Design"),Description("Dark shadow color.")]
public Color DarkShadow
{
get { return ColorFromString(xButtonOver); }
set { ColorStyle=PopupColorStyle.Custom;xButtonOver=popupBorderDark=ColorToString(value); }
}
/// <summary>
/// Get or set shadow color
/// </summary>
[Bindable(true),Category("Design"),Description("Shadow color.")]
public Color Shadow
{
get { return ColorFromString(xButton); }
set { ColorStyle=PopupColorStyle.Custom;xButton=cntBorderDark=ColorToString(value); }
}
/// <summary>
/// Get or set popup window docking
/// </summary>
[Category("Layout"),Description("Popup window docking.")]
public PopupDocking DockMode
{
get { return popDock; }
set { popDock=value; }
}
/// <summary>
/// Get or set x offset
/// </summary>
[Category("Layout"),Description("X offset (from left or right)."),DefaultValue(15)]
public int OffsetX
{
get { return xOffset; }
set { xOffset=value; }
}
/// <summary>
/// Get or set y offset
/// </summary>
[Category("Layout"),Description("Y offset from bottom."),DefaultValue(15)]
public int OffsetY
{
get { return yOffset; }
set { yOffset=value; }
}
/// <summary>
/// Get or set how long will window be displayed
/// </summary>
[Bindable(true),Category("Behavior"),DefaultValue(500),
Description("How long will be window displayed in milliseconds(-1 for infinite).")]
public int HideAfter
{
get { return iHide; }
set { iHide=value; }
}
/// <summary>
/// Get or set how fast will showing of popup be
/// </summary>
[Bindable(true),Category("Behavior"),DefaultValue(20),
Description("Get or set how fast will showing of popup be.")]
public int PopupSpeed
{
get { return iSpeed; }
set { iSpeed=value; }
}
/// <summary>
/// Get or set delay before displaying popup control
/// </summary>
[Bindable(true),Category("Behavior"),DefaultValue(1000),
Description("Delay before displaying popup control.")]
public int ShowAfter
{
get { return startTime; }
set { startTime=value; }
}
/// <summary>
/// Automaticly show popup when page loads (after ShowAfter miliseconds).
/// </summary>
[Category("Behavior"),DefaultValue(true)]
[Description("Automaticly show popup when page loads (after ShowAfter miliseconds).")]
public bool AutoShow
{
get { return bAutoShow; }
set { bAutoShow=value; }
}
/// <summary>
/// Get or set wether user can move popup element
/// </summary>
[Category("Behavior"),DefaultValue(true)]
[Description("Allow user to move popup element.")]
public bool DragDrop
{
get { return bDragDrop; }
set { bDragDrop=value; }
}
/// <summary>
/// Get or set window size
/// </summary>
[Bindable(true),Category("Window"),Description("Opened window size.")]
public Size WindowSize
{
get { return winSize; }
set { winSize=value; }
}
/// <summary>
/// Get or set window scrollbars
/// </summary>
[Bindable(true),Category("Window"),Description("Display scrollbars in new window."),
DefaultValue(true)]
public bool WindowScroll
{
get { return winScroll; }
set { winScroll=value; }
}
/// <summary>
/// Generate link inside popup ?
/// </summary>
[Bindable(true),DefaultValue(true),
Category("Action"),Description("Generate link inside popup and enable action ?")]
public bool ShowLink
{
get { return bShowLink; }
set { bShowLink=value; }
}
#endregion
#region Methods
/// <summary>
/// Convert color to string (no color names !)
/// </summary>
/// <param name="color">Color</param>
/// <returns>String (without # prefix)</returns>
private string ColorToString(Color color)
{
return color.R.ToString("x").PadLeft(2,'0')+
color.G.ToString("x").PadLeft(2,'0')+color.B.ToString("x").PadLeft(2,'0');
}
/// <summary>
/// Convert string in RRGGBB format to Gdi+ color
/// </summary>
/// <param name="str">String to convert</param>
/// <returns>Gdi+ color</returns>
private Color ColorFromString(string str)
{
return ColorTranslator.FromHtml("#"+str);
}
/// <summary>
/// Replace {0}..{10} with colors
/// </summary>
/// <param name="html">Html source</param>
private string PutColors(string html)
{
return String.Format(html,popupBackground,popupBorderDark,popupBorderLight,
cntBorderDark,cntBorderLight,cntBackground,gradientStart,
gradientEnd,textColor,xButton,xButtonOver);
}
/// <summary>
/// Render this control to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void Render(HtmlTextWriter output)
{
string br=Page.Request.Browser.Browser;
string script=sScript,sps=spopStyle;
string acmd="";
switch(popAction)
{
case PopupAction.MessageWindow:
acmd=aCommands.Replace("[cmd]","javascript:[id]espopup_ShowWindow();");
script=script.Replace("[slink]","");
script=script.Replace("[sclose]","");
break;
case PopupAction.RaiseEvents:
acmd=aCommands.Replace("[cmd]","javascript:[id]espopup_ShowWindow();");
string scriptClick=(LinkClicked==null)?"":
(Page.GetPostBackClientEvent(this,"C")+"; return;");
string scriptClose=(PopupClosed==null)?"":
(Page.GetPostBackClientEvent(this,"X")+"; return;");
script=script.Replace("[slink]",scriptClick);
script=script.Replace("[sclose]",scriptClose);
break;
case PopupAction.OpenLink:
acmd=aCommands.Replace("[cmd]",sLink);
script=script.Replace("[slink]","");
script=script.Replace("[sclose]","");
if (sTarget!="") acmd+=" target=\""+sTarget+"\"";
break;
}
sps=sps.Replace("[gs]",gradientStart);
sps=sps.Replace("[ge]",gradientEnd);
sps=sps.Replace("[clr]",textColor);
script=script.Replace("[winstyle]",String.Format(
"width={0},height={1},scrollbars={2}",winSize.Width,
winSize.Height,(winScroll?"yes":"no")));
script=script.Replace("[hide]",iHide.ToString());
script=script.Replace("[stime]",startTime.ToString());
script=script.Replace("[id]",ClientID);
script=script.Replace("[ie]",(br=="IE"?"true":"false"));
script=script.Replace("[popup]",String.Format(sPopup,fullmsg,title,sps));
script=script.Replace("[autoshow]",bAutoShow.ToString().ToLower());
script=script.Replace("[speed]",iSpeed.ToString());
string divPos=String.Format("width:{0}; height:{1}; ",Width,Height);
string cntsI=String.Format(cntStyleI,Width.Value-6,Height.Value-24);
string cntsN=String.Format(cntStyleN,Width.Value-10,Height.Value-28);
string sDragDrop="";
if (bDragDrop)
sDragDrop=" onmousedown=\"return "+ClientID+"espopup_DragDrop(event);\" ";
if (popDock==PopupDocking.BottomLeft) divPos+="left:"; else divPos+="right:";
divPos+=string.Format("{0}px; bottom:{1}px;",xOffset,yOffset);
output.Write(script+String.Format("<div id=\"{0}\" "+
"style=\"display:none; {1} {2}\" onselectstart=\"return false;\" {4}>"+
"<div id=\"{3}\" style=\"cursor:default; display:none; {5}\">{6}</div>"+
"<div id=\"{7}\" onmousedown=\"event.cancelBubble=true;\" style=\"display:none; {8}\">"+
((bShowLink==true)?
"<a style=\"{9}\" {10} id=\"{11}\">{12}</a></div></div>":
"<span style=\"{9}\" id=\"{11}\">{12}</span></div></div>"),
ClientID,PutColors(divDesign),divPos,ClientID+"_header",sDragDrop,PutColors(hdrStyle).
Replace("[wid]",(Width.Value-6).ToString())+PutColors(aStyle),
"<span id=\""+ClientID+"titleEl\">"+title+"</span>"+PutColors(closeHtml).Replace("[id]",ClientID),ClientID+"_content",
PutColors(cntStyle)+((br!="Netscape"&&br!="Mozilla")?cntsI:cntsN),PutColors(aStyle),
acmd.Replace("[id]",ClientID),ClientID+"aCnt",msg));
}
/// <summary>
/// Generate html code to show in new window
/// </summary>
/// <param name="title">Title</param>
/// <param name="text">Text</param>
/// <returns>Html code for new window</returns>
internal string GetWinText(string title,string text)
{
string sps=spopStyle;
sps=sps.Replace("[gs]",gradientStart);
sps=sps.Replace("[ge]",gradientEnd);
sps=sps.Replace("[clr]",textColor);
return String.Format(sPopup,text.Replace("\\","\\\\").Replace("\"","\\\""),title,sps);
}
/// <summary>
/// Returns html code for designer
/// </summary>
internal string GetDesignCode()
{
string divPos=String.Format("width:{0}; height:{1}; ",
Width,Height);
string cntsI=String.Format(cntStyleI,Width.Value-6,Height.Value-24);
return String.Format("<div id=\"{0}\" "+
"style=\"{1} {2}; left:0px; top:0px; \">"+
"<div id=\"{3}\" style=\"{4}\">{5}</div>"+
"<div id=\"{6}\" style=\"{7}\">"+
"<a style=\"{8}\" {9}>{10}</a></div></div>",
ClientID,PutColors(divDesign),divPos,ClientID+"_header",PutColors(hdrStyle).
Replace("[wid]",(Width.Value-6).ToString())+
PutColors(aStyle),title+PutColors(closeHtml).Replace("[id]",ClientID),ClientID+"_content",
PutColors(cntStyle)+cntsI,PutColors(aStyle),aCommands.Replace("[id]",ClientID),msg);
}
#endregion
#region Events and Event handlers
/// <summary>
/// Raise event
/// </summary>
/// <param name="eventArgument">Closed or clicked on link ?</param>
public void RaisePostBackEvent(string eventArgument)
{
if (eventArgument=="C") LinkClicked(this,EventArgs.Empty);
if (eventArgument=="X") PopupClosed(this,EventArgs.Empty);
}
/// <summary>
/// User clicked on link on popup box
/// </summary>
[Category("Popup"),Description("User clicked on link on popup box.")]
public event EventHandler LinkClicked;
/// <summary>
/// User clicked on 'X' on popup box.
/// </summary>
[Category("Popup"),Description("User clicked on 'X' on popup box.")]
public event EventHandler PopupClosed;
#endregion
}
/// <summary>
/// Class for displaying PopupWin in designer
/// </summary>
public class PopupWinDesigner : ControlDesigner
{
#region Overriden methods
/// <summary>
/// Returns HTML code to show in designer
/// </summary>
public override string GetDesignTimeHtml()
{
try
{
return ((PopupWin)Component).GetDesignCode();
}
catch(Exception er)
{
return GetErrorDesignTimeHtml(er);
}
}
#endregion
}
/// <summary>
/// Predefined color style
/// </summary>
public enum PopupColorStyle
{
#region Members
/// <summary> Blue style (default) </summary>
Blue,
/// <summary> Red style </summary>
Red,
/// <summary> Green style </summary>
Green,
/// <summary> Violet style </summary>
Violet,
/// <summary> Custom style - defined by colors </summary>
Custom
#endregion
}
/// <summary>
/// Popup window docking
/// </summary>
public enum PopupDocking
{
#region Members
/// <summary> Control is docked to left and bottom </summary>
BottomLeft,
/// <summary> Control is docked to right and bottom </summary>
BottomRight
#endregion
}
/// <summary>
/// Action to do after user clicked on link
/// </summary>
public enum PopupAction
{
#region Members
/// <summary> Raise server events </summary>
RaiseEvents,
/// <summary> Open new browser window with text message </summary>
MessageWindow,
/// <summary> Open link or javascript script </summary>
OpenLink
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -