Advertisement
idndn

Скриншотер

Mar 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.76 KB | None | 0 0
  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.  
  10. namespace Screenshot
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.  
  19.         private void close_Click(object sender, EventArgs e)
  20.         {
  21.             Application.Exit();
  22.         }
  23.  
  24.         private void minimize_Click(object sender, EventArgs e)
  25.         {
  26.             this.WindowState = FormWindowState.Minimized;
  27.         }
  28.  
  29.         public bool maximizeCounter = false;
  30.         public int normalWidthForm = Form1.ActiveForm.Size.Width;
  31.         public int normalHeightForm = Form1.ActiveForm.Size.Height;
  32.        
  33.         private void maximize_Click(object sender, EventArgs e)
  34.         {
  35.             if (maximizeCounter == false)
  36.             {
  37.                 this.WindowState = FormWindowState.Maximized;
  38.                 SetButtonLocation();
  39.                 maximizeCounter = true;
  40.             }
  41.             else if (maximizeCounter == true)
  42.             {
  43.                 this.WindowState = FormWindowState.Normal;
  44.                 SetButtonLocation();
  45.                 maximizeCounter = false;
  46.             }
  47.         }
  48.         private void SetButtonLocation()
  49.         {
  50.             close.SetBounds(Width - close.Size.Width, close.Bounds.Y, close.Size.Width, close.Size.Height);
  51.             minimize.SetBounds(Width - close.Size.Width - minimize.Size.Width - minimize.Size.Width,
  52.                                minimize.Bounds.Y, minimize.Size.Width, minimize.Size.Height);
  53.             maximize.SetBounds(Width - close.Size.Width - maximize.Size.Width, maximize.Bounds.Y, maximize.Size.Width,
  54.                                maximize.Size.Height);
  55.             centralPanel.SetBounds(pictureBox1.Size.Width + 1, centralPanel.Bounds.Y,
  56.                                    Width - pictureBox1.Size.Width - close.Size.Width - minimize.Size.Width - maximize.Size.Width,
  57.                                    centralPanel.Size.Height);
  58.         }
  59.  
  60.         private Point mouseOffset;
  61.         private bool isMouseDown = false;
  62.  
  63.         private void centralPanel_MouseDown(object sender, MouseEventArgs e)
  64.         {
  65.             int xOffset;
  66.             int yOffset;
  67.  
  68.             if (e.Button == MouseButtons.Left)
  69.             {
  70.                 xOffset = -e.X - SystemInformation.FrameBorderSize.Width - 39;
  71.                 yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height + 36;
  72.                 mouseOffset = new Point (xOffset, yOffset);
  73.                 isMouseDown = true;
  74.             }
  75.         }
  76.  
  77.         private void centralPanel_MouseMove(object sender, MouseEventArgs e)
  78.         {
  79.             if (isMouseDown)
  80.             {
  81.                 Point mousePos = Control.MousePosition;
  82.                 mousePos.Offset(mouseOffset.X, mouseOffset.Y);
  83.                 Location = mousePos;
  84.             }
  85.         }
  86.  
  87.         private void centralPanel_MouseUp(object sender, MouseEventArgs e)
  88.         {
  89.             if (e.Button == MouseButtons.Left)
  90.             {
  91.                 isMouseDown = false;
  92.             }
  93.         }
  94.  
  95.         private void centralPanel_Click(object sender, EventArgs e)
  96.         {
  97.             this.WindowState = FormWindowState.Normal;
  98.             SetButtonLocation();
  99.             maximizeCounter = false;
  100.         }
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement