Witam forumowiczow,
zaimplementoalem w swojej aplikacji liste, ktora jest rysowana wg kodu ponizej:
private void FIXED_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
//Select the Icon that you want to display
// Icon i = new Icon("TICK.ico");
// Get the Bounding rectangle
Rectangle rc = new Rectangle(e.Bounds.X + delta, e.Bounds.Y + delta, e.Bounds.Width - 10, e.Bounds.Height - delta);
Console.WriteLine(e.State.ToString());
// Setup the stringformatting object
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
// Get the item text
FIXED = (ListBox)sender;
string str = (string)FIXED.Items[e.Index];
// Draw the rectangle
e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.Black), 2), rc);
e.Graphics.FillRectangle(new SolidBrush(Color.White), rc);
// Check if the item is selected
if (e.State == (DrawItemState.NoAccelerator | DrawItemState.NoFocusRect))
{
// Paint the item that if not selected
e.Graphics.FillRectangle(new SolidBrush(Color.White), rc);
e.Graphics.DrawString(str, new Font("Ariel", 12), new SolidBrush(Color.Black), rc, sf);
e.DrawFocusRectangle();
}
else
{
// Paint the item accordingly if it is selected
e.DrawFocusRectangle();
e.Graphics.FillRectangle(new SolidBrush(Color.LightYellow), rc);
//e.Graphics.DrawIcon(i, e.Bounds.X, e.Bounds.Y + 5);
e.Graphics.DrawString(str, new Font("Ariel", 12), new SolidBrush(Color.Black), rc, sf);
}
}
private void FIXED_SelectedIndexChanged(object sender, System.EventArgs e)
{
// Unbox the sender
FIXED = (ListBox)sender;
// Get the position of the item selected
int posSelected = FIXED.SelectedIndex;
// Get the item text
string str = (string)FIXED.Items[posSelected];
}
Moja lista musi udostepniac MultiExtended selection mode.
Ale problem jest taki, ze za kazdym razem kiedy uruchomie aplikacje i wcisne ALT lub TAB, cala lista rysuje sie tak, jak gdyby wszystkie elementy zostaly wybrane (zaznaczone jako SELECTED) i wtedy juz nie moge wrocic do ich stanu poprzedniego. Czy ktos moglby mi pomoc naprawic ten problem?
Zaznaczam, ze nie potrzebuje funkcjonalnosci klawiszy ALT i TAB... Wiec moze jakos je zablokowac?