winform 标注式弹出窗口
1,思路,在桌面的右上角弹出不规则桌面的窗体。
关于绘制不规则窗体,可以考虑使用form的属性。比如:backgroundImage属性和transparencykey来设置图片的某种颜色为透明色。
主要功能是窗体慢慢地从桌面的右下角弹出。弹出完后停留5分钟。再慢慢地滚动下去了。
如图。
具体实现原理,请看打包。
还有一种方法,模拟腾讯的,弹出式窗口淡出,停了5秒钟之后,就慢慢淡入了。
实现方法:可以动态的控制opacity 这个属性。具体方法的实现如下。
在form2(弹出窗口)中。的代码如下。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 private double intOpacity ;
2 public double IntOpacity
3 {
4 get
5 {
6 return intOpacity;
7 }
8 set
9 {
10 intOpacity = value;
11 }
12 }
13
14
15
16 //以下是操作弹出式窗口的效果
17 public void FadeShow()
18 {
19 this.Opacity = 0;
20 this.Show();
21 this.timer4.Enabled = true;
22 }
23 /// <summary>
24 /// 淡出
25 /// </summary>
26 private void FadeOut()
27 {
28 try
29 {
30 if (this.Opacity < IntOpacity)
31 {
32 this.Opacity += 0.1;
33 }
34 else
35 {
36 timer4.Enabled = false;
37 timer5.Enabled = true;
38 }
39 }
40 catch (Exception ex)
41 {
42 MessageBox.Show(ex.Message);
43 }
44 }
45
46 private void FadeIn()
47 {
48 if (this.Opacity > 0)
49 {
50 this.Opacity -= 0.1;
51 }
52 else
53 {
54 timer6.Enabled = false;
55 this.Close();
56
57
58 }
59 }
60 private void timer4_Tick(object sender, EventArgs e)
61 {
62 FadeOut();
63 }
64
65 private void timer5_Tick(object sender, EventArgs e)
66 {
67 timer5.Enabled = false;
68 timer6.Enabled = true;
69 }
70
71 private void timer6_Tick(object sender, EventArgs e)
72 {
73 FadeIn();
74 }
2 public double IntOpacity
3 {
4 get
5 {
6 return intOpacity;
7 }
8 set
9 {
10 intOpacity = value;
11 }
12 }
13
14
15
16 //以下是操作弹出式窗口的效果
17 public void FadeShow()
18 {
19 this.Opacity = 0;
20 this.Show();
21 this.timer4.Enabled = true;
22 }
23 /// <summary>
24 /// 淡出
25 /// </summary>
26 private void FadeOut()
27 {
28 try
29 {
30 if (this.Opacity < IntOpacity)
31 {
32 this.Opacity += 0.1;
33 }
34 else
35 {
36 timer4.Enabled = false;
37 timer5.Enabled = true;
38 }
39 }
40 catch (Exception ex)
41 {
42 MessageBox.Show(ex.Message);
43 }
44 }
45
46 private void FadeIn()
47 {
48 if (this.Opacity > 0)
49 {
50 this.Opacity -= 0.1;
51 }
52 else
53 {
54 timer6.Enabled = false;
55 this.Close();
56
57
58 }
59 }
60 private void timer4_Tick(object sender, EventArgs e)
61 {
62 FadeOut();
63 }
64
65 private void timer5_Tick(object sender, EventArgs e)
66 {
67 timer5.Enabled = false;
68 timer6.Enabled = true;
69 }
70
71 private void timer6_Tick(object sender, EventArgs e)
72 {
73 FadeIn();
74 }
注意:代码:
private void FadeOut()
{
try
{
if (this.Opacity < IntOpacity)
{
this.Opacity += 0.1;
}
else
{
timer4.Enabled = false;
timer5.Enabled = true;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
{
try
{
if (this.Opacity < IntOpacity)
{
this.Opacity += 0.1;
}
else
{
timer4.Enabled = false;
timer5.Enabled = true;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
if (this.Opacity < IntOpacity)其中左边的代码不能写成
if (this.Opacity <= IntOpacity)因为intopacity的值为1,如果是《=号的话,那么,else将不会被执行到。