Form1.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace Praktika
  11. {
  12. public partial class Form1 : Form
  13. {
  14. Point moveStart;
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. this.FormBorderStyle = FormBorderStyle.None;
  19. this.BackColor = Color.Yellow;
  20. Button button1 = new Button
  21. {
  22. Location = new Point
  23. {
  24. X = this.Width / 3,
  25. Y = this.Height / 3
  26. }
  27. };
  28. button1.Text = "Закрыть";
  29. button1.Click += button1_Click;
  30. this.Controls.Add(button1); // добавляем кнопку на форму
  31. this.Load += Form1_Load;
  32. this.MouseDown += Form1_MouseDown;
  33. this.MouseMove += Form1_MouseMove;
  34. }
  35. private void button1_Click(object sender, EventArgs e)
  36. {
  37. this.Close();
  38. }
  39. private void Form1_Load(object sender, EventArgs e)
  40. {
  41. System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath();
  42. // создаем эллипс с высотой и шириной формы
  43. myPath.AddEllipse(0, 0, this.Width, this.Height);
  44. // создаем с помощью элипса ту область формы, которую мы хотим видеть
  45. Region myRegion = new Region(myPath);
  46. // устанавливаем видимую область
  47. this.Region = myRegion;
  48. }
  49. private void Form1_MouseDown(object sender, MouseEventArgs e)
  50. {
  51. if (e.Button == MouseButtons.Left)
  52. {
  53. moveStart = new Point(e.X, e.Y);
  54. }
  55. }
  56. private void Form1_MouseMove(object sender, MouseEventArgs e)
  57. {
  58. // если нажата левая кнопка мыши
  59. if ((e.Button & MouseButtons.Left) != 0)
  60. {
  61. // получаем новую точку положения формы
  62. Point deltaPos = new Point(e.X - moveStart.X, e.Y - moveStart.Y);
  63. // устанавливаем положение формы
  64. this.Location = new Point(this.Location.X + deltaPos.X,
  65. this.Location.Y + deltaPos.Y);
  66. }
  67. }
  68. }
  69. }