123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- using PDF_Office.CustomControl.ScanViewControl;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace PDF_Office.Views.Scan
- {
- /// <summary>
- /// ScanViwer.xaml 的交互逻辑
- /// </summary>
- public partial class ScanViwer : UserControl
- {
- public ScanViwer()
- {
- InitializeComponent();
- }
- double scale = 1;
- private void Grid_MouseWheel(object sender, MouseWheelEventArgs e)
- {
- if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
- {
- if (e.Delta > 0)
- {
- scale += 0.1;
- ImageGrid.Width = 500 * scale;
- ImageGrid.Height = 500 * scale;
- }
- else
- {
- if (scale > 0.2)
- {
- scale -= 0.2;
- }
- ImageGrid.Width = 500 * scale;
- ImageGrid.Height = 500 * scale;
- }
- }
- RedressControl.Visibility = Visibility.Collapsed;
- }
- private Point MouseDownPos;
- bool dowm = false;
- bool CreateNewRect = false;
- private async void CustomPanel_MouseDown(object sender, MouseButtonEventArgs e)
- {
- RedressControl.Visibility = Visibility.Visible;
- MouseDownPos = e.GetPosition(BitmapPanel);
- HitTestResult hitResult = VisualTreeHelper.HitTest(BitmapPanel, MouseDownPos);
- if (hitResult != null && hitResult.VisualHit is CustomDraw)
- {
- CustomDraw hitChild = (CustomDraw)hitResult.VisualHit;
- BitmapPanel.DisplayContent(hitChild);
- RedressControl.SetValue(Canvas.LeftProperty, hitChild.PaintRect.Left + (hitChild.PaintRect.Width / 2 - RedressControl.ActualWidth / 2));
- if (hitChild.PaintRect.Top - RedressControl.ActualHeight > 0)
- {
- RedressControl.SetValue(Canvas.TopProperty, hitChild.PaintRect.Top - RedressControl.ActualHeight);
- }
- else
- {
- RedressControl.SetValue(Canvas.TopProperty, hitChild.PaintRect.Bottom);
- }
- RedressControl.HitChild = hitChild;
- RedressControl.TextBoxContext = hitChild.PaintText;
- await Task.Delay(5);
- RedressControl.SelectAll();
- return;
- }
- RedressControl.Visibility = Visibility.Collapsed;
- }
- private void RedressControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
- {
- if (!(bool)e.NewValue)
- {
- BitmapPanel.DisplayContent(null);
- }
- }
- private void RedressControl_ApplyCommandHandler(object sender, EventArgs e)
- {
- RedressControl.HitChild.PaintText = RedressControl.TextBoxContext;
- RedressControl.HitChild.Draw();
- RedressControl.Visibility = Visibility.Collapsed;
- }
- private void BitmapPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- Point clickPoint = e.GetPosition(BitmapPanel);
- dowm = true;
- if (!BitmapPanel.RectMouseLeftButtonDown(clickPoint) && BitmapPanel.DrawRect.Contains(clickPoint))
- {
- BitmapPanel.RectSetMaxRect(BitmapPanel.DrawRect);
- CreateNewRect = true;
- }
- }
- private void BitmapPanel_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
- {
- dowm = false;
- CreateNewRect = false;
- }
- private void BitmapPanel_MouseMove(object sender, MouseEventArgs e)
- {
- Point currentPos = e.GetPosition(BitmapPanel);
- if (dowm && BitmapPanel.DrawRect.Contains(currentPos))
- {
- if (CreateNewRect)
- {
- Rect drawRect = new Rect(MouseDownPos, currentPos);
- BitmapPanel.SetRect(drawRect);
- BitmapPanel.RectDraw();
- }
- else
- {
- BitmapPanel.RectMouseMove(currentPos);
- }
- }
- }
- }
- }
|