Form2.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using System;
  2. using System.Windows.Forms;
  3. using BenQGuru.eMES.DLLService;
  4. using System.Drawing.Drawing2D;
  5. using System.Drawing;
  6. using System.Runtime.InteropServices;
  7. namespace TestProject
  8. {
  9. public partial class Form2 : Form
  10. {
  11. //所有用到了headBar的部分都需要这段代码
  12. [DllImport("user32.dll")]
  13. public static extern bool ReleaseCapture();
  14. [DllImport("user32.dll")]
  15. public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
  16. [DllImport("user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]
  17. public static extern int GetWindowLong(HandleRef hWnd, int nIndex);
  18. [DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)]
  19. public static extern IntPtr SetWindowLong(HandleRef hWnd, int nIndex, int dwNewLong);
  20. public const int WM_SYSCOMMAND = 0x0112;
  21. public const int SC_MOVE = 0xF010;
  22. public const int HTCAPTION = 0x0002;
  23. private Panel TitlePanel;
  24. public Form2()
  25. {
  26. InitializeComponent();
  27. }
  28. private void Form2_Load(object sender, EventArgs e)
  29. {
  30. }
  31. private void ChangeBackColor(object sender, EventArgs e)
  32. {
  33. }
  34. private void button1_Click(object sender, EventArgs e)
  35. {
  36. MESHelper helper = new MESHelper();
  37. string user = "zhangz";
  38. string resCode = "ZY_AOIA";
  39. string psw = "111111";
  40. string err="";
  41. if (helper.CheckUserAndResourcePassed(user, resCode, psw, out err))
  42. {
  43. MessageBox.Show("OK");
  44. }
  45. else
  46. {
  47. MessageBox.Show(err);
  48. }
  49. }
  50. private void InitializeComponent()
  51. {
  52. this.TitlePanel = new System.Windows.Forms.Panel();
  53. this.SuspendLayout();
  54. //
  55. // TitlePanel
  56. //
  57. this.TitlePanel.Dock = System.Windows.Forms.DockStyle.Top;
  58. this.TitlePanel.Location = new System.Drawing.Point(0, 0);
  59. this.TitlePanel.Name = "TitlePanel";
  60. this.TitlePanel.Size = new System.Drawing.Size(435, 40);
  61. this.TitlePanel.TabIndex = 0;
  62. this.TitlePanel.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
  63. this.TitlePanel.MouseDown += new System.Windows.Forms.MouseEventHandler(this.TitlePanel_MouseDown);
  64. //
  65. // Form2
  66. //
  67. this.BackColor = System.Drawing.Color.White;
  68. this.ClientSize = new System.Drawing.Size(435, 184);
  69. this.Controls.Add(this.TitlePanel);
  70. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
  71. this.Name = "Form2";
  72. this.Load += new System.EventHandler(this.Form2_Load_1);
  73. this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form2_Paint);
  74. this.ResumeLayout(false);
  75. }
  76. private void Form2_Load_1(object sender, EventArgs e)
  77. {
  78. }
  79. private void Form2_Paint(object sender, PaintEventArgs e)
  80. {
  81. }
  82. internal static GraphicsPath CreateRoundedRectanglePath(Rectangle rect, int cornerRadius)
  83. {
  84. GraphicsPath roundedRect = new GraphicsPath();
  85. roundedRect.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90);
  86. roundedRect.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y);
  87. roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90);
  88. roundedRect.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2);
  89. roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90);
  90. roundedRect.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom);
  91. roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90);
  92. roundedRect.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2);
  93. roundedRect.CloseFigure();
  94. return roundedRect;
  95. }
  96. private void panel1_Paint(object sender, PaintEventArgs e)
  97. {
  98. Graphics g = e.Graphics;
  99. Pen p = new Pen(Color.CadetBlue, 2);
  100. Rectangle rect = new Rectangle(TitlePanel.Location, TitlePanel.Size);
  101. LinearGradientBrush b3 = new LinearGradientBrush(rect, Color.LightSkyBlue, Color.White, LinearGradientMode.Vertical);
  102. g.FillRectangle(b3, rect);
  103. g.DrawString("通知公告", new Font("微软雅黑", 14F, FontStyle.Regular, GraphicsUnit.Point, 134), Brushes.Black, TitlePanel.Width / 2 - 40, 2);
  104. //绘制关闭按钮矩形
  105. b3 = new LinearGradientBrush(rect, Color.IndianRed, Color.White, LinearGradientMode.Vertical);
  106. rect = new Rectangle(new Point(TitlePanel.Location.X + TitlePanel.Size.Width - TitlePanel.Size.Height, 0), new Size(TitlePanel.Size.Height, TitlePanel.Size.Height));
  107. //绘制关闭按钮实线
  108. GraphicsPath Rect = CreateRoundedRectanglePath(rect, 1);
  109. g.FillPath(Brushes.Tomato, Rect);
  110. g.DrawLine(new Pen(Color.White, 4), new Point(TitlePanel.Location.X + TitlePanel.Size.Width - TitlePanel.Size.Height + 12, 12), new Point(TitlePanel.Location.X + TitlePanel.Size.Width - 12, TitlePanel.Size.Height - 12));
  111. g.DrawLine(new Pen(Color.White, 4), new Point(TitlePanel.Location.X + TitlePanel.Size.Width - TitlePanel.Size.Height + 12, TitlePanel.Size.Height - 12), new Point(TitlePanel.Location.X + TitlePanel.Size.Width - 12, 12));
  112. //绘制最小化按钮
  113. rect = new Rectangle(new Point(TitlePanel.Location.X + TitlePanel.Size.Width - TitlePanel.Size.Height * 2 - 10, 0), new Size(TitlePanel.Size.Height, TitlePanel.Size.Height));
  114. //使用路径绘制
  115. Rect = CreateRoundedRectanglePath(rect, 1);
  116. g.FillPath(Brushes.Tomato, Rect);
  117. g.DrawLine(new Pen(Color.White, 4), new Point(TitlePanel.Location.X + TitlePanel.Size.Width - TitlePanel.Size.Height*2 , 20), new Point(TitlePanel.Location.X + TitlePanel.Size.Width - TitlePanel.Size.Height - 20, 20));
  118. }
  119. private void TitlePanel_MouseDown(object sender, MouseEventArgs e)
  120. {
  121. ReleaseCapture();
  122. SendMessage(Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  123. }
  124. }
  125. }