ShowMessageForm.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*----------------------------------------------------------------
  2. // Copyright (C) 2007 liu523@QQ.COM
  3. // 版权所有。
  4. // 开发者:liu523@QQ.COM团队
  5. // 文件名:ShowMessageForm.cs
  6. // 文件功能描述:动态效果显示文本信息(起提醒作用)
  7. //----------------------------------------------------------------*/
  8. using System;
  9. using System.ComponentModel;
  10. using System.Drawing;
  11. using System.Windows.Forms;
  12. namespace ShowMessage
  13. {
  14. /// <summary>
  15. /// 信息框
  16. /// </summary>
  17. public partial class ShowMessageForm : Form
  18. {
  19. /// <summary>
  20. /// 当前的时间
  21. /// </summary>
  22. private int times;
  23. /// <summary>
  24. /// 总时间(上升时间+显示时间)
  25. /// </summary>
  26. private int allTimes;
  27. /// <summary>
  28. /// 开始上升前的高度
  29. /// </summary>
  30. private int startTop;
  31. /// <summary>
  32. /// 单位时间内信息框上升的高度
  33. /// </summary>
  34. private int step;
  35. public ShowMessageForm()
  36. {
  37. InitializeComponent();
  38. }
  39. /// <summary>
  40. /// 初始化各个参数
  41. /// </summary>
  42. /// <param name="sender"></param>
  43. /// <param name="e"></param>
  44. private void ShowMessageForm_Load(object sender, EventArgs e)
  45. {
  46. times = 0;
  47. allTimes = 25+ (int)(txt_Message.Text.Length * 10 / 2.5);
  48. Size screenSize = Screen.PrimaryScreen.Bounds.Size;
  49. startTop=screenSize.Height -42;
  50. step=this.Height/25;
  51. this.Opacity = 0.00;
  52. this.Left = screenSize.Width - this.Width;
  53. this.Top = startTop;
  54. this.TopMost = true;
  55. txt_Message.ReadOnly = true;
  56. txt_Message.Cursor = Cursors.Hand;
  57. txt_Message.Enabled = false;
  58. FormControlTimer.Enabled = true;
  59. }
  60. /// <summary>
  61. /// 时钟控制信息框上升
  62. /// </summary>
  63. /// <param name="sender"></param>
  64. /// <param name="e"></param>
  65. private void FormControlTimer_Tick(object sender, EventArgs e)
  66. {
  67. if (this.Opacity < 1.00)
  68. {
  69. this.Opacity += 0.04;
  70. this.Top -= step;
  71. }
  72. if (++times > allTimes) this.Close();
  73. }
  74. /// <summary>
  75. /// 信息
  76. /// </summary>
  77. public string Message
  78. {
  79. set
  80. {
  81. txt_Message.Text = value;
  82. }
  83. }
  84. }
  85. }