Form1.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 WindowsFormsApp2
  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. myPath.AddEllipse(0, 0, this.Width, this.Height);
  43. Region myRegion = new Region(myPath);
  44. this.Region = myRegion;
  45. }
  46. private void Form1_MouseDown(object sender, MouseEventArgs e)
  47. {
  48. if (e.Button == MouseButtons.Left)
  49. {
  50. moveStart = new Point(e.X, e.Y);
  51. }
  52. }
  53. private void Form1_MouseMove(object sender, MouseEventArgs e)
  54. {
  55. if ((e.Button & MouseButtons.Left) != 0)
  56. {
  57. Point deltaPos = new Point(e.X - moveStart.X, e.Y - moveStart.Y);
  58. this.Location = new Point(this.Location.X + deltaPos.X,
  59. this.Location.Y + deltaPos.Y);
  60. }
  61. }
  62. private void Form1_Load(object sender, EventArgs e)
  63. {
  64. }
  65. private void LoadEvent(object sender, EventArgs e)
  66. {
  67. this.BackColor = Color.Yellow;
  68. }
  69. private void button1_Click(object sender, EventArgs e)
  70. {
  71. Form2 newForm = new Form2();
  72. newForm.Show();
  73. }
  74. }
  75. }