首页 新闻 搜索 专区 学院

wpf InkCanvas

0
悬赏园豆:10 [已解决问题] 解决于 2016-03-02 16:55

想在 InkCanvas 上实现向QQ截图涂鸦那个可以画箭头的那中怎么做?像这种的。

豌豆夹的主页 豌豆夹 | 初学一级 | 园豆:6
提问于:2016-03-02 15:11
< >
分享
最佳答案
0

后台代码

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;
using Microsoft.Expression.Shapes;

namespace WpfApplication1
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
private Boolean isdraw = false;
Point[] p = new Point[2];
public MainWindow()
{
InitializeComponent();
}

private void Button_Click(object sender, RoutedEventArgs e)
{
isdraw = true;
}

private void InkCanvas_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed&&isdraw)
{
p[0] = e.GetPosition(canvas);
}
}

private void InkCanvas_MouseUp(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Released&&isdraw)
{
p[1] = e.GetPosition(canvas);
BlockArrow b = new BlockArrow();
b.Fill = Brushes.Red;
this.canvas.Children.Add(b);
b.Margin = new Thickness(p[0].X, p[0].Y, canvas.ActualWidth - p[0].X, canvas.ActualHeight - p[0].Y);
double w = Math.Abs(p[0].X - p[1].X);
double h = Math.Abs(p[0].Y - p[1].Y);
b.Width = Math.Sqrt(w * w + h * h);
b.Height = 10;
b.RenderTransform = new RotateTransform(Math.Atan2((p[1].Y - p[0].Y), (p[1].X - p[0].X))*180/Math.PI);
isdraw = false;
}
}
}
}

前台代码

<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<InkCanvas Name="canvas" Grid.Row="0" PreviewMouseDown="InkCanvas_MouseDown" MouseUp="InkCanvas_MouseUp">

</InkCanvas>
<Button Grid.Row="1" Content="画箭头" Click="Button_Click">

</Button>
</Grid>
</Window>

写了一个DEMO  你看看 这只是一个思路 这个DEMO没有屏蔽画箭头时候的自带划线 也没有预览功能 箭头是一个现成的对象  你可以看看这样的思路是否可以

收获园豆:10
我丫的是条鱼 | 菜鸟二级 |园豆:240 | 2016-03-02 16:39

很有帮助,谢谢!!!!

豌豆夹 | 园豆:6 (初学一级) | 2016-03-02 16:54
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册