Added prompts for drag-drop on tiles Added drag-drop on tile layout container Changed drag icon for tile movement and file drop Changed to remove legacy TileContainer
130 lines
4.9 KiB
C#
130 lines
4.9 KiB
C#
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
namespace RyzStudio.Windows.TileForms
|
|
{
|
|
public partial class Tile : RyzStudio.Windows.Forms.TUserControl
|
|
{
|
|
private int _imageLeft = 0;
|
|
private int _imageTop = 11;
|
|
private int _labelMargin = 3;
|
|
private int _labelTop = 47;
|
|
private Rectangle _labelRectangle = new Rectangle();
|
|
|
|
private string _title = "";
|
|
private Image _largeIcon = null;
|
|
|
|
|
|
public Tile()
|
|
{
|
|
InitializeComponent();
|
|
|
|
this.AutoScaleMode = AutoScaleMode.None;
|
|
this.BackColor = DefaultVisualStyle.Default.BackColour;
|
|
this.DoubleBuffered = true;
|
|
this.Font = new Font(this.Font.FontFamily, 8.25F);
|
|
this.ForeColor = DefaultVisualStyle.Default.ForeColour;
|
|
//this.Size = new Size(70, 70);
|
|
|
|
this.EnableMovable = true;
|
|
}
|
|
|
|
#region encapsulated properties
|
|
|
|
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
public override bool AutoSize { get => base.AutoSize; set => base.AutoSize = false; }
|
|
|
|
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
public new AutoScaleMode AutoScaleMode { get => base.AutoScaleMode; set => base.AutoScaleMode = AutoScaleMode.None; }
|
|
|
|
//[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
//public new Padding Margin { get => base.Margin; set => base.Margin = new Padding(0); }
|
|
|
|
//[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
//public new Padding Padding { get => base.Padding; set => base.Padding = new Padding(0); }
|
|
|
|
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
public override Size MaximumSize { get => base.MaximumSize; set => this.Size = value; }
|
|
|
|
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
public override Size MinimumSize { get => base.MinimumSize; set => this.Size = value; }
|
|
|
|
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
public new Size Size { get => base.Size; set => base.MaximumSize = base.MinimumSize = base.Size = value; }
|
|
|
|
#endregion
|
|
|
|
#region public properties
|
|
|
|
[Category("Appearance"), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
|
|
public Image LargeIcon
|
|
{
|
|
get => _largeIcon;
|
|
set
|
|
{
|
|
_largeIcon = value;
|
|
|
|
if (_largeIcon == null)
|
|
{
|
|
_imageLeft = 0;
|
|
}
|
|
else
|
|
{
|
|
_imageLeft = (this.Width - _largeIcon.Width) / 2;
|
|
}
|
|
|
|
this.Invalidate();
|
|
}
|
|
}
|
|
|
|
[Category("Appearance"), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
|
|
public string Title
|
|
{
|
|
get => _title;
|
|
set
|
|
{
|
|
_title = value;
|
|
|
|
_labelRectangle = new Rectangle(_labelMargin, _labelTop, (this.Width - (_labelMargin * 2)), (this.Height - _labelTop - 1));
|
|
|
|
this.Invalidate();
|
|
}
|
|
}
|
|
|
|
[Category("Behaviour"), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
|
|
public ContextMenuStrip LeftContextMenuStrip { get; set; }
|
|
|
|
#endregion
|
|
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
{
|
|
base.OnPaint(e);
|
|
|
|
Graphics g = e.Graphics;
|
|
|
|
if (this.LargeIcon != null)
|
|
{
|
|
g.DrawImage(this.LargeIcon, new Point(_imageLeft, _imageTop));
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(this.Title))
|
|
{
|
|
TextRenderer.DrawText(e.Graphics, this.Title, this.Font, _labelRectangle, this.ForeColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.NoPadding | TextFormatFlags.EndEllipsis);
|
|
}
|
|
|
|
g.DrawRectangle(new Pen(DefaultVisualStyle.Default.Border.Colour, DefaultVisualStyle.Default.Border.Width), new Rectangle(this.DisplayRectangle.X, this.DisplayRectangle.Y, (this.DisplayRectangle.Width - 1), (this.DisplayRectangle.Height - 1)));
|
|
}
|
|
|
|
protected override void OnMouseClick(MouseEventArgs e)
|
|
{
|
|
base.OnMouseClick(e);
|
|
|
|
if (e.Button == MouseButtons.Left)
|
|
{
|
|
this.LeftContextMenuStrip?.Show(this, e.Location);
|
|
}
|
|
}
|
|
|
|
}
|
|
} |