private void listBox_Replace_DrawItem(object sender, DrawItemEventArgs e) { ListBox listBox = (ListBox)sender; // Draw the background of the ListBox control for each item. e.DrawBackground(); // Define the default color of the brush as black. Brush myBrush = Brushes.Black; //设定焦点 Object folderObj = mapElement.mapsManager.antetypesManager[comboBox_folder.SelectedIndex]; if (folderObj != null) { AntetypeFolder folder = (AntetypeFolder)folderObj; int index = listBox_Actors.SelectedIndex; if (index >= 0 && index < anteTypes_current.Count) { if (anteTypes_replace[index] != null) { Antetype replaceAT = (Antetype)anteTypes_replace[index]; int itemID = replaceAT.GetID(); if (itemID >= 0 && e.Index == itemID) { myBrush = Brushes.Red; } } } } // Draw the current item text based on the current Font and the custom brush settings. e.Graphics.DrawString(listBox.Items[e.Index].ToString(), e.Font, myBrush, e.Bounds, StringFormat.GenericDefault); // If the ListBox has focus, draw a focus rectangle around the selected item. e.DrawFocusRectangle(); }
private void refreshActorList() { if (mapElement == null) { return; } if (comboBox_folder.Items.Count <= 0) { return; } Object folderObj = mapElement.mapsManager.antetypesManager[comboBox_folder.SelectedIndex]; if (folderObj == null) { return; } AntetypeFolder folder = (AntetypeFolder)folderObj; listBox_Replace.Items.Clear(); for (int i = 0; i < folder.Count(); i++) { Antetype anteType = folder[i]; listBox_Replace.Items.Add(anteType.name); } //设定焦点 int index = listBox_Actors.SelectedIndex; if (index < 0 || index >= anteTypes_current.Count) { return; } if (anteTypes_replace[index] != null) { Antetype replaceAT = (Antetype)anteTypes_replace[index]; int itemID = replaceAT.GetID(); if (itemID >= 0) { noEvent = true; listBox_Replace.SelectedIndex = itemID; noEvent = false; } } }