private void dgwResources_SelectionChanged(object sender, EventArgs e) { if (dgwResources.SelectedRows.Count == 0) { txtId.Text = ""; txtFrequency.Text = ""; txtName.Text = ""; txtUnit.Text = ""; chbExploatable.Checked = false; chbImportant.Checked = false; chbRenewable.Checked = false; txtDescription.Text = ""; txtTypeId.Text = ""; txtTypeName.Text = ""; pbxIcon.Hide(); pnlTags.Controls.Clear(); } else { Resource res = (Resource)dgwResources.SelectedRows[0].Tag; if (res != null) { txtId.Text = res.ID; txtFrequency.Text = Resource.FrequencyToString(res.Frequency); txtName.Text = res.Name; txtUnit.Text = Resource.UnitToString(res.Unit); chbExploatable.Checked = res.Exploatable; chbImportant.Checked = res.Important; chbRenewable.Checked = res.Renewable; txtDescription.Text = res.Description; txtTypeId.Text = MainForm.types[res.Type.ID].SecondID; txtTypeName.Text = MainForm.types[res.Type.ID].Name; pnlTags.Controls.Clear(); if (res.Tags.Count > 0) { int off = 3; Label lbl; foreach (Tag t in res.Tags.Values) { lbl = new Label(); lbl.Width = 15 + 7 * t.SecondID.Length; lbl.Text = t.SecondID; lbl.BackColor = t.Color; lbl.Left = off; //lbl.ForeColor = Color.FromArgb(255 - t.Color.R, 255 - t.Color.G, 255 - t.Color.G); lbl.ForeColor = HSV.Complementary(t.Color); pnlTags.Controls.Add(lbl); lbl.Left = off; off += lbl.Width + 3; } pnlTags.Refresh(); } pbxIcon.Show(); if (!res.IconFileName.Equals("")) { try { pbxIcon.Image = Image.FromFile(res.IconFileName); pbxIcon.SizeMode = PictureBoxSizeMode.StretchImage; } catch (FileNotFoundException fnfe) { //pbxIcon.Image = pbxIcon.ErrorImage; try { pbxIcon.Image = Image.FromFile(res.Type.IconFileName); Console.WriteLine(fnfe.StackTrace); } catch (FileNotFoundException fnfe1) { pbxIcon.Image = pbxIcon.ErrorImage; //pbxIcon.Image = Image.FromFile(res.Type.IconFileName); Console.WriteLine(fnfe1.StackTrace); } } } else { pbxIcon.Image = Image.FromFile(res.Type.IconFileName); //pbxIcon.Image = pbxIcon.InitialImage; } } } }
private void lstSelectedTags_DrawItem(object sender, DrawItemEventArgs e) { e.DrawBackground(); bool selected = ((e.State & DrawItemState.Selected) == DrawItemState.Selected); int index = e.Index; if (index >= 0 && index < lstSelectedTags.Items.Count) { string text = lstSelectedTags.Items[index].ToString(); Graphics g = e.Graphics; //background: SolidBrush backgroundBrush; if (selected) { backgroundBrush = tagsBackgroundBrushSelected; } else { backgroundBrush = new SolidBrush(MainForm.GetTagBySecondID(text).Color); } g.FillRectangle(backgroundBrush, e.Bounds); //text: SolidBrush foregroundBrush = (selected) ? tagsForegroundBrushSelected : new SolidBrush(HSV.Complementary(MainForm.GetTagBySecondID(text).Color)); g.DrawString(text, e.Font, foregroundBrush, lstSelectedTags.GetItemRectangle(index).Location); } e.DrawFocusRectangle(); }