关于仿照QQ 和 MSN的网页谈出窗口控件值得拿来学习!
2006-03-15 17:48
459 查看
using System;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
namespace EeekSoft.Web
{
/// <summary>
/// Popup window anchor control
/// Popup window 瞄定控件
/// </summary>
[DefaultProperty("PopupToShow"), ToolboxData("<{0}:PopupWinAnchor runat=server></{0}:PopupWinAnchor>")]
[Designer(typeof(AnchorDesigner))]
public class PopupWinAnchor : System.Web.UI.WebControls.WebControl
{
#region Variables:变量
string controlId,controlLink,jsEvent;
string snMsg,snText,snTitle;
bool bChangeText=false;
#endregion
#region Constructor 构造器
/// <summary>
/// Create control创建控件
/// </summary>
public PopupWinAnchor()
{
jsEvent="onclick";
bChangeText=false;
}
#endregion
#region Properties 属性
/// <summary>
/// Should texts on PopupWin be replaced with new texts ?
/// 该文本在PopupWin控件被替换的文本
/// </summary>
[Bindable(true),Category("PopupWin"),DefaultValue(false)]
[Description("Should texts on PopupWin be replaced with new texts ?")]
public bool ChangeTexts
{
get { return bChangeText; }
set { bChangeText=value; }
}
/// <summary>
/// New message text
/// 新的消息文本
/// </summary>
[Bindable(true),Category("PopupWin"),DefaultValue("")]
[Description("New message text")]
public string NewMessage
{
get { return snMsg; }
set { snMsg=value; }
}
/// <summary>
/// New popup title text
/// 新的popup标题
/// </summary>
[Bindable(true),Category("PopupWin"),DefaultValue("")]
[Description("New popup title text")]
public string NewTitle
{
get { return snTitle; }
set { snTitle=value; }
}
/// <summary>
/// New text to show in opened window
/// 显示在新打开window中文本内容
/// </summary>
[Bindable(true),Category("PopupWin"),DefaultValue("")]
[Description("New text to show in opened window")]
public string NewText
{
get { return snText; }
set { snText=value; }
}
/// <summary>
/// JavaScript event to handle
/// JavaScript事件处理方式
/// </summary>
[Bindable(true),Category("Anchor"),DefaultValue("onclick")]
[Editor(typeof(JavaScriptEventEditor),typeof(UITypeEditor))]
[Description("JavaScript event to handle")]
public string HandledEvent
{
get { return jsEvent; }
set { jsEvent=value; }
}
4000
/// <summary>
/// Popup control to show when event occurs
/// 当事件发生时Popup控件显示
/// </summary>
[Bindable(true),Category("Anchor"),DefaultValue("")]
[Editor(typeof(PopupControlsEditor), typeof(UITypeEditor))]
[Description("Popup control to show when event occurs")]
public string PopupToShow
{
get { return controlId; }
set { controlId=value; }
}
/// <summary>
/// Contol which event will cause the popup to show
/// 哪个事件将使popup显示出来
/// </summary>
[Bindable(true),Category("Anchor"),DefaultValue("")]
[Editor(typeof(AllControlsEditor), typeof(UITypeEditor))]
[Description("Control ")]
public string LinkedControl
{
get { return controlLink; }
set { controlLink=value; }
}
#endregion
#region Methods方法
/// <summary>
/// Render script for displaying popup control
/// 使popup控件展开script
/// </summary>
/// <param name="output">The HTML writer to write out to</param>
protected override void Render(HtmlTextWriter output)
{
output.Write(@"
<script type=""text/javascript"">
//<![CDATA[
var "+ID+@"oldOnLoad=window.onload;
window.onload="+ID+@"espopup_anchorInit;
function "+ID+@"espopup_anchorInit()
{
if ("+ID+@"oldOnLoad!=null) "+ID+@"oldOnLoad();
document.getElementById('"+controlLink+@"')."+jsEvent+@"="+
ID+@"espopup_anchorEvent;
}
function "+ID+@"espopup_anchorEvent()
{
");
if (bChangeText)
{
Control ct=Page.FindControl(controlId);
if (ct!=null)
{
output.Write(controlId+"nText=/""+
((PopupWin)ct).GetWinText(snTitle,snText)+"/";/n");
}
output.Write(controlId+"nMsg=/""+snMsg+"/";/n");
output.Write(controlId+"nTitle=/""+snTitle+"/";/n");
output.Write(controlId+"bChangeTexts=true;/n");
}
else
{
output.Write(controlId+"bChangeTexts=false;/n");
}
output.Write("/n"+controlId+@"espopup_ShowPopup('"+ID+@"');
}
//]]>
</script>");
}
#endregion
}
/// <summary>
/// Class for displaying PopupWin in designer
/// 在设计器使用PopupWin的类
/// </summary>
public class AnchorDesigner : ControlDesigner
{
#region Overriden methods
/// <summary>
/// Returns HTML code to show in designer
/// 返回显示在设计器的 HTML代码
/// </summary>
public override string GetDesignTimeHtml()
{
return "<div style=/"padding:2px; background-color: ButtonFace;color:ButtonText; "+
"border-style:outset; border-width:1px; font: 75% 'Microsoft Sans Serif';/"><b>"+
"PopupWinAnchor</b> - "+((Control)Component).ID+"</div>";
}
#endregion
}
/// <summary>
/// Editor for selecting JavaScript event
/// 编辑选择JavaScript的事件
/// </summary>
public class JavaScriptEventEditor : UITypeEditor
{
#region Variables变量
private System.Windows.Forms.Design.IWindowsFormsEditorService edSvc=null;
private System.Windows.Forms.ListBox lb;
#endregion
#region Methods方法
/// <summary>
/// Overrides the method used to provide basic behaviour for selecting editor.
/// Shows our custom control for editing the value.
/// 忽略使用的方法为选择提供基本的行为编辑。
/// 显示我们的习惯控制的编辑方式。
/// </summary>
/// <param name="context">The context of the editing control组件的上下文信息</param>
/// <param name="provider">A valid service provider服务提供的机制</param>
/// <param name="value">The current value of the object to edit编辑对象的通用值</param>
/// <returns>The new value of the object对象的新值</returns>
public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider,object value)
{
if (context!=null&&context.Instance!=null&&provider!=null)
{
edSvc=(System.Windows.Forms.Design.IWindowsFormsEditorService)
provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));
if (edSvc!=null)
{
lb=new System.Windows.Forms.ListBox();
lb.BorderStyle=System.Windows.Forms.BorderStyle.None;
lb.SelectedIndexChanged+=new EventHandler(lb_SelectedIndexChanged);
lb.Items.Add("onclick");
lb.Items.Add("ondblclick");
lb.Items.Add("onmouseover");
lb.Items.Add("onfocus");
lb.Items.Add("oncontextmenu");
edSvc.DropDownControl(lb);
if (lb.SelectedIndex==-1) return value;
return lb.SelectedItem;
}
}
return value;
}
/// <summary>
/// Choose editor type
/// 选择编辑类别
/// </summary>
/// <param name="context">The context of the editing control编辑组件的上下文信息</param>
/// <returns>Returns <c>UITypeEditorEditStyle.DropDown编辑样式</c></returns>
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
/// <summary>
/// Close the dropdowncontrol when the user has selected a value
/// 当选择值时关闭dropdowncontrol控件
/// </summary>
private void lb_SelectedIndexChanged(object sender, EventArgs e)
{
if (edSvc != null)
{
edSvc.CloseDropDown();
}
}
#endregion
}
/// <summary>
/// Editor for selecting controls from Asp.Net page
/// 从Asp.Net页面文件里面选择编辑器
/// </summary>
public abstract class ControlsEditor : UITypeEditor
{
#region Variables变量
private System.Windows.Forms.Design.IWindowsFormsEditorService edSvc=null;
private System.Windows.Forms.ListBox lb;
private Type typeShow;
#endregion
#region Constructor构造
/// <summary>
/// onstructor - show specified types
/// 构造--显示特殊类型
/// </summary>
/// <param name="show">Type descriptor类型描述符</param>
public ControlsEditor(Type show)
{
typeShow=show;
}
#endregion
#region Methods
/// <summary>
/// Overrides the method used to provide basic behaviour for selecting editor.
/// Shows our custom control for editing the value.
/// 忽略使用的方法为选择提供基本的行为编辑。
/// 显示我们的习惯控制的编辑方式。
/// </summary>
/// <param name="context">The context of the editing control编辑控件的上下文信息</param>
/// <param name="provider">A valid service provider 一个有效的服务提供者</param>
/// <param name="value">The current value of the object to edit编辑对象的当前值</param>
/// <returns>The new value of the object返回对象的值</returns>
public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider,object value)
{
if (context!=null&&context.Instance!=null&&provider!=null)
{
edSvc=(System.Windows.Forms.Design.IWindowsFormsEditorService)
provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));
if (edSvc!=null)
{
lb=new System.Windows.Forms.ListBox();
lb.BorderStyle=System.Windows.Forms.BorderStyle.None;
lb.SelectedIndexChanged+=new EventHandler(lb_SelectedIndexChanged);
foreach(Control ctrl in ((Control)context.Instance).Page.Controls)
{
if (ctrl.GetType().IsSubclassOf(typeShow)||
ctrl.GetType().FullName==typeShow.FullName) lb.Items.Add(ctrl.ID);
}
edSvc.DropDownControl(lb);
if (lb.SelectedIndex==-1) return value;
return lb.SelectedItem;
}
}
return value;
}
/// <summary>
/// Choose editor type
/// 选择编辑类别
/// </summary>
/// <param name="context">The context of the editing control编辑控件的上下文信息</param>
/// <returns>Returns <c>UITypeEditorEditStyle.DropDown控件样式</c></returns>
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
/// <summary>
/// Close the dropdowncontrol when the user has selected a value
/// </summary>
private void lb_SelectedIndexChanged(object sender, EventArgs e)
{
if (edSvc != null)
{
edSvc.CloseDropDown();
}
}
#endregion
}
/// <summary>
/// Editor for selecting all Asp.Net controls
/// </summary>
public class AllControlsEditor : ControlsEditor
{
#region Members
/// <summary>
/// Invoke base constructor 调用基类构造器
/// </summary>
public AllControlsEditor() : base(typeof(Control)) {}
#endregion
}
/// <summary>
/// Editor for selecting PopupWin controls
/// </summary>
public class PopupControlsEditor : ControlsEditor
{
#region Members
/// <summary>
/// Invoke base constructor
/// </summary>
public PopupControlsEditor() : base(typeof(PopupWin)) {}
#endregion
}
}
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
namespace EeekSoft.Web
{
/// <summary>
/// Popup window anchor control
/// Popup window 瞄定控件
/// </summary>
[DefaultProperty("PopupToShow"), ToolboxData("<{0}:PopupWinAnchor runat=server></{0}:PopupWinAnchor>")]
[Designer(typeof(AnchorDesigner))]
public class PopupWinAnchor : System.Web.UI.WebControls.WebControl
{
#region Variables:变量
string controlId,controlLink,jsEvent;
string snMsg,snText,snTitle;
bool bChangeText=false;
#endregion
#region Constructor 构造器
/// <summary>
/// Create control创建控件
/// </summary>
public PopupWinAnchor()
{
jsEvent="onclick";
bChangeText=false;
}
#endregion
#region Properties 属性
/// <summary>
/// Should texts on PopupWin be replaced with new texts ?
/// 该文本在PopupWin控件被替换的文本
/// </summary>
[Bindable(true),Category("PopupWin"),DefaultValue(false)]
[Description("Should texts on PopupWin be replaced with new texts ?")]
public bool ChangeTexts
{
get { return bChangeText; }
set { bChangeText=value; }
}
/// <summary>
/// New message text
/// 新的消息文本
/// </summary>
[Bindable(true),Category("PopupWin"),DefaultValue("")]
[Description("New message text")]
public string NewMessage
{
get { return snMsg; }
set { snMsg=value; }
}
/// <summary>
/// New popup title text
/// 新的popup标题
/// </summary>
[Bindable(true),Category("PopupWin"),DefaultValue("")]
[Description("New popup title text")]
public string NewTitle
{
get { return snTitle; }
set { snTitle=value; }
}
/// <summary>
/// New text to show in opened window
/// 显示在新打开window中文本内容
/// </summary>
[Bindable(true),Category("PopupWin"),DefaultValue("")]
[Description("New text to show in opened window")]
public string NewText
{
get { return snText; }
set { snText=value; }
}
/// <summary>
/// JavaScript event to handle
/// JavaScript事件处理方式
/// </summary>
[Bindable(true),Category("Anchor"),DefaultValue("onclick")]
[Editor(typeof(JavaScriptEventEditor),typeof(UITypeEditor))]
[Description("JavaScript event to handle")]
public string HandledEvent
{
get { return jsEvent; }
set { jsEvent=value; }
}
4000
/// <summary>
/// Popup control to show when event occurs
/// 当事件发生时Popup控件显示
/// </summary>
[Bindable(true),Category("Anchor"),DefaultValue("")]
[Editor(typeof(PopupControlsEditor), typeof(UITypeEditor))]
[Description("Popup control to show when event occurs")]
public string PopupToShow
{
get { return controlId; }
set { controlId=value; }
}
/// <summary>
/// Contol which event will cause the popup to show
/// 哪个事件将使popup显示出来
/// </summary>
[Bindable(true),Category("Anchor"),DefaultValue("")]
[Editor(typeof(AllControlsEditor), typeof(UITypeEditor))]
[Description("Control ")]
public string LinkedControl
{
get { return controlLink; }
set { controlLink=value; }
}
#endregion
#region Methods方法
/// <summary>
/// Render script for displaying popup control
/// 使popup控件展开script
/// </summary>
/// <param name="output">The HTML writer to write out to</param>
protected override void Render(HtmlTextWriter output)
{
output.Write(@"
<script type=""text/javascript"">
//<![CDATA[
var "+ID+@"oldOnLoad=window.onload;
window.onload="+ID+@"espopup_anchorInit;
function "+ID+@"espopup_anchorInit()
{
if ("+ID+@"oldOnLoad!=null) "+ID+@"oldOnLoad();
document.getElementById('"+controlLink+@"')."+jsEvent+@"="+
ID+@"espopup_anchorEvent;
}
function "+ID+@"espopup_anchorEvent()
{
");
if (bChangeText)
{
Control ct=Page.FindControl(controlId);
if (ct!=null)
{
output.Write(controlId+"nText=/""+
((PopupWin)ct).GetWinText(snTitle,snText)+"/";/n");
}
output.Write(controlId+"nMsg=/""+snMsg+"/";/n");
output.Write(controlId+"nTitle=/""+snTitle+"/";/n");
output.Write(controlId+"bChangeTexts=true;/n");
}
else
{
output.Write(controlId+"bChangeTexts=false;/n");
}
output.Write("/n"+controlId+@"espopup_ShowPopup('"+ID+@"');
}
//]]>
</script>");
}
#endregion
}
/// <summary>
/// Class for displaying PopupWin in designer
/// 在设计器使用PopupWin的类
/// </summary>
public class AnchorDesigner : ControlDesigner
{
#region Overriden methods
/// <summary>
/// Returns HTML code to show in designer
/// 返回显示在设计器的 HTML代码
/// </summary>
public override string GetDesignTimeHtml()
{
return "<div style=/"padding:2px; background-color: ButtonFace;color:ButtonText; "+
"border-style:outset; border-width:1px; font: 75% 'Microsoft Sans Serif';/"><b>"+
"PopupWinAnchor</b> - "+((Control)Component).ID+"</div>";
}
#endregion
}
/// <summary>
/// Editor for selecting JavaScript event
/// 编辑选择JavaScript的事件
/// </summary>
public class JavaScriptEventEditor : UITypeEditor
{
#region Variables变量
private System.Windows.Forms.Design.IWindowsFormsEditorService edSvc=null;
private System.Windows.Forms.ListBox lb;
#endregion
#region Methods方法
/// <summary>
/// Overrides the method used to provide basic behaviour for selecting editor.
/// Shows our custom control for editing the value.
/// 忽略使用的方法为选择提供基本的行为编辑。
/// 显示我们的习惯控制的编辑方式。
/// </summary>
/// <param name="context">The context of the editing control组件的上下文信息</param>
/// <param name="provider">A valid service provider服务提供的机制</param>
/// <param name="value">The current value of the object to edit编辑对象的通用值</param>
/// <returns>The new value of the object对象的新值</returns>
public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider,object value)
{
if (context!=null&&context.Instance!=null&&provider!=null)
{
edSvc=(System.Windows.Forms.Design.IWindowsFormsEditorService)
provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));
if (edSvc!=null)
{
lb=new System.Windows.Forms.ListBox();
lb.BorderStyle=System.Windows.Forms.BorderStyle.None;
lb.SelectedIndexChanged+=new EventHandler(lb_SelectedIndexChanged);
lb.Items.Add("onclick");
lb.Items.Add("ondblclick");
lb.Items.Add("onmouseover");
lb.Items.Add("onfocus");
lb.Items.Add("oncontextmenu");
edSvc.DropDownControl(lb);
if (lb.SelectedIndex==-1) return value;
return lb.SelectedItem;
}
}
return value;
}
/// <summary>
/// Choose editor type
/// 选择编辑类别
/// </summary>
/// <param name="context">The context of the editing control编辑组件的上下文信息</param>
/// <returns>Returns <c>UITypeEditorEditStyle.DropDown编辑样式</c></returns>
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
/// <summary>
/// Close the dropdowncontrol when the user has selected a value
/// 当选择值时关闭dropdowncontrol控件
/// </summary>
private void lb_SelectedIndexChanged(object sender, EventArgs e)
{
if (edSvc != null)
{
edSvc.CloseDropDown();
}
}
#endregion
}
/// <summary>
/// Editor for selecting controls from Asp.Net page
/// 从Asp.Net页面文件里面选择编辑器
/// </summary>
public abstract class ControlsEditor : UITypeEditor
{
#region Variables变量
private System.Windows.Forms.Design.IWindowsFormsEditorService edSvc=null;
private System.Windows.Forms.ListBox lb;
private Type typeShow;
#endregion
#region Constructor构造
/// <summary>
/// onstructor - show specified types
/// 构造--显示特殊类型
/// </summary>
/// <param name="show">Type descriptor类型描述符</param>
public ControlsEditor(Type show)
{
typeShow=show;
}
#endregion
#region Methods
/// <summary>
/// Overrides the method used to provide basic behaviour for selecting editor.
/// Shows our custom control for editing the value.
/// 忽略使用的方法为选择提供基本的行为编辑。
/// 显示我们的习惯控制的编辑方式。
/// </summary>
/// <param name="context">The context of the editing control编辑控件的上下文信息</param>
/// <param name="provider">A valid service provider 一个有效的服务提供者</param>
/// <param name="value">The current value of the object to edit编辑对象的当前值</param>
/// <returns>The new value of the object返回对象的值</returns>
public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider,object value)
{
if (context!=null&&context.Instance!=null&&provider!=null)
{
edSvc=(System.Windows.Forms.Design.IWindowsFormsEditorService)
provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));
if (edSvc!=null)
{
lb=new System.Windows.Forms.ListBox();
lb.BorderStyle=System.Windows.Forms.BorderStyle.None;
lb.SelectedIndexChanged+=new EventHandler(lb_SelectedIndexChanged);
foreach(Control ctrl in ((Control)context.Instance).Page.Controls)
{
if (ctrl.GetType().IsSubclassOf(typeShow)||
ctrl.GetType().FullName==typeShow.FullName) lb.Items.Add(ctrl.ID);
}
edSvc.DropDownControl(lb);
if (lb.SelectedIndex==-1) return value;
return lb.SelectedItem;
}
}
return value;
}
/// <summary>
/// Choose editor type
/// 选择编辑类别
/// </summary>
/// <param name="context">The context of the editing control编辑控件的上下文信息</param>
/// <returns>Returns <c>UITypeEditorEditStyle.DropDown控件样式</c></returns>
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
/// <summary>
/// Close the dropdowncontrol when the user has selected a value
/// </summary>
private void lb_SelectedIndexChanged(object sender, EventArgs e)
{
if (edSvc != null)
{
edSvc.CloseDropDown();
}
}
#endregion
}
/// <summary>
/// Editor for selecting all Asp.Net controls
/// </summary>
public class AllControlsEditor : ControlsEditor
{
#region Members
/// <summary>
/// Invoke base constructor 调用基类构造器
/// </summary>
public AllControlsEditor() : base(typeof(Control)) {}
#endregion
}
/// <summary>
/// Editor for selecting PopupWin controls
/// </summary>
public class PopupControlsEditor : ControlsEditor
{
#region Members
/// <summary>
/// Invoke base constructor
/// </summary>
public PopupControlsEditor() : base(typeof(PopupWin)) {}
#endregion
}
}
相关文章推荐
- 网页中添加调用qq或者msn,skype聊天窗口与客服进行互动
- 网页中添加调用qq或者msn聊天窗口与客服进行互动
- 教你作类似msn(QQ)等网页中窗口的拖动效果
- popupWin 属性及用法介绍 ASP.NET控件,仿QQ,msn右下角弹出窗口
- 让网页实现弹出QQ,MSN窗口功能
- 近期 关于QQ 或MSN 右下角弹出提示框 解决方案 网页
- popupWin 属性及用法介绍 ASP.NET控件,仿QQ,msn右下角弹出窗口
- 网页中如何添加调用qq或者msn聊天窗口与客服进行互动
- popupWin 属性及用法介绍 ASP.NET控件,仿QQ,msn右下角弹出窗口
- 网页中添加调用qq或者msn聊天窗口与客服进行互动
- 关于网页打开新窗口的解决方案,拒绝屏蔽
- 关于网页动态数据获取的知识学习(1)
- 如何在网页HTML中嵌入QQ、MSN、旺旺、Gtalk快速对话框代码
- 在网页上加入QQ msn yahoo alibaba等连接
- 网页设计问题大搜集(有些细节的问题,很值得学习)
- MFC TAB控件,关于窗口之间控件操作问题
- 关于“网页对话框”中链接和表单提交会在新窗口中打开的问题
- 【转】MSN,QQ在线即时交谈网页代码
- ASP.NET(C#)AJAX+JAVASCRIPT实现类似QQ,MSN窗口之功能(续)
- 关于Activity生命周期学习之窗口化一个Activity