📄 inertbutton.cs
字号:
#region Fireball License
// Copyright (C) 2005 Sebastian Faltoni sebastian{at}dotnetfireball{dot}net
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#endregion
#region Original License
// *****************************************************************************
//
// 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
// *****************************************************************************
#endregion
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.ComponentModel;
namespace Fireball.Docking
{
/// <include file='CodeDoc\InertButton.xml' path='//CodeDoc/Class[@name="InertButton"]/ClassDef/*'/>
[ToolboxItem(false)]
public class InertButton : Control
{
private enum RepeatClickStatus
{
Disabled,
Started,
Repeating,
Stopped
}
private class RepeatClickEventArgs : EventArgs
{
private static RepeatClickEventArgs _empty;
static RepeatClickEventArgs()
{
_empty = new RepeatClickEventArgs();
}
public new static RepeatClickEventArgs Empty
{
get { return _empty; }
}
}
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 int m_imageIndexEnabled = -1;
private int m_imageIndexDisabled = -1;
private bool m_monochrom = true;
private ToolTip m_toolTip = null;
private string m_toolTipText = "";
private Color m_borderColor = Color.Empty;
private ImageList _ImageList = new ImageList();
private ContentAlignment _TextAlign;
public virtual ContentAlignment TextAlign
{
get
{
return this._TextAlign;
}
set
{
_TextAlign = value;
}
}
public ImageList ImageList
{
get
{
return _ImageList;
}
}
/// <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.SupportsTransparentBackColor, 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);
this.BackColor = Color.Transparent;
m_timer = new Timer();
m_timer.Enabled = false;
m_timer.Tick += new EventHandler(Timer_Tick);
}
/// <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")]
//#if FRAMEWORK_VER_2x
//public new Color BorderColor
//#else
public Color BorderColor
// #endif
{
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 (ImageList == null || ImageIndexEnabled == -1)
return null;
else
return 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 (ImageList == null || ImageIndexDisabled == -1)
return null;
else
return 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="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="RepeatClick"]/*'/>
[Category("Behavior")]
[LocalizedDescription("InertButton.RepeatClick.Description")]
[DefaultValue(false)]
public bool RepeatClick
{
get { return (ClickStatus != RepeatClickStatus.Disabled); }
set { ClickStatus = RepeatClickStatus.Stopped; }
}
private RepeatClickStatus m_clickStatus = RepeatClickStatus.Disabled;
private RepeatClickStatus ClickStatus
{
get { return m_clickStatus; }
set
{
if (m_clickStatus == value)
return;
m_clickStatus = value;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -