-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainForm.cs
152 lines (135 loc) · 5.09 KB
/
MainForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace TrayTools {
public partial class MainForm : Form {
Hotkey printScreen;
Hotkey colorPicker;
Hotkey screenPicker;
NotifyIcon TrayIcon;
ContextMenu TrayMenu;
public MainForm() {
InitializeComponent();
}
void MainForm_Load(object sender, EventArgs e) {
printScreen = new Hotkey();
printScreen.Control = true;
printScreen.Alt = true;
printScreen.KeyCode = Keys.P;
printScreen.Pressed += new HandledEventHandler(printScreen_Pressed);
printScreen.Register(this);
HotKeySettingPrintScreen.Hotkey = printScreen;
colorPicker = new Hotkey();
colorPicker.Control = true;
colorPicker.Alt = true;
colorPicker.KeyCode = Keys.O;
colorPicker.Pressed += new HandledEventHandler(colorPicker_Pressed);
colorPicker.Register(this);
HotKeySettingColorPicker.Hotkey = colorPicker;
TrayMenu = new ContextMenu();
TrayMenu.MenuItems.Add(0, new MenuItem("Exit", new System.EventHandler(Exit_Click)));
TrayIcon = new NotifyIcon();
TrayIcon.Text = "Coffee give me!!!";
TrayIcon.Icon = Properties.Resources.coffee;
TrayIcon.ContextMenu = TrayMenu;
TrayIcon.Visible = true;
TrayIcon.DoubleClick += new System.EventHandler(this.TrayDoubleClick);
Hide();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void printScreen_Pressed(object sender, HandledEventArgs e) {
for (int index = 0; index < Screen.AllScreens.Length; index++) {
ImageSelection imageSelection = new ImageSelection(index);
imageSelection.Show();
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void colorPicker_Pressed(object sender, HandledEventArgs e) {
ColorPicker cp = new ColorPicker();
FloatingColor color = FloatingColor.FromString(Clipboard.GetText(TextDataFormat.Text));
if (color != null) {
cp.Color = color.ToColor();
} else {
Random r = new Random();
cp.Color = Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255));
}
cp.Show();
cp.Focus();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void Exit_Click(Object sender, System.EventArgs e) {
TrayIcon.Visible = false;
Application.Exit();
}
/// <summary>
///
/// </summary>
/// <param name="Sender"></param>
/// <param name="e"></param>
void TrayDoubleClick(object Sender, EventArgs e) {
Show();
WindowState = FormWindowState.Normal;
Activate();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
TrayIcon.Dispose();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void MainForm_FormClosing(object sender, FormClosingEventArgs e) {
if (e.CloseReason == CloseReason.UserClosing) {
e.Cancel = true;
Hide();
}
}
//protected override void ScaleControl(SizeF factor, BoundsSpecified specified) {}
/// <summary>
///
/// </summary>
/// <returns></returns>
public Bitmap GetScreen() {
//foreach (Screen screen in Screen.AllScreens) {
// uint dpiX = 0, dpiY = 0;
// screen.GetDpi(DpiType.Angular, out dpiX, out dpiY);
// string message = string.Format("DPI {0} x {1}", dpiX, dpiY);
// MessageBox.Show(message);
// screen.GetDpi(DpiType.Effective, out dpiX, out dpiY);
// message = string.Format("DPI {0} x {1}", dpiX, dpiY);
// MessageBox.Show(message);
// screen.GetDpi(DpiType.Raw, out dpiX, out dpiY);
// message = string.Format("DPI {0} x {1}", dpiX, dpiY);
// MessageBox.Show(message);
//}
Rectangle screenSize = Screen.GetBounds(Screen.GetBounds(Point.Empty));
Bitmap bitmap = new Bitmap(screenSize.Width, screenSize.Height);
Graphics g = Graphics.FromImage(bitmap);
g.CopyFromScreen(new Point(0, 0), new Point(0, 0), screenSize.Size);
g.Dispose();
return bitmap;
}
}
}