Exferia/Exferia_Controles/Exferia_Controles/Exferia_CheckListBox.cs

82 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Exferia_Controles
{
public partial class Exferia_CheckListBox : CheckedListBox
{
private List<string> g_lst_ListaObjetos_Textos = new List<string>();
private List<int> g_lst_ListaObjetos_Indices = new List<int>();
public void Exferia_CheckListBox_CheckAndDisable(string _str_Elemento)
{
g_lst_ListaObjetos_Textos.Add(_str_Elemento);
Refresh();
}
public void Exferia_CheckListBox_CheckAndDisable(int _int_Indice)
{
g_lst_ListaObjetos_Indices.Add(_int_Indice);
Refresh();
}
public void Exferia_CheckListBox_Vaciar_Desabilitados()
{
g_lst_ListaObjetos_Textos.Clear();
g_lst_ListaObjetos_Indices.Clear();
Refresh();
}
public Exferia_CheckListBox()
{ }
#region "Eventos privados"
protected override void OnDrawItem(DrawItemEventArgs e)
{
if (e.Index > -1)
{
try
{
string s = Items[e.Index].ToString();
if (g_lst_ListaObjetos_Textos.Contains(s) || g_lst_ListaObjetos_Indices.Contains(e.Index))
{
System.Windows.Forms.VisualStyles.CheckBoxState state = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedDisabled;
Size glyphSize = CheckBoxRenderer.GetGlyphSize(e.Graphics, state);
CheckBoxRenderer.DrawCheckBox(
e.Graphics,
new Point(e.Bounds.X + 1, e.Bounds.Y + 1), // add one pixel to align the check gliph properly
new Rectangle(
new Point(e.Bounds.X + glyphSize.Width + 3, e.Bounds.Y), // add three pixels to align text properly
new Size(e.Bounds.Width - glyphSize.Width, e.Bounds.Height)),
s,
Font,
TextFormatFlags.Left, // text is centered by default
false,
state);
}
else
{
base.OnDrawItem(e);
}
}
catch (Exception)
{ base.OnDrawItem(e); }
}
else
{
base.OnDrawItem(e);
}
}
#endregion
}
}