C#实现仿msn提示消息在登录后只弹出一次的效果(downmoon)
2007-06-13 09:13
796 查看
在
codeproject
上看到一个很不错的控件,完全能够自定义弹出窗口的样式、内容、链接,该控件支持Mozilla
, Internet Explorer
和 Opera
,我试用了一下,效果非常不错,推荐大家使用。
Download demo project (C# and VB.NET) - 38.1 Kb
Download control with source - 37.7 Kb
Download control documentation - 71.1 Kb
Open online sample
[^
].
下面主要介绍该控件结合cookie实现登录后只提醒一次的功能!
一、定义变量}
members
#region
members
protected
AgronetControl.PopupWin pwVegnet;
private
string
downmoontest
=
"
downmoontest
"
;
#endregion
二、按钮事件
Events
#region
Events
private
void
Page_Load(
object
sender, System.EventArgs e)
...
{
pwVegnet.LinkClicked
+=
new
EventHandler(pwVegnet_LinkClicked);
this
.pwVegnet.Visible
=
false
;
if
(
!
IsPostBack)
...
{
bool
bl
=
IsShowMessage();
if
(bl)
...
{
SetMessage();
setCookies(downmoontest,
"
yes
"
,
1
);
}
else
...
{
this
.pwVegnet.Visible
=
false
;
}
}
}
/**/
///
<summary>
///
注销按钮
///
</summary>
///
<param name="sender"></param>
///
<param name="e"></param>
private
void
btnLogOff_Click(
object
sender, System.EventArgs e)
...
{
RemoveAll();
}
private
void
pwVegnet_LinkClicked(
object
sender, EventArgs e)
...
{
//
此处可以加上"下次是否显示之类的脚本"---downmoon
Page.Response.Redirect(
@"
http://www.vegnet.com.cn/user/
"
);
}
三、主要方法:
Methods
#region
Methods
private
void
SetMessage()
...
{
pwVegnet.HideAfter
=
5000
;
pwVegnet.Visible
=
true
;
pwVegnet.Title
=
textTitle.Text;
pwVegnet.Message
=
textMsg.Text;
pwVegnet.Text
=
textFull.Text;
pwVegnet.DragDrop
=
true
;
pwVegnet.OffsetX
=
30
;
pwVegnet.OffsetY
=
15
;
pwVegnet.DockMode
=
AgronetControl.PopupDocking.BottomRight;
//
随机弹出窗口样式
int
t
=
GetRandomID(
1
,
4
);
switch
(t)
...
{
case
1
: pwVegnet.ColorStyle
=
AgronetControl.PopupColorStyle.Red;
break
;
case
2
: pwVegnet.ColorStyle
=
AgronetControl.PopupColorStyle.Green;
break
;
case
3
: pwVegnet.ColorStyle
=
AgronetControl.PopupColorStyle.Blue;
break
;
case
4
: pwVegnet.ColorStyle
=
AgronetControl.PopupColorStyle.Violet;
break
;
default
:pwVegnet.ColorStyle
=
AgronetControl.PopupColorStyle.Green;
break
;
}
pwVegnet.Link
=
@"
http://www.vegnet.com.cn
"
;
}
private
bool
IsShowMessage()
...
{
string
str
=
getCookies(downmoontest);
if
(str
==
string
.Empty
||
str.ToLower()
==
"
no
"
)
...
{
return
true
;
}
else
...
{
return
false
;
}
}
public
void
MsgBox(
string
strDebug)
...
{
Page.Response.Write(
"
<script language=javascript>alert('
"
+
strDebug.Replace(
"
'
"
,
""
).Replace(
"
"
,
""
)
+
"
');</script>
"
);
//
Page.Response.End();
}
public
static
string
RandomKey(
int
b,
int
e)
...
{
return
DateTime.Now.ToString(
"
yyyyMMdd-HHmmss-fff-
"
)
+
GetRandomID(b,e);
}
public
static
int
GetRandomID(
int
minValue,
int
maxValue)
...
{
Random ri
=
new
Random(
unchecked
((
int
)DateTime.Now.Ticks));
int
k
=
ri.Next(minValue,maxValue);
return
k;
}
设置cookie
#region
读cookie
private
void
setCookies(
string
cook,
string
valuee,
int
num)
...
{
//
Response.Cookies.Clear();
HttpCookie cookie ;
cookie
=
Request.Cookies[cook];
if
(cookie
==
null
)
...
{
cookie
=
new
HttpCookie(cook);
cookie.Value
=
valuee;
cookie.Expires
=
DateTime.Now.AddDays(num);
HttpContext.Current.Response.Cookies.Add(cookie);
}
else
...
{
cookie.Value
=
valuee;
}
}
#endregion
读cookie
#region
写cookie
private
string
getCookies(
string
cook)
...
{
HttpCookie readcookie
=
Request.Cookies[cook];
if
(readcookie
!=
null
&&
readcookie.Value
!=
null
)
...
{
return
readcookie.Value;
}
else
...
{
return
string
.Empty;
}
}
#endregion
去除SESSION/注销
#region
去除SESSION/注销
/**/
///
<summary>
///
去除SESSION/注销
///
</summary>
public
void
RemoveAll()
...
{
HttpCookieCollection cooks
=
HttpContext.Current.Response.Cookies;
cooks[downmoontest].Expires
=
new
DateTime(
1999
,
10
,
12
);
HttpContext.Current.Response.Cookies.Add(cooks[downmoontest]);
}
#endregion
#endregion
实现效果:
邀月注:本文版权由邀月
和CSDN共同所有,转载请注明出处。
助人等于自助!
3w@live.cn
codeproject
上看到一个很不错的控件,完全能够自定义弹出窗口的样式、内容、链接,该控件支持Mozilla
, Internet Explorer
和 Opera
,我试用了一下,效果非常不错,推荐大家使用。
Download demo project (C# and VB.NET) - 38.1 Kb
Download control with source - 37.7 Kb
Download control documentation - 71.1 Kb
Open online sample
[^
].
下面主要介绍该控件结合cookie实现登录后只提醒一次的功能!
一、定义变量}
members
#region
members
protected
AgronetControl.PopupWin pwVegnet;
private
string
downmoontest
=
"
downmoontest
"
;
#endregion
二、按钮事件
Events
#region
Events
private
void
Page_Load(
object
sender, System.EventArgs e)
...
{
pwVegnet.LinkClicked
+=
new
EventHandler(pwVegnet_LinkClicked);
this
.pwVegnet.Visible
=
false
;
if
(
!
IsPostBack)
...
{
bool
bl
=
IsShowMessage();
if
(bl)
...
{
SetMessage();
setCookies(downmoontest,
"
yes
"
,
1
);
}
else
...
{
this
.pwVegnet.Visible
=
false
;
}
}
}
/**/
///
<summary>
///
注销按钮
///
</summary>
///
<param name="sender"></param>
///
<param name="e"></param>
private
void
btnLogOff_Click(
object
sender, System.EventArgs e)
...
{
RemoveAll();
}
private
void
pwVegnet_LinkClicked(
object
sender, EventArgs e)
...
{
//
此处可以加上"下次是否显示之类的脚本"---downmoon
Page.Response.Redirect(
@"
http://www.vegnet.com.cn/user/
"
);
}
三、主要方法:
Methods
#region
Methods
private
void
SetMessage()
...
{
pwVegnet.HideAfter
=
5000
;
pwVegnet.Visible
=
true
;
pwVegnet.Title
=
textTitle.Text;
pwVegnet.Message
=
textMsg.Text;
pwVegnet.Text
=
textFull.Text;
pwVegnet.DragDrop
=
true
;
pwVegnet.OffsetX
=
30
;
pwVegnet.OffsetY
=
15
;
pwVegnet.DockMode
=
AgronetControl.PopupDocking.BottomRight;
//
随机弹出窗口样式
int
t
=
GetRandomID(
1
,
4
);
switch
(t)
...
{
case
1
: pwVegnet.ColorStyle
=
AgronetControl.PopupColorStyle.Red;
break
;
case
2
: pwVegnet.ColorStyle
=
AgronetControl.PopupColorStyle.Green;
break
;
case
3
: pwVegnet.ColorStyle
=
AgronetControl.PopupColorStyle.Blue;
break
;
case
4
: pwVegnet.ColorStyle
=
AgronetControl.PopupColorStyle.Violet;
break
;
default
:pwVegnet.ColorStyle
=
AgronetControl.PopupColorStyle.Green;
break
;
}
pwVegnet.Link
=
@"
http://www.vegnet.com.cn
"
;
}
private
bool
IsShowMessage()
...
{
string
str
=
getCookies(downmoontest);
if
(str
==
string
.Empty
||
str.ToLower()
==
"
no
"
)
...
{
return
true
;
}
else
...
{
return
false
;
}
}
public
void
MsgBox(
string
strDebug)
...
{
Page.Response.Write(
"
<script language=javascript>alert('
"
+
strDebug.Replace(
"
'
"
,
""
).Replace(
"
"
,
""
)
+
"
');</script>
"
);
//
Page.Response.End();
}
public
static
string
RandomKey(
int
b,
int
e)
...
{
return
DateTime.Now.ToString(
"
yyyyMMdd-HHmmss-fff-
"
)
+
GetRandomID(b,e);
}
public
static
int
GetRandomID(
int
minValue,
int
maxValue)
...
{
Random ri
=
new
Random(
unchecked
((
int
)DateTime.Now.Ticks));
int
k
=
ri.Next(minValue,maxValue);
return
k;
}
设置cookie
#region
读cookie
private
void
setCookies(
string
cook,
string
valuee,
int
num)
...
{
//
Response.Cookies.Clear();
HttpCookie cookie ;
cookie
=
Request.Cookies[cook];
if
(cookie
==
null
)
...
{
cookie
=
new
HttpCookie(cook);
cookie.Value
=
valuee;
cookie.Expires
=
DateTime.Now.AddDays(num);
HttpContext.Current.Response.Cookies.Add(cookie);
}
else
...
{
cookie.Value
=
valuee;
}
}
#endregion
读cookie
#region
写cookie
private
string
getCookies(
string
cook)
...
{
HttpCookie readcookie
=
Request.Cookies[cook];
if
(readcookie
!=
null
&&
readcookie.Value
!=
null
)
...
{
return
readcookie.Value;
}
else
...
{
return
string
.Empty;
}
}
#endregion
去除SESSION/注销
#region
去除SESSION/注销
/**/
///
<summary>
///
去除SESSION/注销
///
</summary>
public
void
RemoveAll()
...
{
HttpCookieCollection cooks
=
HttpContext.Current.Response.Cookies;
cooks[downmoontest].Expires
=
new
DateTime(
1999
,
10
,
12
);
HttpContext.Current.Response.Cookies.Add(cooks[downmoontest]);
}
#endregion
#endregion
实现效果:
邀月注:本文版权由邀月
和CSDN共同所有,转载请注明出处。
助人等于自助!
3w@live.cn
相关文章推荐
- C#实现仿msn提示消息在登录后只弹出一次的效果(downmoon)
- C#实现仿msn提示消息在登录后只弹出一次的效果
- C# 模仿QQ、MSN消息提示系列 三、实现多个提示效果
- C# 模仿QQ、MSN消息提示系列 三、实现多个提示效果
- C# 模仿QQ、MSN消息提示系列 三、实现多个提示效果
- 实现MSN,QQ消息提示效果[ASP.Net]
- C# 模仿QQ、MSN消息提示系列 二、基本效果模仿包含代码
- JavaScript实现类似QQ、MSN消息提示的效果(转载)
- C# 模仿QQ、MSN消息提示系列 二、基本效果模仿包含代码
- JS实现MSN提示弹出的效果
- 类似msn的提示效果代码系列四:利用反射和嵌入JavaScript资源封装消息提示的C#类
- C# 模仿QQ、MSN消息提示系列 四、bug修改 效果优化
- C# 模仿QQ、MSN消息提示系列 四、bug修改 效果优化
- C# 模仿QQ、MSN消息提示系列 四、bug修改 效果优化
- C# 模仿QQ、MSN消息提示系列 二、基本效果模仿包含代码
- C# 模仿QQ、MSN消息提示系列 二、基本效果模仿包含代码
- 仿QQ、MSN消息提示窗口的实现(C#)
- ymPrompt消息提示组件实现弹出层使用小结
- 用PHP实现弹出消息提示框
- BootstrapValidator实现注册校验和登录错误提示效果