WPF拖动绘制
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Shapes;
using System.Windows.Media; namespace BrawDraw.Com.HandleAnEvent
{
class HandleAnEvent
{
[STAThread]
public static void Main()
{
Application app = new Application();
Window win = new Window();
win.Title = "Handle An Event";
win.MouseDown += WindowOnMouseDown;
win.MouseMove += WindowOnMouseMove;
win.MouseUp += WindowOnMouseUp; app.Run(win);
} static Point startPoint;
static Point endPoint;
static bool isCapture = false; static void WindowOnMouseDown(object sender, MouseButtonEventArgs args)
{
Window win = sender as Window;
startPoint = args.GetPosition(win);
isCapture = true;
} static void WindowOnMouseMove(object sender, MouseEventArgs args)
{
endPoint = args.GetPosition(sender as Window);
if (isCapture)
{
DrawRectangle(sender); //这里隐藏与不隐藏时差别很大,特别是鼠标的最后位置与开始位置的相对位移为负时,特征更加明显。
}
} static void WindowOnMouseUp(object sender, MouseButtonEventArgs args)
{
isCapture = false;
DrawRectangle(sender);
} static void DrawRectangle(object sender)
{
#region DoStartEndPointPlace
Point tmpPoint = startPoint;
if (endPoint.X < startPoint.X)
{
startPoint.X = endPoint.X;
endPoint.X = tmpPoint.X;
}
if (endPoint.Y < startPoint.Y)
{
startPoint.Y = endPoint.Y;
endPoint.Y = tmpPoint.Y;
}
#endregion DoStartEndPointPlace Window win = sender as Window;
Rectangle rect = new Rectangle();
rect.Stroke = Brushes.Black;
rect.Fill = Brushes.SkyBlue;
rect.HorizontalAlignment = HorizontalAlignment.Left;
rect.VerticalAlignment = VerticalAlignment.Center;
rect.Height = Math.Abs(endPoint.Y - startPoint.Y);
rect.Width = Math.Abs(endPoint.X - startPoint.X);
Canvas canvas = new Canvas();
Canvas.SetLeft(rect, startPoint.X);
Canvas.SetTop(rect, startPoint.Y);
canvas.Children.Add(rect);
win.Content = canvas;
}
}
}
WPF拖动绘制的更多相关文章
- wpf 后台绘制圆弧
wpf 前台绘制圆弧很简单,如:<Path x:Name="path_data" Stroke="#FFE23838" StrokeThickness=& ...
- WPF拖动总结[转载]
WPF拖动总结 这篇博文总结下WPF中的拖动,文章内容主要包括: 1.拖动窗口 2.拖动控件 Using Visual Studio 2.1thumb控件 2.2Drag.Drop(不连续,没有中 ...
- WPF拖动DataGrid滚动条时内容混乱的解决方法
WPF拖动DataGrid滚动条时内容混乱的解决方法 在WPF中,如果DataGrid里使用了模板列,当拖动滚动条时,往往会出现列表内容显示混乱的情况.解决方法就是在Binding的时候给Update ...
- 用canvas实现鼠标拖动绘制矩形框
需要用到jCanvas插件和jQuery. jCanvas下载:https://raw.githubusercontent.com/caleb531/jcanvas/master/jcanvas.mi ...
- C#WPF 如何绘制几何图形 图示教程 绘制sin曲线 正弦 绘制2D坐标系 有图有代码
原文:C#WPF 如何绘制几何图形 图示教程 绘制sin曲线 正弦 绘制2D坐标系 有图有代码 C#WPF 如何绘制几何图形? 怎么绘制坐标系?绘制sin曲线(正弦曲线)? 这离不开Path(Syst ...
- WPF 图形绘制 及各种线帽、箭头的实现
原文:WPF 图形绘制 及各种线帽.箭头的实现 /// <summary> /// 矩形类 /// </summary> public sealed ...
- WPF特效-绘制实时2D激光雷达图
原文:WPF特效-绘制实时2D激光雷达图 接前两篇: https://blog.csdn.net/u013224722/article/details/80738619 https://blog.cs ...
- 【C#】第3章补充(一)如何在WPF中绘制正弦曲线
分类:C#.VS2015 创建日期:2016-06-19 使用教材:(十二五国家级规划教材)<C#程序设计及应用教程>(第3版) 一.要点 本例子提前使用了教材第13章介绍的基本知识. 二 ...
- 在WPF中绘制多维数据集
原文 https://stuff.seans.com/2008/08/13/drawing-a-cube-in-wpf/ 是时候使用WPF绘制一个简单的3D对象了.作为WPF中3D图形的快速介绍,让我 ...
随机推荐
- JAVA编程心得-多态设计初步
面向对象的思想中,封装,继承,多态作为特性会在开发中广泛应用,一个健壮的系统除了功能强大以外,它的可扩展性应该也很强,多态恰好应用了这个思路. 下面我以杨小聪去某地的方式为例,我们知道首先杨小聪要去某 ...
- android中利用实现二级联动的效果
按照惯例,首先上一张效果图. 本篇文章实现的效果就是如图中所圈的那样,实现类似于HTML中的二级联动的效果. 对于第一个选项我们读取的是本地xml文件来填充数据的, 对于第二个选项我们读取的是通过中央 ...
- 转:ORACLEERP开发基础之EBS开发基础
转自:http://blog.itpub.net/8781091/viewspace-1012244/ [内容导航] 第1页:开发工具安装 第2页:增加数据块 第3页:注册表单FORM 第4页:注册请 ...
- c语言,strcat(),字符串拼接
#include<stdio.h> #include<string.h> int main() { char destination[25]; char *zhang=& ...
- 【排障】每次打开word都提示要安装配置
为什么每次打开word都提示要安装配置?很多人在打开word时,总是提示要安装配置一遍,花去不少时间,这是由于电脑里有两个不同版本的office软件,产生的原因可能是原来的卸载了没卸载干净,或是安装了 ...
- xilinx仿真库的作用(原创)
① secureip库:硬核(HARD IP)仿真(功能仿真和时序仿真)模型(hard IP simulation model),比如PowerPC.PCIE.SRIO.DDR等.Simulation ...
- PHP 概述 特点 基础语法
PHP是什么 http://php.net/manual/zh/intro-whatis.php#intro-whatis PHP(Hypertext Preprocessor,超文本预处理器)是一 ...
- JQuery设置缓慢下拉大行多次执行的解决办法,以及stop()函数的简单理解
$(function(){ $('.all>li').mouseover(function(e) { $(this).children().stop().slideDown(300 ...
- Activiti工作流引擎使用
http://www.kafeitu.me/activiti/2012/03/22/workflow-activiti-action.html 1.简单介工作流引擎与Activiti 对于工作流引擎的 ...
- Asp.Net Core简单整理
1.Asp.NetCore 中文入门文档 http://www.cnblogs.com/dotNETCoreSG/p/aspnetcore-index.html