Пример #1
0
        private void BtnTextColour_Click(object sender, EventArgs e)
        {
            this.Hide();
            Bitmap bg = ScreenProcessingHelper.getVirtualScreen();

            Form image = new Form();

            image.BackgroundImage = bg;
            image.Opacity         = 1;
            image.StartPosition   = FormStartPosition.Manual;
            image.Location        = new Point(0, 0);

            image.Size = new Size(bg.Width, bg.Height);

            image.FormBorderStyle = FormBorderStyle.None;
            image.Visible         = false;
            image.TopMost         = false;

            image.Show();

            //waiting for left click originally pressed for this button
            while ((GetAsyncKeyState(0x01) & 0x8000) > 0)
            {
                Application.DoEvents();
                Thread.Sleep(10);
            }

            //while key not down
            while ((GetAsyncKeyState(0x01) & 0x8000) < 1)
            {
                Application.DoEvents();
                Thread.Sleep(10);
            }

            //when key pressed move overlay form and save
            POINT pos = new POINT();

            GetCursorPos(out pos);

            btnTextColour.BackColor = bg.GetPixel(pos.X, pos.Y);
            image.Close();
            this.Show();
        }
Пример #2
0
        private void btnSelectScreen_Click(object sender, EventArgs e)
        {
            this.Hide();
            Bitmap bg = ScreenProcessingHelper.getVirtualScreen();

            Form image = new Form();

            image.BackgroundImage = bg;
            image.Opacity         = 1;
            image.StartPosition   = FormStartPosition.Manual;
            image.Location        = new Point(0, 0);

            image.Size = new Size(bg.Width, bg.Height);

            image.FormBorderStyle = FormBorderStyle.None;
            image.Visible         = false;
            image.TopMost         = false;

            /*
             * Label lblTest = new Label();
             * lblTest.Location = new Point(10, 10);
             * lblTest.Text = "lol";
             * test.Controls.Add(lblTest);
             */

            Form selector = new Form();

            selector.Opacity       = 0.4;
            selector.BackColor     = Color.Black;
            selector.StartPosition = FormStartPosition.Manual;
            selector.Location      = new Point(0, 0);

            selector.Size = new Size(0, 0);

            selector.FormBorderStyle = FormBorderStyle.None;
            selector.Visible         = false;
            selector.TopMost         = true;


            image.Show();

            //waiting for left click originally pressed for this button
            while ((GetAsyncKeyState(0x01) & 0x8000) > 0)
            {
                Application.DoEvents();
                Thread.Sleep(10);
            }

            //while key not down
            while ((GetAsyncKeyState(0x01) & 0x8000) < 1)
            {
                Application.DoEvents();
                Thread.Sleep(10);
            }

            //when key pressed move overlay form and save
            POINT curStartPos = new POINT();
            POINT curEndPos   = new POINT();

            GetCursorPos(out curStartPos);

            image.Hide();
            IntPtr window = ScreenProcessingHelper.getWindowFromPoint(curStartPos);

            image.Show();

            selector.Show();
            selector.Location = new Point(curStartPos.X, curStartPos.Y);

            ScreenProcessingHelper.RECT windowSize = ScreenProcessingHelper.getWindowRect(window);
            int maxWidth  = windowSize.x2 - curStartPos.X;
            int maxHeight = windowSize.y2 - curStartPos.Y;

            int minX = windowSize.x1;
            int minY = windowSize.y1;

            //while key is still down
            while ((GetAsyncKeyState(0x01) & 0x8000) > 0)
            {
                GetCursorPos(out curEndPos);

                if (curEndPos.X < minX)
                {
                    curEndPos.X = minX;
                }
                if (curEndPos.Y < minY)
                {
                    curEndPos.Y = minY;
                }

                int width  = curEndPos.X - curStartPos.X;
                int height = curEndPos.Y - curStartPos.Y;

                if (width > maxWidth)
                {
                    width = maxWidth;
                }
                if (height > maxHeight)
                {
                    height = maxHeight;
                }

                if (width > 0 && height > 0)
                {
                    selector.Size = new Size(width, height);
                }
                else if (width > 0 && height <= 0)
                {
                    //if drag right and up
                    height            = curStartPos.Y - curEndPos.Y;
                    selector.Location = new Point(curStartPos.X, curEndPos.Y);
                    selector.Size     = new Size(width, height);
                }
                else if (width <= 0 && height > 0)
                {
                    //if drag left and down
                    width             = curStartPos.X - curEndPos.X;
                    selector.Location = new Point(curEndPos.X, curStartPos.Y);
                    selector.Size     = new Size(width, height);
                }
                else
                {
                    //if drag left and up
                    height            = curStartPos.Y - curEndPos.Y;
                    width             = curStartPos.X - curEndPos.X;
                    selector.Location = new Point(curEndPos.X, curEndPos.Y);
                    selector.Size     = new Size(width, height);
                }

                Application.DoEvents();
                Thread.Sleep(1);
            }

            image.Close();
            selector.Close();

            this.startPos = new Point(selector.Location.X, selector.Location.Y);
            this.endPos   = new Point(selector.Location.X + selector.Width, selector.Location.Y + selector.Height);
            this.Show();
        }