本文主要是介绍C#自定义控件的放置与拖动,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、自定义控件
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace PartApp.Uc
{public class And:Control{private bool dragging = false;private Point dragCursorPoint;private Point dragFormPoint;public And(){SetStyle(ControlStyles.OptimizedDoubleBuffer, true);this.MouseUp += And_MouseUp;this.MouseMove += And_MouseMove;this.MouseDown += And_MouseDown;}private void And_MouseDown(object sender, MouseEventArgs e){dragging = true;dragCursorPoint = Cursor.Position;dragFormPoint = this.Location;}private void And_MouseMove(object sender, MouseEventArgs e){if (dragging){Point dif = Point.Subtract(Cursor.Position, new Size(dragCursorPoint));this.Location
这篇关于C#自定义控件的放置与拖动的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!