Beispiel #1
0
        private static void colorPickerIconClicked(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                foreach (Screen s in Screen.AllScreens)
                {
                    Rectangle r = new Rectangle();
                    r = Rectangle.Union(r, s.Bounds);

                    BlockInteraction blockForm = new BlockInteraction();
                    blockForm.Top    = r.Top;
                    blockForm.Left   = r.Left;
                    blockForm.Width  = r.Width;
                    blockForm.Height = r.Height;
                    blockForm.Show();

                    blockerForms.Add(blockForm);
                }

                MouseHook.Start();
                MouseHook.MouseAction += mouseEvent;
            }
        }
Beispiel #2
0
        private static void mouseEvent(object sender, MouseHook.RawMouseEventArgs e)
        {
            if (e.Message == MouseHook.MouseMessages.WM_LBUTTONUP)
            {
                blockerForms.ForEach(b => b.Close());

                MouseHook.Stop();
                MouseHook.MouseAction -= mouseEvent;
                colorPickerIcon.Icon   = Properties.Resources.picker;

                Thread.Sleep(500);



                Color  selectedColor = GetColorAt(e.Point.x, e.Point.y);
                string hexColor      = ColorTranslator.ToHtml(Color.FromArgb(selectedColor.ToArgb()));

                Clipboard.SetText(hexColor);
            }
            else if (e.Message == MouseHook.MouseMessages.WM_MOUSEMOVE)
            {
                if (mouseThread != null && mouseThread.IsAlive)
                {
                    return;
                }

                mouseThread = new Thread(() =>
                {
                    Thread.CurrentThread.IsBackground = true;

                    setIconToColor(GetColorAt(e.Point.x, e.Point.y));
                });

                mouseThread.Start();
            }
        }