Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace Screenshot
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void close_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void minimize_Click(object sender, EventArgs e)
- {
- this.WindowState = FormWindowState.Minimized;
- }
- public bool maximizeCounter = false;
- public int normalWidthForm = Form1.ActiveForm.Size.Width;
- public int normalHeightForm = Form1.ActiveForm.Size.Height;
- private void maximize_Click(object sender, EventArgs e)
- {
- if (maximizeCounter == false)
- {
- this.WindowState = FormWindowState.Maximized;
- SetButtonLocation();
- maximizeCounter = true;
- }
- else if (maximizeCounter == true)
- {
- this.WindowState = FormWindowState.Normal;
- SetButtonLocation();
- maximizeCounter = false;
- }
- }
- private void SetButtonLocation()
- {
- close.SetBounds(Width - close.Size.Width, close.Bounds.Y, close.Size.Width, close.Size.Height);
- minimize.SetBounds(Width - close.Size.Width - minimize.Size.Width - minimize.Size.Width,
- minimize.Bounds.Y, minimize.Size.Width, minimize.Size.Height);
- maximize.SetBounds(Width - close.Size.Width - maximize.Size.Width, maximize.Bounds.Y, maximize.Size.Width,
- maximize.Size.Height);
- centralPanel.SetBounds(pictureBox1.Size.Width + 1, centralPanel.Bounds.Y,
- Width - pictureBox1.Size.Width - close.Size.Width - minimize.Size.Width - maximize.Size.Width,
- centralPanel.Size.Height);
- }
- private Point mouseOffset;
- private bool isMouseDown = false;
- private void centralPanel_MouseDown(object sender, MouseEventArgs e)
- {
- int xOffset;
- int yOffset;
- if (e.Button == MouseButtons.Left)
- {
- xOffset = -e.X - SystemInformation.FrameBorderSize.Width - 39;
- yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height + 36;
- mouseOffset = new Point (xOffset, yOffset);
- isMouseDown = true;
- }
- }
- private void centralPanel_MouseMove(object sender, MouseEventArgs e)
- {
- if (isMouseDown)
- {
- Point mousePos = Control.MousePosition;
- mousePos.Offset(mouseOffset.X, mouseOffset.Y);
- Location = mousePos;
- }
- }
- private void centralPanel_MouseUp(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- isMouseDown = false;
- }
- }
- private void centralPanel_Click(object sender, EventArgs e)
- {
- this.WindowState = FormWindowState.Normal;
- SetButtonLocation();
- maximizeCounter = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement