Winform 自定义Panel
来源:互联网 发布:口算题出题系统 mac 编辑:程序博客网 时间:2024/06/16 05:53
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TomWinform.CustomerControl
{
public partial class DragPanel : Panel
{
private Color borderColor = Color.Black;
private float borderSize = 1;
private Point point;
public DragPanel()
{
InitializeComponent();
this.MouseDown += new MouseEventHandler(DragMouseDown);
this.MouseMove += new MouseEventHandler(DragMouseMove);
this.MouseUp += new MouseEventHandler(DragMouseUp);
}
protected override void OnPaint(PaintEventArgs pe)
{
DrawBorder(pe);
base.OnPaint(pe);
}
private void DragMouseDown(object sender, MouseEventArgs e)
{
if (e.Y > 0 && e.Y < 50)
{
this.Cursor = Cursors.SizeAll;
point.X = e.X;
point.Y = e.Y;
}
}
private void DragMouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (e.Y > 0 && e.Y < 50)
{
this.Left = (e.X - point.X) + this.Left;
this.Top = (e.Y - point.Y) + this.Top;
}
}
}
private void DragMouseUp(object sender, MouseEventArgs e)
{
this.Cursor = Cursors.Arrow;
}
//画边框
private void DrawBorder(PaintEventArgs pe)
{
Graphics g = pe.Graphics;
Pen pen = new Pen(borderColor, borderSize);
Point[] point = new Point[4];
point[0] = new Point(0, 0);
point[1] = new Point(this.Width - 1, 0);
point[2] = new Point(this.Width - 1, this.Height - 1);
point[3] = new Point(0, this.Height - 1);
g.DrawPolygon(pen, point);
}
#region 属性
[Description("边框颜色"), Category("自定义属性")]
public Color BorderColor
{
get { return borderColor; }
set { borderColor = value; this.Invalidate(); }
}
[Description("边框宽度"), Category("自定义属性")]
public float BorderSize
{
get { return borderSize; }
set { borderSize = value; this.Invalidate(); }
}
#endregion
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TomWinform.CustomerControl
{
public partial class DragPanel : Panel
{
private Color borderColor = Color.Black;
private float borderSize = 1;
private Point point;
public DragPanel()
{
InitializeComponent();
this.MouseDown += new MouseEventHandler(DragMouseDown);
this.MouseMove += new MouseEventHandler(DragMouseMove);
this.MouseUp += new MouseEventHandler(DragMouseUp);
}
protected override void OnPaint(PaintEventArgs pe)
{
DrawBorder(pe);
base.OnPaint(pe);
}
private void DragMouseDown(object sender, MouseEventArgs e)
{
if (e.Y > 0 && e.Y < 50)
{
this.Cursor = Cursors.SizeAll;
point.X = e.X;
point.Y = e.Y;
}
}
private void DragMouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (e.Y > 0 && e.Y < 50)
{
this.Left = (e.X - point.X) + this.Left;
this.Top = (e.Y - point.Y) + this.Top;
}
}
}
private void DragMouseUp(object sender, MouseEventArgs e)
{
this.Cursor = Cursors.Arrow;
}
//画边框
private void DrawBorder(PaintEventArgs pe)
{
Graphics g = pe.Graphics;
Pen pen = new Pen(borderColor, borderSize);
Point[] point = new Point[4];
point[0] = new Point(0, 0);
point[1] = new Point(this.Width - 1, 0);
point[2] = new Point(this.Width - 1, this.Height - 1);
point[3] = new Point(0, this.Height - 1);
g.DrawPolygon(pen, point);
}
#region 属性
[Description("边框颜色"), Category("自定义属性")]
public Color BorderColor
{
get { return borderColor; }
set { borderColor = value; this.Invalidate(); }
}
[Description("边框宽度"), Category("自定义属性")]
public float BorderSize
{
get { return borderSize; }
set { borderSize = value; this.Invalidate(); }
}
#endregion
}
}
阅读全文
0 0
- winform自定义panel控件
- Winform 自定义Panel
- Winform 使用panel 自定义拖动窗体
- c# winForm 圆角Panel
- panel 显示winform
- Winform Panel按钮位置
- c# winForm 圆角Panel
- 把winform放到panel中
- Winform的Panel绘制边框
- android之自定义Panel
- 自定义面板类Panel
- Flex4 创建自定义Panel
- InstallAnywhere的自定义PANEL
- C# winform Panel 获取滚轮事件
- C# winform 运行时panel 如何拖动
- C# WinForm开发系列 - ListBox/ListView/Panel
- C# WinForm开发系列 - ListBox/ListView/Panel
- winform 移动窗口中的控件,panel
- 第二章 命名的意义
- 【第1125期】GraphQL 技术栈揭秘
- 总结1
- linux硬链接与软链接
- Codeforces-891A Pride(GCD&&思维)
- Winform 自定义Panel
- Webstorm快捷键、自动补全
- Centos 7 环境下将修改后的MAC地址永久保存
- 微信小程序/下拉选择
- JAVA中转发和重定向的区别
- LR乱码处理
- 1021. 个位数统计 (15)
- 设置eclipse启动时使用jdk的版本
- Winform 自定义文本框