wpf简单的绘图板-阿里云开发者社区

开发者社区> 开发与运维> 正文
登录阅读全文

wpf简单的绘图板

简介: 原文:wpf简单的绘图板 版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/a771948524/article/details/9323121 ...
原文:wpf简单的绘图板

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/a771948524/article/details/9323121

xaml:

<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="418" Width="525">
    <DockPanel LastChildFill="True">
        <StackPanel MinWidth="100" DockPanel.Dock="Left">
            <TextBlock HorizontalAlignment="Center">editing mode</TextBlock>
            <Button x:Name="btnselection" Margin="5" Click="btnselection_Click">selection</Button>
            <Button x:Name="btndraw" Margin="5" Click="btndraw_Click">draw</Button>
            <Button x:Name="btnerase" Margin="5" Click="btnerase_Click">erase</Button>

            <TextBlock HorizontalAlignment="Center">choss color:</TextBlock>
            <Ellipse x:Name="rectred" Fill="Red" MinHeight="50" Margin="5" MouseDown="rectred_MouseDown"></Ellipse>
            <Ellipse x:Name="rectgreen" Fill="Green" MinHeight="50" Margin="5" MouseDown="rectgreen_MouseDown"></Ellipse>
            <Ellipse x:Name="rectblue" Fill="Blue" MinHeight="50" Margin="5" MouseDown="rectblue_MouseDown"></Ellipse>
            <Ellipse x:Name="rectyellow" Fill="Yellow" MinHeight="50" Margin="5"></Ellipse>
        </StackPanel>
        <InkCanvas x:Name="inkcanvas1" EditingMode="Ink" ClipToBounds="True">
            
        </InkCanvas>
    </DockPanel>
</Window>

 

后台:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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 WpfApplication1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
 
        }

        private void btnerase_Click(object sender, RoutedEventArgs e)
        {
            inkcanvas1.EditingMode = System.Windows.Controls.InkCanvasEditingMode.EraseByPoint;
        }

        private void rectred_MouseDown(object sender, MouseButtonEventArgs e)
        {
            inkcanvas1.DefaultDrawingAttributes.Color = System.Windows.Media.Colors.Red;
        }

        private void btndraw_Click(object sender, RoutedEventArgs e)
        {
            inkcanvas1.EditingMode = System.Windows.Controls.InkCanvasEditingMode.Ink;
        }

        private void rectgreen_MouseDown(object sender, MouseButtonEventArgs e)
        {
            inkcanvas1.DefaultDrawingAttributes.Color = System.Windows.Media.Colors.Green;
        }

        private void rectblue_MouseDown(object sender, MouseButtonEventArgs e)
        {
            inkcanvas1.DefaultDrawingAttributes.Color = System.Windows.Media.Colors.Blue;
        }

        private void rectyellow_MouseDown(object sender, MouseButtonEventArgs e)
        {
            inkcanvas1.DefaultDrawingAttributes.Color = System.Windows.Media.Colors.Yellow;
;
        }

        private void btnselection_Click(object sender, RoutedEventArgs e)
        {
            inkcanvas1.EditingMode = System.Windows.Controls.InkCanvasEditingMode.Select;
        }


    }
}


 

效果:

 

 

 

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

其他文章