Example #1
0
        /// <summary>
        ///
        /// </summary>
        private void func_全選()
        {
            t_拖曳中.Enabled = false;



            b_右上.Margin = new Thickness(this.ActualWidth - 10, -10, 0, 0);
            b_右下.Margin = new Thickness(this.ActualWidth - 10, this.ActualHeight - 10, -10, 0);
            b_左上.Margin = new Thickness(-10, -10, 0, 0);
            b_左下.Margin = new Thickness(-10, this.ActualHeight - 10, 0, 0);

            b_下.Margin = new Thickness(0, this.ActualHeight - 11, 0, 0);
            b_右.Margin = new Thickness(this.ActualWidth - 11, 0, 0, 0);
            b_上.Margin = new Thickness(0, -10, 0, 0);
            b_左.Margin = new Thickness(-10, 0, 0, 0);


            int_拖曳模式 = 拖曳模式.中心;
            bool_初始  = false;

            double L = b_左.Margin.Left + 10;
            double T = b_上.Margin.Top + 10;
            double W = b_右.Margin.Left - b_左.Margin.Left;
            double H = b_下.Margin.Top - b_上.Margin.Top;

            b_中心拖曳.Width  = Math.Abs(W) - 10;
            b_中心拖曳.Height = Math.Abs(H) - 10;
            b_中心拖曳.Margin = new Thickness(L + 5, T + 5, 0, 0);
            rg_遮罩.Rect    = new Rect(L, T, Math.Abs(W) + 1, Math.Abs(H) + 1); //計算遮罩位置

            fun_顯示按鈕();
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        public void func_重新()
        {
            //計算遮罩位置
            rg_遮罩.Rect = new Rect(0, 0, 0, 0);

            b_右上.Margin = new Thickness(-100, 0, 0, 0);
            b_右下.Margin = new Thickness(-100, 0, 0, 0);
            b_左上.Margin = new Thickness(-100, 0, 0, 0);
            b_左下.Margin = new Thickness(-100, 0, 0, 0);

            b_下.Margin = new Thickness(0, -100, 0, 0);
            b_右.Margin = new Thickness(-100, -100, 0, 0);

            bool_初始  = true;
            int_拖曳模式 = 拖曳模式.none;
            t_拖曳中.Start();
            st_按鈕群.Visibility = Visibility.Hidden;
        }
Example #3
0
        /// <summary>
        /// 在全域的鍵盤偵測進行呼叫
        /// </summary>
        /// <param name="e"></param>
        public void func_key_down(System.Windows.Forms.KeyEventArgs e)
        {
            bool bool_ctrl = Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl);

            var k = e.KeyCode;

            if (k == System.Windows.Forms.Keys.Escape)   //按esc結束
            {
                func_關閉程式();
                return;
            }

            if (k == System.Windows.Forms.Keys.C && bool_ctrl) //複製
            {
                e.Handled = true;                              //遮蔽系統原生的快速鍵
                fun_確認儲存("copy");
                return;
            }
            if (k == System.Windows.Forms.Keys.X && bool_ctrl) //複製
            {
                e.Handled = true;                              //遮蔽系統原生的快速鍵
                fun_確認儲存("copy");
                return;
            }

            if (k == System.Windows.Forms.Keys.D && bool_ctrl)  //取消選取
            {
                if (int_拖曳模式 != 拖曳模式.none)
                {
                    func_重新();
                    return;
                }
            }

            if (k == System.Windows.Forms.Keys.S && bool_ctrl)  //直接儲存
            {
                if (int_拖曳模式 != 拖曳模式.none)
                {
                    fun_確認儲存("png");
                    return;
                }
            }

            if (k == System.Windows.Forms.Keys.A && bool_ctrl)  //全選
            {
                func_全選();
                return;
            }


            if (k == System.Windows.Forms.Keys.Enter)  //直接儲存
            {
                if (int_拖曳模式 != 拖曳模式.none)
                {
                    fun_確認儲存("png");
                    return;
                }
                return;
            }

            if (int_拖曳模式 == 拖曳模式.none)
            {
                return;
            }

            //按空白鍵 拖曳
            if (bool_空白鍵記錄 == false)
            {
                if (k == System.Windows.Forms.Keys.Space)
                {
                    bool_空白鍵記錄 = true;
                    d_xywh     = new double[] { b_中心拖曳.Margin.Left, b_中心拖曳.Margin.Top, b_中心拖曳.ActualWidth, b_中心拖曳.ActualHeight };
                    d_滑鼠xy     = func_取得滑鼠();
                    int_空白鍵記錄  = int_拖曳模式;
                    int_拖曳模式   = 拖曳模式.中心;
                }
            }
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        private void func_初始化(e_截圖類型 e_type)
        {
            if (e_type == e_截圖類型.全螢幕截圖_png)
            {
                String s_儲存路徑 = M.func_取得儲存檔名("png");

                //轉換成 rgb24 ,才不會有破圖現象
                var bmpOut = new System.Drawing.Bitmap(bimg.Width, bimg.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                var g      = System.Drawing.Graphics.FromImage(bmpOut);
                g.DrawImage(bimg,
                            new System.Drawing.Rectangle(0, 0, bimg.Width, bimg.Height),
                            new System.Drawing.Rectangle(0, 0, bimg.Width, bimg.Height),
                            System.Drawing.GraphicsUnit.Pixel
                            );
                bmpOut.Save(s_儲存路徑);

                //自動存入剪貼簿
                try {
                    if (M.checkBox_自動存入剪貼簿.IsChecked.Value)
                    {
                        Clipboard.SetData(DataFormats.Bitmap, bimg);
                    }
                } catch { }

                func_關閉程式();
                return;
            }



            st_size與放大鏡.Visibility = Visibility.Hidden;//隱藏szie資訊

            //初始化顏色
            b_上.Fill    = color_原始;
            b_下.Fill    = color_原始;
            b_右.Fill    = color_原始;
            b_左.Fill    = color_原始;
            b_右上.Stroke = color_原始;
            b_右下.Stroke = color_原始;
            b_左上.Stroke = color_原始;
            b_左下.Stroke = color_原始;



            //取得解析度偏差
            PresentationSource source = PresentationSource.FromVisual(M);

            d_解析度比例_x = source.CompositionTarget.TransformToDevice.M11;
            d_解析度比例_y = source.CompositionTarget.TransformToDevice.M22;



            this.Background = new ImageBrush(ToBitmapSource(bimg));//設定背景

            this.Focus();

            //程式最大化
            this.Width  = d_螢幕_w / d_解析度比例_x;
            this.Height = d_螢幕_h / d_解析度比例_y;
            //var Work = System.Windows.Forms.Screen.GetBounds(new System.Drawing.Point((int)this.Left, (int)this.Top));


            //MessageBox.Show(d_螢幕_h + "\n" + System.Windows.Forms.Cursor.Clip.Size.Height + "");


            this.Left = int_螢幕起始坐標_x;
            this.Top  = int_螢幕起始坐標_y;

            //啟動計時器
            t_拖曳中          = new System.Windows.Forms.Timer();
            t_拖曳中.Interval = 10;
            t_拖曳中.Tick    += T_Tick;
            t_拖曳中.Start();
            T_Tick(null, null);//立刻執行,避免使用者開啟截圖後立即點擊

            func_重新();

            Rectangle[] ar = { b_中心拖曳, b_左上, b_上, b_右上, b_右, b_右下, b_下, b_左下, b_左 };

            //滑鼠按下
            for (int i = 0; i < ar.Length; i++)
            {
                ar[i].MouseLeftButtonDown += (object sender, MouseButtonEventArgs e) => {
                    re_目前拖曳物件         = (Rectangle)sender;
                    st_按鈕群.Visibility = Visibility.Hidden;
                    d_滑鼠xy            = func_取得滑鼠();
                    t_拖曳中.Start();
                };
            }


            //滑鼠移入後改變顏色
            for (int i = 0; i < ar.Length; i++)
            {
                ar[i].MouseEnter += (sender, e) => {
                    if (sender == b_上 || sender == b_右 || sender == b_下 || sender == b_左)
                    {
                        if (t_拖曳中.Enabled == false)
                        {
                            ((Rectangle)sender).Fill = color_滑鼠移入;
                        }
                    }
                };
                ar[i].MouseLeave += (sender, e) => {
                    if (sender == b_上 || sender == b_右 || sender == b_下 || sender == b_左)
                    {
                        if (t_拖曳中.Enabled == false)
                        {
                            ((Rectangle)sender).Fill = color_原始;
                        }
                    }
                };
                ar[i].MouseDown += (sender, e) => {
                    if (sender == b_上 || sender == b_右 || sender == b_下 || sender == b_左)
                    {
                        ((Rectangle)sender).Fill = color_滑鼠移入;
                    }
                };

                ar[i].MouseEnter += (sender, e) => {
                    if (sender == b_左上 || sender == b_左下 || sender == b_右上 || sender == b_右下)
                    {
                        if (t_拖曳中.Enabled == false)
                        {
                            ((Rectangle)sender).Stroke = color_滑鼠移入;
                        }
                    }
                };
                ar[i].MouseLeave += (sender, e) => {
                    if (sender == b_左上 || sender == b_左下 || sender == b_右上 || sender == b_右下)
                    {
                        if (t_拖曳中.Enabled == false)
                        {
                            ((Rectangle)sender).Stroke = color_原始;
                        }
                    }
                };
                ar[i].MouseDown += (sender, e) => {
                    if (sender == b_左上 || sender == b_左下 || sender == b_右上 || sender == b_右下)
                    {
                        ((Rectangle)sender).Stroke = color_滑鼠移入;
                    }
                };
            }

            b_中心拖曳.MouseLeftButtonDown += (object sender, MouseButtonEventArgs e) => {
                d_xywh   = new double[] { b_中心拖曳.Margin.Left, b_中心拖曳.Margin.Top, b_中心拖曳.ActualWidth, b_中心拖曳.ActualHeight };
                int_拖曳模式 = 拖曳模式.中心;
            };

            b_上.MouseLeftButtonDown += (object sender, MouseButtonEventArgs e) => {
                d_xywh   = new double[] { b_上.Margin.Left, b_上.Margin.Top, b_上.ActualWidth, b_上.ActualHeight };
                int_拖曳模式 = 拖曳模式.;
            };
            b_下.MouseLeftButtonDown += (object sender, MouseButtonEventArgs e) => {
                d_xywh   = new double[] { b_下.Margin.Left, b_下.Margin.Top, b_下.ActualWidth, b_下.ActualHeight };
                int_拖曳模式 = 拖曳模式.;
            };

            b_右.MouseLeftButtonDown += (object sender, MouseButtonEventArgs e) => {
                d_xywh   = new double[] { b_右.Margin.Left, b_右.Margin.Top, b_右.ActualWidth, b_右.ActualHeight };
                int_拖曳模式 = 拖曳模式.右;
            };
            b_左.MouseLeftButtonDown += (object sender, MouseButtonEventArgs e) => {
                d_xywh   = new double[] { b_左.Margin.Left, b_左.Margin.Top, b_左.ActualWidth, b_左.ActualHeight };
                int_拖曳模式 = 拖曳模式.左;
            };



            b_左上.MouseLeftButtonDown += (object sender, MouseButtonEventArgs e) => {
                d_xywh   = new double[] { b_左上.Margin.Left, b_左上.Margin.Top, b_左上.ActualWidth, b_左上.ActualHeight };
                int_拖曳模式 = 拖曳模式.左上;
            };
            b_右上.MouseLeftButtonDown += (object sender, MouseButtonEventArgs e) => {
                d_xywh   = new double[] { b_右上.Margin.Left, b_右上.Margin.Top, b_右上.ActualWidth, b_右上.ActualHeight };
                int_拖曳模式 = 拖曳模式.右上;
            };
            b_右下.MouseLeftButtonDown += (object sender, MouseButtonEventArgs e) => {
                d_xywh   = new double[] { b_右下.Margin.Left, b_右下.Margin.Top, b_右下.ActualWidth, b_右下.ActualHeight };
                int_拖曳模式 = 拖曳模式.右下;
            };
            b_左下.MouseLeftButtonDown += (object sender, MouseButtonEventArgs e) => {
                d_xywh   = new double[] { b_左下.Margin.Left, b_左下.Margin.Top, b_左下.ActualWidth, b_左下.ActualHeight };
                int_拖曳模式 = 拖曳模式.左下;
            };



            this.MouseLeftButtonUp += (object sender, MouseButtonEventArgs e) => {
                if (rg_遮罩.Rect.Width == 0 || rg_遮罩.Rect.Height == 0)
                {
                    func_重新();
                    return;
                }

                t_拖曳中.Enabled  = false;
                rect_游標.Margin = new Thickness(-100, -100, 0, 0);

                fun_顯示按鈕();
            };



            //第一次拖曳
            this.MouseLeftButtonDown += (object sender, MouseButtonEventArgs e) => {
                if (bool_初始)
                {
                    b_左上.Margin = new Thickness(func_取得滑鼠().X - 10, func_取得滑鼠().Y - 10, 0, 0);

                    d_xywh = new double[] { b_左上.Margin.Left, b_左上.Margin.Top, b_左上.ActualWidth, b_左上.ActualHeight };
                    d_滑鼠xy = func_取得滑鼠();
                    t_拖曳中.Start();
                    int_拖曳模式 = 拖曳模式.右下;
                    bool_初始  = false;
                }
            };



            this.KeyDown += (sender, e) => {
            };
            this.KeyUp   += (object sender, KeyEventArgs e) => {
                //按空白鍵 拖曳
                if (e.Key == Key.Space)
                {
                    bool_空白鍵記錄 = false;

                    Rectangle r = null;
                    if (int_空白鍵記錄 == 拖曳模式.左上)
                    {
                        r = b_左上;
                    }
                    else if (int_空白鍵記錄 == 拖曳模式.右上)
                    {
                        r = b_右上;
                    }
                    else if (int_空白鍵記錄 == 拖曳模式.右下)
                    {
                        r = b_右下;
                    }
                    else if (int_空白鍵記錄 == 拖曳模式.左下)
                    {
                        r = b_左下;
                    }
                    else if (int_空白鍵記錄 == 拖曳模式.)
                    {
                        r = b_上;
                    }
                    else if (int_空白鍵記錄 == 拖曳模式.)
                    {
                        r = b_下;
                    }
                    else if (int_空白鍵記錄 == 拖曳模式.右)
                    {
                        r = b_右;
                    }
                    else if (int_空白鍵記錄 == 拖曳模式.左)
                    {
                        r = b_左;
                    }
                    else
                    {
                        return;
                    }

                    d_xywh = new double[] { r.Margin.Left, r.Margin.Top, r.ActualWidth, r.ActualHeight };
                    d_滑鼠xy = func_取得滑鼠();

                    int_拖曳模式   = int_空白鍵記錄;
                    this.Title = "**";
                }
            };


            //右鍵 結束
            this.MouseRightButtonUp += (object sender, MouseButtonEventArgs e) => {
                if (int_拖曳模式 == 拖曳模式.none)
                {
                    func_關閉程式();
                }
                else
                {
                    func_重新();
                }
            };

            button_關閉.Click += (sender, e) => {
                func_關閉程式();
            };

            button_重新.Click += (sender, e) => {
                func_重新();
            };

            button_確認_png.Click += (sender, e) => {
                fun_確認儲存("png");
            };
            button_確認_jpg.Click += (sender, e) => {
                fun_確認儲存("jpg");
            };
            button_確認_copy.Click += (sender, e) => {
                fun_確認儲存("copy");
            };

            button_編輯.Click += (sender, e) => {
                fun_確認儲存("edit");
            };

            but_複製顏色_16.Click += (sender, e) => {
                Clipboard.SetText(lab_複製顏色_16.Content + "");
                func_關閉程式();
            };
            but_複製顏色_rgb.Click += (sender, e) => {
                Clipboard.SetText(lab_複製顏色_rgb.Content + "");
                func_關閉程式();
            };
        }