📄 newcontrol.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Threading;
using System.Runtime.InteropServices;
namespace NewControl
{
public partial class JPM_ImageButton : System.Windows.Forms.PictureBox
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
System.Drawing.Bitmap _imageNormal;
System.Drawing.Bitmap _imageMove;
System.Drawing.Bitmap _imageDown;
System.Drawing.Bitmap _imageUp;
public System.Drawing.Image ImageNormal
{
set
{
_imageNormal = (System.Drawing.Bitmap)value;
this.Invalidate();
}
get
{
return _imageNormal;
}
}
public System.Drawing.Image ImageMove
{
set
{
_imageMove = (System.Drawing.Bitmap)value;
}
get
{
return _imageMove;
}
}
public System.Drawing.Image ImageDown
{
set
{
_imageDown = (System.Drawing.Bitmap)value;
}
get
{
return _imageDown;
}
}
public System.Drawing.Image ImageUp
{
set
{
_imageUp = (System.Drawing.Bitmap)value;
}
get
{
return _imageUp;
}
}
/// <summary>
/// 构建一个空Image以防止引用空的_imageOnMouseMove
/// </summary>
public JPM_ImageButton()
{
_imageNormal = null;
_imageMove = null;
_imageDown = null;
_imageUp = null;
}
protected override void Dispose(bool disposing)
{
if (disposing == true)
{
if (_imageNormal != null)
{
_imageNormal.Dispose();
}
if (_imageMove != null)
{
_imageMove.Dispose();
}
if (_imageDown != null)
{
_imageDown.Dispose();
}
if (_imageUp != null)
{
_imageUp.Dispose();
}
}
base.Dispose(disposing);
}
protected override void OnPaint(PaintEventArgs pe)
{
if (this.Image == null)
{
this.Image = _imageNormal;
}
base.OnPaint(pe);
}
protected override void OnMouseEnter(EventArgs e)
{
if (this.IsDisposed == false && _imageMove != null)
{
Image = (System.Drawing.Bitmap)_imageMove;
}
this.Cursor = global::System.Windows.Forms.Cursors.Hand;
}
protected override void OnMouseDown(MouseEventArgs e)
{
if (this.IsDisposed == false && _imageDown != null)
{
Image = (System.Drawing.Image)_imageDown;
}
}
protected override void OnMouseUp(MouseEventArgs e)
{
if (this.IsDisposed == false)
{
if (_imageUp != null)
{
Image = (System.Drawing.Image)_imageUp;
}
else if (_imageNormal != null)
{
Image = (System.Drawing.Image)_imageNormal;
}
}
}
protected override void OnMouseLeave(System.EventArgs e)
{
if (this.IsDisposed == false && _imageNormal != null)
{
Image = (System.Drawing.Image)_imageNormal;
}
this.Cursor = global::System.Windows.Forms.Cursors.Default;
}
}
public class JPM_CartoonImageBox : System.Windows.Forms.Control
{
Bitmap _image;
public JPM_CartoonImageBox()
{
this.BackColor = Color.White;
_image = null;
}
protected override void Dispose(bool disposing)
{
if (disposing == true)
{
if (_image != null)
{
_image.Dispose();
}
}
base.Dispose(disposing);
}
public System.Drawing.Image Image
{
set
{
_image = (System.Drawing.Bitmap)value;
this.Invalidate();
}
get
{
return _image;
}
}
protected override void OnPaint(PaintEventArgs e)
{
if (_image == null)
{
return;
}
try
{
SolidBrush t_sbBG = new SolidBrush(this.BackColor);
e.Graphics.FillRectangle(t_sbBG, new Rectangle(0, 0, this.Width, this.Height));
e.Graphics.DrawImage(_image, new Rectangle((this.Width - _image.Width) / 2, (this.Height - _image.Height) / 2, _image.Width, _image.Height));
t_sbBG.Dispose();
e.Dispose();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Source + ":" + ex.Message);
}
}
protected override void OnMouseEnter(EventArgs e)
{
if (this.IsDisposed == false && _image != null)
{
int t_L, t_T;
Pen t_YPen = new Pen(Color.FromArgb(255, 153, 0));
Graphics t_G = this.CreateGraphics();
t_L = (this.Width - _image.Width) / 4;
t_T = (this.Height - _image.Height) / 4;
t_G.DrawImage(_image, new Rectangle(t_L, t_T, _image.Width + t_L, _image.Height + t_T));
Thread.Sleep(50);
t_G.DrawImage(_image, new Rectangle(2, 2, this.Width - 4, this.Height - 4));
t_G.DrawRectangle(t_YPen, new Rectangle(0, 0, this.Width - 1, this.Height - 1));
t_YPen.Dispose();
t_G.Dispose();
}
}
protected override void OnMouseLeave(EventArgs e)
{
if (this.IsDisposed == false && _image != null)
{
int t_L, t_T;
SolidBrush t_WBrush = new SolidBrush(Color.White);
Rectangle t_rect = new Rectangle(0, 0, this.Width, this.Height);
Bitmap t_Buffer = new Bitmap(this.Width, this.Height);
Graphics t_BG = Graphics.FromImage(t_Buffer);
Graphics t_G = this.CreateGraphics();
t_L = (this.Width - _image.Width) / 4;
t_T = (this.Height - _image.Height) / 4;
t_BG.FillRectangle(t_WBrush, t_rect);
t_BG.DrawImage(_image, new Rectangle(t_L, t_T, _image.Width + t_L, _image.Height + t_T));
t_G.DrawImage(t_Buffer, t_rect);
Thread.Sleep(50);
t_BG.FillRectangle(t_WBrush, t_rect);
t_BG.DrawImage(_image, (this.Width - _image.Width) / 2, (this.Height - _image.Height) / 2);
t_G.DrawImage(t_Buffer, t_rect);
t_WBrush.Dispose();
t_Buffer.Dispose();
t_BG.Dispose();
t_G.Dispose();
//base.OnMouseLeave(e);
}
}
}
public class JPM_CurrentButton : System.Windows.Forms.Control
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
string _caption;
System.Drawing.Bitmap _imageNormal;
System.Drawing.Bitmap _imageMove;
System.Drawing.Bitmap _imageDown;
public string Caption
{
set
{
_caption = value;
this.Invalidate();
}
get
{
return _caption;
}
}
/// <summary>
/// 构建一个空Image以防止引用空的_imageOnMouseMove
/// </summary>
public JPM_CurrentButton()
{
_imageNormal = global::NewControl.Resource.BMP_MYBUTTON;
_imageMove = global::NewControl.Resource.BMP_MYBUTTON_MOVE;
_imageDown = global::NewControl.Resource.BMP_MYBUTTON_DOWN;
Width = 60;
Height = 22;
}
protected override void Dispose(bool disposing)
{
if (disposing == true)
{
if (_imageNormal != null)
{
_imageNormal.Dispose();
}
if (_imageMove != null)
{
_imageMove.Dispose();
}
if (_imageDown != null)
{
_imageDown.Dispose();
}
}
base.Dispose(disposing);
}
protected override void OnPaint(PaintEventArgs e)
{
if (_imageNormal != null)
{
e.Graphics.DrawImage(_imageNormal, new Rectangle(0, 0, 60, 22));
if (_caption != null)
{
e.Graphics.DrawString(_caption, Parent.Font, new SolidBrush(Color.Black), new Point((int)(60 - e.Graphics.MeasureString(_caption, Parent.Font).Width) / 2, 5));
}
}
}
protected override void OnMouseEnter(EventArgs e)
{
if (this.IsDisposed == false && _imageMove != null)
{
Graphics t_G = this.CreateGraphics();
t_G.DrawImage(_imageMove, new Rectangle(0, 0, 60, 22));
if (_caption != null)
{
t_G.DrawString(_caption, Parent.Font, new SolidBrush(Color.Black), new Point((int)(60 - t_G.MeasureString(_caption, Parent.Font).Width) / 2, 5));
}
this.Cursor = global::System.Windows.Forms.Cursors.Hand;
}
}
protected override void OnMouseDown(MouseEventArgs e)
{
if (this.IsDisposed == false && _imageDown != null)
{
Graphics t_G = this.CreateGraphics();
t_G.DrawImage(_imageDown, new Rectangle(0, 0, 60, 22));
if (_caption != null)
{
t_G.DrawString(_caption, Parent.Font, new SolidBrush(Color.Black), new Point((int)(60 - t_G.MeasureString(_caption, Parent.Font).Width) / 2, 5));
}
}
}
protected override void OnMouseUp(MouseEventArgs e)
{
if (this.IsDisposed == false && _imageNormal != null)
{
Graphics t_G = this.CreateGraphics();
t_G.DrawImage(_imageNormal, new Rectangle(0, 0, 60, 22));
if (_caption != null)
{
t_G.DrawString(_caption, Parent.Font, new SolidBrush(Color.Black), new Point((int)(60 - t_G.MeasureString(_caption, Parent.Font).Width) / 2, 5));
}
}
}
protected override void OnMouseLeave(System.EventArgs e)
{
if (this.IsDisposed == false && _imageNormal != null)
{
Graphics t_G = this.CreateGraphics();
t_G.DrawImage(_imageNormal, new Rectangle(0, 0, 60, 22));
if (_caption != null)
{
t_G.DrawString(_caption, Parent.Font, new SolidBrush(Color.Black), new Point((int)(60 - t_G.MeasureString(_caption, Parent.Font).Width) / 2, 5));
}
this.Cursor = global::System.Windows.Forms.Cursors.Default;
}
}
}
public class JPM_List_Entity
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -