NoTitleForm.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using Y.Utils.WindowsUtils.APIUtils;
  10. namespace Y.Skin.YoForm.NoTitle
  11. {
  12. public partial class NoTitleForm : Form
  13. {
  14. private int Border = 1;
  15. Color BorderColor = Color.Black;
  16. public NoTitleForm()
  17. {
  18. InitializeComponent();
  19. }
  20. private void NoTitleForm_Load(object sender, EventArgs e)
  21. {
  22. SetBorder();
  23. }
  24. /// <summary>
  25. /// 设置无标题窗口可拖动
  26. /// </summary>
  27. /// <param name="e"></param>
  28. protected override void OnMouseMove(MouseEventArgs e)
  29. {
  30. base.OnMouseMove(e);
  31. FormStyleAPI.ReleaseCapture();
  32. FormStyleAPI.SendMessage(Handle, FormStyleAPI.WM_NCLBUTTONDOWN, FormStyleAPI.HTCAPTION, 0);
  33. }
  34. /// <summary>
  35. /// 设置窗口边框
  36. /// </summary>
  37. protected void SetBorder()
  38. {
  39. Label BorderTop = new Label();
  40. BorderTop.BackColor = BorderColor;
  41. BorderTop.Width = Width;
  42. BorderTop.Height = Border;
  43. Controls.Add(BorderTop);
  44. BorderTop.BringToFront();
  45. BorderTop.Top = 0;
  46. BorderTop.Left = 0;
  47. Label BorderBottom = new Label();
  48. BorderBottom.BackColor = BorderColor;
  49. BorderBottom.Width = Width;
  50. BorderBottom.Height = Border;
  51. Controls.Add(BorderBottom);
  52. BorderBottom.BringToFront();
  53. BorderBottom.Top = Height - Border;
  54. BorderBottom.Left = 0;
  55. Label BorderLeft = new Label();
  56. BorderLeft.BackColor = BorderColor;
  57. BorderLeft.Width = Border;
  58. BorderLeft.Height = Height;
  59. Controls.Add(BorderLeft);
  60. BorderLeft.BringToFront();
  61. BorderLeft.Top = 0;
  62. BorderLeft.Left = 0;
  63. Label BorderRight = new Label();
  64. BorderRight.BackColor = BorderColor;
  65. BorderRight.Width = Border;
  66. BorderRight.Height = Height;
  67. Controls.Add(BorderRight);
  68. BorderRight.BringToFront();
  69. BorderRight.Top = 0;
  70. BorderRight.Left = Width - Border;
  71. }
  72. protected override void OnPaint(PaintEventArgs e)
  73. {
  74. base.OnPaint(e);
  75. //Graphics g = CreateGraphics();
  76. //g.DrawRectangle(new Pen(Color.Red, 1), new Rectangle(0, 0, Width, Height));
  77. }
  78. }
  79. }