1
 <Grid x:Name="LayoutRoot" Background="White">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="800"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="0.865*"/>
            <RowDefinition Height="0.135*"/>
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="1" Orientation="Vertical" HorizontalAlignment="Left" Background="#FFE7E7E7" Width="420" Margin="78,0,0,21">
            <StackPanel Orientation="Horizontal">
                <Rectangle x:Name="rect0" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect0_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect1" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect1_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect2" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect2_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect3" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect3_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect4" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect4_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect5" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect5_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect6" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect6_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect7" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect7_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect8" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect8_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect9" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect9_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect10" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect10_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect11" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect11_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect12" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect12_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect13" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect13_MouseLeftButtonDown"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" >
                <Rectangle x:Name="rect14" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect14_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect15" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect15_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect16" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect16_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect17" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect17_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect18" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect18_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect19" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect19_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect20" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect20_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect21" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect21_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect22" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect22_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect23" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect23_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect24" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect24_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect25" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect25_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect26" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect26_MouseLeftButtonDown"/>
                <Rectangle x:Name="rect27" Height="30" Width="30" Stroke="#FF000000" StrokeThickness="3" MouseLeftButtonDown="rect27_MouseLeftButtonDown"/>
            </StackPanel>
        </StackPanel>
        <Canvas Grid.Row="1" Background="#FFF2F2F2" Width="78" HorizontalAlignment="Left">
            <Rectangle Height="67" x:Name="rectFront" Width="70" Fill="#FF000000" Stroke="#FFB9B9B9" StrokeThickness="3" StrokeLineJoin="Miter" StrokeStartLineCap="Flat" Stretch="Uniform" Canvas.Left="4"/>
        </Canvas>
        <Slider x:Name="BrushSize" HorizontalAlignment="Right" Margin="0,18,86,39" Width="90" Grid.Row="1"/>
        <TextBlock Height="13" HorizontalAlignment="Right" VerticalAlignment="Top" Width="59" FontSize="10" Text="Size" TextWrapping="Wrap" Grid.Row="1" Margin="0,5,86,0"/>
        <Slider x:Name="BrushOpacity" HorizontalAlignment="Right" Margin="0,0,86,5" Width="90" Grid.Row="1" VerticalAlignment="Bottom" Height="20"/>
        <TextBlock HorizontalAlignment="Right" Margin="0,0,86,25" Width="59" FontSize="10" Text="Opacity" TextWrapping="Wrap" Grid.Row="1" Height="14" VerticalAlignment="Bottom"/>
        <RadioButton x:Name="RadioRound" Height="18" HorizontalAlignment="Right" Margin="0,5,188,0" VerticalAlignment="Top" Width="101" Grid.Row="1" Content="Round" IsChecked="True"/>
        <RadioButton x:Name="RadioSquare" HorizontalAlignment="Right" Margin="0,23,188,39" Width="101" Grid.Row="1" Content="Square" />
        <RadioButton x:Name="RadioTriangle" HorizontalAlignment="Right" Margin="0,0,188,21" Width="101" Grid.Row="1" Content="Triangle" VerticalAlignment="Bottom" Height="18" />
        <RadioButton x:Name="RadioFlat" HorizontalAlignment="Right" Margin="0,0,188,3" Width="101" Grid.Row="1" Content="Flat" Height="18" VerticalAlignment="Bottom" />
        <Button x:Name="btnClear" HorizontalAlignment="Right" Margin="0,4,2,12" Width="74" Grid.Row="1" Content="Clear" Click="btnClear_Click" ToolTipService.ToolTip="Click to Clear the Drawing"/>
        <Grid x:Name="DrawingArea" Margin="0,0,-5,8" MouseMove="DrawingArea_MouseMove" MouseLeftButtonDown="DrawingArea_MouseLeftButtonDown" MouseLeftButtonUp="DrawingArea_MouseLeftButtonUp" Background="#FFFFFFFF"/>
    </Grid>
</UserControl>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace PaintApp4thApril
{
    public partial class MainPage : UserControl
    {
        Point pt;
        Point ptOld1;
        Point ptOld2;
        Point ptOld3;
        Point ptOld4;
        Point ptOld5;
        bool MouseDraw = false;
        Line Line1;

        public MainPage()
        {
            InitializeComponent();

            rect0.Fill = new SolidColorBrush(Color.FromArgb(100, 0, 0, 0));
            rect1.Fill = new SolidColorBrush(Color.FromArgb(100, 128, 128, 128));
            rect2.Fill = new SolidColorBrush(Color.FromArgb(100, 128, 0, 0));
            rect3.Fill = new SolidColorBrush(Color.FromArgb(100, 128, 128, 0));
            rect4.Fill = new SolidColorBrush(Color.FromArgb(100, 0, 128, 0));
            rect5.Fill = new SolidColorBrush(Color.FromArgb(100, 0, 128, 128));
            rect6.Fill = new SolidColorBrush(Color.FromArgb(100, 0, 0, 128));
            rect7.Fill = new SolidColorBrush(Color.FromArgb(100, 128, 0, 128));
            rect8.Fill = new SolidColorBrush(Color.FromArgb(100, 128, 128, 64));
            rect9.Fill = new SolidColorBrush(Color.FromArgb(100, 0, 64, 64));
            rect10.Fill = new SolidColorBrush(Color.FromArgb(100, 0, 128, 255));
            rect11.Fill = new SolidColorBrush(Color.FromArgb(100, 0, 64, 128));
            rect12.Fill = new SolidColorBrush(Color.FromArgb(100, 128, 0, 255));
            rect13.Fill = new SolidColorBrush(Color.FromArgb(100, 128, 64, 0));

            rect14.Fill = new SolidColorBrush(Color.FromArgb(100, 255, 255, 255));
            rect15.Fill = new SolidColorBrush(Color.FromArgb(100, 192, 192, 192));
            rect16.Fill = new SolidColorBrush(Color.FromArgb(100, 255, 0, 0));
            rect17.Fill = new SolidColorBrush(Color.FromArgb(100, 255, 255, 0));
            rect18.Fill = new SolidColorBrush(Color.FromArgb(100, 0, 255, 0));
            rect19.Fill = new SolidColorBrush(Color.FromArgb(100, 0, 255, 255));
            rect20.Fill = new SolidColorBrush(Color.FromArgb(100, 0, 0, 255));
            rect21.Fill = new SolidColorBrush(Color.FromArgb(100, 255, 0, 255));
            rect22.Fill = new SolidColorBrush(Color.FromArgb(100, 255, 255, 128));
            rect23.Fill = new SolidColorBrush(Color.FromArgb(100, 0, 255, 128));
            rect24.Fill = new SolidColorBrush(Color.FromArgb(100, 128, 255, 255));
            rect25.Fill = new SolidColorBrush(Color.FromArgb(100, 128, 128, 255));
            rect26.Fill = new SolidColorBrush(Color.FromArgb(100, 255, 0, 128));
            rect27.Fill = new SolidColorBrush(Color.FromArgb(100, 255, 128, 64));

            ptOld1 = pt;
            ptOld2 = ptOld1;
            ptOld3 = ptOld2;
            ptOld4 = ptOld3;
            ptOld5 = ptOld4;
            BrushSize.Minimum = 1;
            BrushSize.Maximum = 30;
            BrushSize.Value = 10;
            BrushOpacity.Minimum = 0.1;
            BrushOpacity.Maximum = 1;
            BrushOpacity.Value = 1;
        }

        private void DrawShapeType()
        {
            if (RadioRound.IsChecked == true)
            {
                Line1.StrokeStartLineCap = PenLineCap.Round;
                Line1.StrokeEndLineCap = PenLineCap.Round;
            }
            else if (RadioSquare.IsChecked == true)
            {
                Line1.StrokeStartLineCap = PenLineCap.Square;
                Line1.StrokeEndLineCap = PenLineCap.Square;
            }
            else if (RadioTriangle.IsChecked == true)
            {
                Line1.StrokeStartLineCap = PenLineCap.Triangle;
                Line1.StrokeEndLineCap = PenLineCap.Triangle;
            }
            else if (RadioFlat.IsChecked == true)
            {
                Line1.StrokeStartLineCap = PenLineCap.Flat;
                Line1.StrokeEndLineCap = PenLineCap.Flat;
            }
        }

        #region Rectangle Colors
        private void rect0_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect0.Fill;
        }

        private void rect1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect1.Fill;
        }

        private void rect2_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect2.Fill;
        }

        private void rect3_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect3.Fill;
        }

        private void rect4_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect4.Fill;
        }

        private void rect5_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect5.Fill;
        }

        private void rect6_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect6.Fill;
        }

        private void rect7_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect7.Fill;
        }

        private void rect8_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect8.Fill;
        }

        private void rect9_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect9.Fill;
        }

        private void rect10_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect10.Fill;
        }

        private void rect11_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect11.Fill;
        }

        private void rect12_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect12.Fill;
        }

        private void rect13_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect13.Fill;
        }

        private void rect14_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect14.Fill;
        }

        private void rect15_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect15.Fill;
        }

        private void rect16_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect16.Fill;
        }

        private void rect17_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect17.Fill;
        }

        private void rect18_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect18.Fill;
        }

        private void rect19_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect19.Fill;
        }

        private void rect20_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect20.Fill;
        }

        private void rect21_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect21.Fill;
        }

        private void rect22_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect22.Fill;
        }

        private void rect23_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect23.Fill;
        }

        private void rect24_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect24.Fill;
        }

        private void rect25_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect25.Fill;
        }

        private void rect26_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect26.Fill;
        }

        private void rect27_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            rectFront.Fill = rect27.Fill;
        }
        #endregion

        private void btnClear_Click(object sender, RoutedEventArgs e)
        {
            DrawingArea.Children.Clear();
        }

        private void DrawingArea_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            MouseDraw = false;
        }

        private void DrawingArea_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            pt = e.GetPosition(DrawingArea);
            ptOld1 = pt;
            MouseDraw = true;
        }

        private void DrawingArea_MouseMove(object sender, MouseEventArgs e)
        {
            if (MouseDraw)
            {
                pt = e.GetPosition(DrawingArea);
                Line1 = new Line();
                Line1.X1 = pt.X;
                Line1.Y1 = pt.Y;
                Line1.X2 = ptOld1.X;
                Line1.Y2 = ptOld1.Y;

                Line1.Stroke = rectFront.Fill;

                DrawShapeType();

                Line1.StrokeThickness = BrushSize.Value;
                Line1.Opacity = BrushOpacity.Value;
                DrawingArea.Children.Add(Line1);
                ptOld1 = pt;
            }
            ptOld1 = pt;
        }

    }
}

我需要添加一个橡皮擦功能。如何调整此窗口(网格)的大小,以便在我运行应用程序时,它适合浏览器窗口?

另外,我在 Asp.net 上创建了一个简单的网站。我需要当我单击该网站上的链接按钮时,此绘图应用程序会打开。它们都是独立的项目。我怎样才能做到这一点?绘画应用程序是使用 Blend 设计的,是一个 Silverlight 应用程序,而简单网站是在 Asp.net (Visual Studio 2015) 中创建的。

如何将图像保存到 sqlserver 数据库?

4

0 回答 0