2020-04-27 12:17:13 +00:00
|
|
|
|
namespace RyzStudio.Windows.ThemedForms
|
|
|
|
|
{
|
|
|
|
|
using RyzStudio.Drawing;
|
|
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2020-05-10 10:45:54 +00:00
|
|
|
|
public partial class TListBox : RyzStudio.Windows.ThemedForms.TUserControl
|
2020-04-27 12:17:13 +00:00
|
|
|
|
{
|
|
|
|
|
protected readonly Padding textboxPadding = new Padding(6, 2, 4, 2);
|
|
|
|
|
|
2020-05-10 10:45:54 +00:00
|
|
|
|
public TListBox() : base()
|
2020-04-27 12:17:13 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
this.Font = new Font(this.Font, FontStyle.Regular);
|
|
|
|
|
this.Margin = new Padding(10, 4, 10, 4);
|
|
|
|
|
|
2020-05-12 23:37:01 +00:00
|
|
|
|
listBox1.Items.Add("one");
|
|
|
|
|
listBox1.Items.Add("two");
|
|
|
|
|
listBox1.Items.Add("three");
|
|
|
|
|
listBox1.Items.Add("four");
|
|
|
|
|
listBox1.Items.Add("five");
|
|
|
|
|
|
|
|
|
|
listBox1.Font = this.Font;
|
|
|
|
|
listBox1.BorderStyle = BorderStyle.None;
|
2020-04-27 12:17:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnResize(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnResize(e);
|
|
|
|
|
|
2020-05-12 23:37:01 +00:00
|
|
|
|
//int b = (styleActive.BorderWidth + 1) + styleActive.BorderPadding;
|
2020-04-27 12:17:13 +00:00
|
|
|
|
|
2020-05-12 23:37:01 +00:00
|
|
|
|
//this.Height = comboBox1.Height + (b + textboxPadding.Top) + ((b - 1) + textboxPadding.Bottom);
|
2020-04-27 12:17:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnGotFocus(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnGotFocus(e);
|
|
|
|
|
|
2020-05-12 23:37:01 +00:00
|
|
|
|
listBox1.Focus();
|
2020-04-27 12:17:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Browsable(true), EditorBrowsable(EditorBrowsableState.Advanced)]
|
|
|
|
|
[Category("Appearance")]
|
2020-05-12 23:37:01 +00:00
|
|
|
|
public System.Windows.Forms.ListBox ListBox { get => listBox1; set => listBox1 = value; }
|
2020-04-27 12:17:13 +00:00
|
|
|
|
|
|
|
|
|
[Browsable(true), EditorBrowsable(EditorBrowsableState.Advanced)]
|
|
|
|
|
[Category("Appearance")]
|
2020-05-10 10:45:54 +00:00
|
|
|
|
public TButton SubmitButton { get; set; } = null;
|
2020-04-27 12:17:13 +00:00
|
|
|
|
|
|
|
|
|
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
|
|
|
|
|
public new Padding Margin { get => base.Margin; set => base.Margin = value; }
|
|
|
|
|
|
2020-05-12 23:37:01 +00:00
|
|
|
|
[Category("Action")]
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
public event EventHandler OnAdd;
|
|
|
|
|
|
|
|
|
|
[Category("Action")]
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
public event EventHandler OnEdit;
|
|
|
|
|
|
|
|
|
|
protected override void updateBackground(Graphics g, ThemeStyle style)
|
2020-04-27 12:17:13 +00:00
|
|
|
|
{
|
|
|
|
|
int b = (styleActive.BorderWidth + 1) + styleActive.BorderPadding;
|
|
|
|
|
|
|
|
|
|
this.Padding = new Padding((b + textboxPadding.Left), (b + textboxPadding.Top), ((b - 1) + textboxPadding.Right), ((b - 1) + textboxPadding.Bottom));
|
|
|
|
|
|
|
|
|
|
Rectangoid area = new Rectangoid(this.ClientRectangle, style.BorderRadius, style.BorderWidth);
|
|
|
|
|
g.FillPath(new SolidBrush(style.BackColour), area.ToGraphicsPath());
|
|
|
|
|
g.DrawPath(new Pen(new SolidBrush(style.BorderColour), style.BorderWidth), area.ToGraphicsPath());
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 23:37:01 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Add
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void imageBox1_MouseClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Button != MouseButtons.Left)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.OnAdd?.Invoke(sender, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Edit
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void imageBox5_MouseClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Button != MouseButtons.Left)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.OnEdit?.Invoke(sender, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void imageBox2_MouseClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Button != MouseButtons.Left)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (listBox1.SelectedIndex < 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int pos = listBox1.SelectedIndex;
|
|
|
|
|
|
|
|
|
|
listBox1.Items.RemoveAt(pos);
|
|
|
|
|
|
|
|
|
|
if (pos > (listBox1.Items.Count - 1))
|
|
|
|
|
{
|
|
|
|
|
pos = (listBox1.Items.Count - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
listBox1.SelectedIndex = pos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Move up
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void imageBox3_MouseClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e != null)
|
|
|
|
|
{
|
|
|
|
|
if (e.Button != MouseButtons.Left)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (listBox1.SelectedIndex <= 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (listBox1.SelectedItem == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object item = listBox1.SelectedItem;
|
|
|
|
|
int pos = listBox1.SelectedIndex;
|
|
|
|
|
|
|
|
|
|
listBox1.Items.RemoveAt(pos);
|
|
|
|
|
listBox1.Items.Insert((pos - 1), item);
|
|
|
|
|
|
|
|
|
|
listBox1.SelectedIndex = (pos - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Move down
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void imageBox4_MouseClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e != null)
|
|
|
|
|
{
|
|
|
|
|
if (e.Button != MouseButtons.Left)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (listBox1.SelectedIndex >= (listBox1.Items.Count - 1))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (listBox1.SelectedItem == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object item = listBox1.SelectedItem;
|
|
|
|
|
int pos = listBox1.SelectedIndex;
|
|
|
|
|
|
|
|
|
|
listBox1.Items.RemoveAt(pos);
|
|
|
|
|
listBox1.Items.Insert((pos + 1), item);
|
|
|
|
|
|
|
|
|
|
listBox1.SelectedIndex = (pos + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e) => imageBox5_MouseClick(sender, e);
|
|
|
|
|
|
|
|
|
|
private void listBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
switch (e.KeyCode)
|
|
|
|
|
{
|
|
|
|
|
case Keys.Enter:
|
|
|
|
|
if (this.SubmitButton != null)
|
|
|
|
|
{
|
|
|
|
|
this.SubmitButton.PerformClick();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case Keys.Escape:
|
|
|
|
|
close();
|
|
|
|
|
break;
|
|
|
|
|
case Keys.Up:
|
|
|
|
|
if (e.Alt)
|
|
|
|
|
{
|
|
|
|
|
imageBox3_MouseClick(sender, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case Keys.Down:
|
|
|
|
|
if (e.Alt)
|
|
|
|
|
{
|
|
|
|
|
imageBox4_MouseClick(sender, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-27 12:17:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|