Repository navigation
Expand file tree
/
Copy pathMainForm.cs
More file actions
121 lines (93 loc) · 3.34 KB
/
Copy pathMainForm.cs
File metadata and controls
121 lines (93 loc) · 3.34 KB
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SendMedia
{
public partial class MainForm : Form
{
private KeyboardWatcher _kw = null;
private GiphySearch _gs = new GiphySearch();
public MainForm()
{
InitializeComponent();
_kw = new KeyboardWatcher(new List<string> { "Notepad" },
new List<string> { this.Text });
//_kw.ActivatedWindow += _kw_Activated;
//_kw.DeactivatedWindow += _kw_Deactivated;
_kw.ActivatedKeyword += OnActivatedKeyword;
_gs.DownloadFileCompleted += AddToGrid;
}
private string _keyword;
private string _word;
private void OnActivatedKeyword(string keyword, string word)
{
this.Invoke(new Action(() =>
{
_keyword = keyword;
_word = word;
this.Top = Cursor.Position.Y + 5;
this.Left = Cursor.Position.X + 5;
this.Visible = true;
gridImages.Controls.Clear();
_gs.Search(word);
}));
}
private void MainForm_Load(object sender, EventArgs e)
{
//Rectangle resolution = Screen.PrimaryScreen.Bounds;
//this.Top = resolution.Height - this.Height;
//this.Left = resolution.Width - this.Width;
//ThreadPool.QueueUserWorkItem(x =>
// {
// Thread.Sleep(100);
// this.Invoke(new Action(() => { this.Visible = false; }));
// });
}
private void MainForm_Shown(object sender, EventArgs e)
{
HideWindow();
}
private void AddToGrid(string fileName, string url)
{
PictureBox picBox = new PictureBox();
picBox.SizeMode = PictureBoxSizeMode.StretchImage;
picBox.Height = 200;
picBox.Width = 200;
picBox.WaitOnLoad = false;
picBox.LoadAsync(fileName);
picBox.Name = url;
picBox.Cursor = Cursors.Hand;
picBox.MouseClick += new MouseEventHandler(
(object picSender, MouseEventArgs evntArgs) => {
PictureBox pic = (PictureBox)picSender;
HideWindow();
ClipboardHelper.ClearText(_keyword.Length + _word.Length + 1);
ClipboardHelper.PasteText(pic.Name);
SendKeys.Send("{Enter}");
System.Diagnostics.Debug.WriteLine("Click => " + pic.Name);
}
);
gridImages.Controls.Add(picBox);
}
private void MainForm_Deactivate(object sender, EventArgs e)
{
HideWindow();
}
private void MainForm_Leave(object sender, EventArgs e)
{
HideWindow();
}
private void HideWindow()
{
this.Visible = false;
_kw.IsActivatedWindow = false;
}
}
}