inertbutton.cs
来自「SharpDevelop2.0.0 c#开发免费工具」· CS 代码 · 共 610 行 · 第 1/2 页
CS
610 行
// *****************************************************************************
//
// Copyright 2004, Weifen Luo
// All rights reserved. The software and associated documentation
// supplied hereunder are the proprietary information of Weifen Luo
// and are supplied subject to licence terms.
//
// WinFormsUI Library Version 1.0
// *****************************************************************************
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.ComponentModel;
namespace WeifenLuo.WinFormsUI
{
/// <include file='CodeDoc\InertButton.xml' path='//CodeDoc/Class[@name="InertButton"]/ClassDef/*'/>
public class InertButton : Control
{
private IContainer components = new Container();
private int m_borderWidth = 1;
private bool m_mouseOver = false;
private bool m_mouseCapture = false;
private bool m_isPopup = false;
private Image m_imageEnabled = null;
private Image m_imageDisabled = null;
private ImageList m_imageList = null;
private int m_imageIndexEnabled = -1;
private int m_imageIndexDisabled = -1;
private bool m_monochrom = true;
private ContentAlignment m_textAlign = ContentAlignment.MiddleCenter;
private ToolTip m_toolTip = null;
private string m_toolTipText = "";
private Color m_borderColor = Color.Empty;
/// <include file='CodeDoc\InertButton.xml' path='//CodeDoc/Class[@name="InertButton"]/Constructor[@name="Overloads"]/*'/>
/// <include file='CodeDoc\InertButton.xml' path='//CodeDoc/Class[@name="InertButton"]/Constructor[@name="()"]/*'/>
public InertButton()
{
InternalConstruct(null, null);
}
/// <include file='CodeDoc\InertButton.xml' path='//CodeDoc/Class[@name="InertButton"]/Constructor[@name="(Image)"]/*'/>
public InertButton(Image imageEnabled)
{
InternalConstruct(imageEnabled, null);
}
/// <include file='CodeDoc\InertButton.xml' path='//CodeDoc/Class[@name="InertButton"]/Constructor[@name="(Image, Image)"]/*'/>
public InertButton(Image imageEnabled, Image imageDisabled)
{
InternalConstruct(imageEnabled, imageDisabled);
}
private void InternalConstruct(Image imageEnabled, Image imageDisabled)
{
// Remember parameters
ImageEnabled = imageEnabled;
ImageDisabled = imageDisabled;
// Prevent drawing flicker by blitting from memory in WM_PAINT
SetStyle(ControlStyles.ResizeRedraw, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
// Prevent base class from trying to generate double click events and
// so testing clicks against the double click time and rectangle. Getting
// rid of this allows the user to press then release button very quickly.
SetStyle(ControlStyles.StandardDoubleClick, false);
// Should not be allowed to select this control
SetStyle(ControlStyles.Selectable, false);
}
/// <exclude/>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
components.Dispose();
}
base.Dispose(disposing);
}
/// <include file='CodeDoc\InertButton.xml' path='//CodeDoc/Class[@name="InertButton"]/Property[@name="BorderColor"]/*'/>
[Category("Appearance")]
[LocalizedDescription("InertButton.BorderColor.Description")]
public Color BorderColor
{
get { return m_borderColor; }
set
{
if (m_borderColor != value)
{
m_borderColor = value;
Invalidate();
}
}
}
private bool ShouldSerializeBorderColor()
{
return (m_borderColor != Color.Empty);
}
/// <include file='CodeDoc\InertButton.xml' path='//CodeDoc/Class[@name="InertButton"]/Property[@name="BorderWidth"]/*'/>
[Category("Appearance")]
[LocalizedDescription("InertButton.BorderWidth.Description")]
[DefaultValue(1)]
public int BorderWidth
{
get { return m_borderWidth; }
set
{
if (value < 1)
value = 1;
if (m_borderWidth != value)
{
m_borderWidth = value;
Invalidate();
}
}
}
/// <include file='CodeDoc\InertButton.xml' path='//CodeDoc/Class[@name="InertButton"]/Property[@name="ImageEnabled"]/*'/>
[Category("Appearance")]
[LocalizedDescription("InertButton.ImageEnabled.Description")]
[DefaultValue(null)]
public Image ImageEnabled
{
get
{
if (m_imageEnabled != null)
return m_imageEnabled;
try
{
if (m_imageList == null || m_imageIndexEnabled == -1)
return null;
else
return m_imageList.Images[m_imageIndexEnabled];
}
catch
{
return null;
}
}
set
{
if (m_imageEnabled != value)
{
m_imageEnabled = value;
Invalidate();
}
}
}
private bool ShouldSerializeImageEnabled()
{
return (m_imageEnabled != null);
}
/// <include file='CodeDoc\InertButton.xml' path='//CodeDoc/Class[@name="InertButton"]/Property[@name="ImageDisabled"]/*'/>
[Category("Appearance")]
[LocalizedDescription("InertButton.ImageDisabled.Description")]
[DefaultValue(null)]
public Image ImageDisabled
{
get
{
if (m_imageDisabled != null)
return m_imageDisabled;
try
{
if (m_imageList == null || m_imageIndexDisabled == -1)
return null;
else
return m_imageList.Images[m_imageIndexDisabled];
}
catch
{
return null;
}
}
set
{
if (m_imageDisabled != value)
{
m_imageDisabled = value;
Invalidate();
}
}
}
private bool ShouldSerializeImageDisabled()
{
return (m_imageDisabled != null);
}
/// <include file='CodeDoc\InertButton.xml' path='//CodeDoc/Class[@name="InertButton"]/Property[@name="ImageList"]/*'/>
[Category("Appearance")]
[LocalizedDescription("InertButton.ImageList.Description")]
[DefaultValue(null)]
[RefreshProperties(RefreshProperties.Repaint)]
public ImageList ImageList
{
get { return m_imageList; }
set
{
if (m_imageList != value)
{
m_imageList = value;
Invalidate();
}
}
}
/// <include file='CodeDoc\InertButton.xml' path='//CodeDoc/Class[@name="InertButton"]/Property[@name="ImageIndexEnabled"]/*'/>
[Category("Appearance")]
[LocalizedDescription("InertButton.ImageIndexEnabled.Description")]
[DefaultValue(-1)]
[Editor("System.Windows.Forms.Design.ImageIndexEditor, System.Design", "System.Drawing.Design.UITypeEditor,System.Drawing")]
[TypeConverter(typeof(System.Windows.Forms.ImageIndexConverter))]
[RefreshProperties(RefreshProperties.Repaint)]
public int ImageIndexEnabled
{
get { return m_imageIndexEnabled; }
set
{
if (m_imageIndexEnabled != value)
{
m_imageIndexEnabled = value;
Invalidate();
}
}
}
/// <include file='CodeDoc\InertButton.xml' path='//CodeDoc/Class[@name="InertButton"]/Property[@name="ImageIndexDisabled"]/*'/>
[Category("Appearance")]
[LocalizedDescription("InertButton.ImageIndexDisabled.Description")]
[DefaultValue(-1)]
[Editor("System.Windows.Forms.Design.ImageIndexEditor, System.Design", "System.Drawing.Design.UITypeEditor,System.Drawing")]
[TypeConverter(typeof(System.Windows.Forms.ImageIndexConverter))]
[RefreshProperties(RefreshProperties.Repaint)]
public int ImageIndexDisabled
{
get { return m_imageIndexDisabled; }
set
{
if (m_imageIndexDisabled != value)
{
m_imageIndexDisabled = value;
Invalidate();
}
}
}
/// <include file='CodeDoc\InertButton.xml' path='//CodeDoc/Class[@name="InertButton"]/Property[@name="IsPopup"]/*'/>
[Category("Appearance")]
[LocalizedDescription("InertButton.IsPopup.Description")]
[DefaultValue(false)]
public bool IsPopup
{
get { return m_isPopup; }
set
{
if (m_isPopup != value)
{
m_isPopup = value;
Invalidate();
}
}
}
/// <include file='CodeDoc\InertButton.xml' path='//CodeDoc/Class[@name="InertButton"]/Property[@name="Monochrome"]/*'/>
[Category("Appearance")]
[LocalizedDescription("InertButton.Monochrom.Description")]
[DefaultValue(true)]
public bool Monochrome
{
get { return m_monochrom; }
set
{
if (value != m_monochrom)
{
m_monochrom = value;
Invalidate();
}
}
}
/// <include file='CodeDoc\InertButton.xml' path='//CodeDoc/Class[@name="InertButton"]/Property[@name="TextAlign"]/*'/>
[Category("Appearance")]
[LocalizedDescription("InertButton.TextAlign.Description")]
[DefaultValue(ContentAlignment.MiddleCenter)]
public ContentAlignment TextAlign
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?