private void butModify_Click(object sender, EventArgs e) { try { if (listView1.SelectedItems.Count <= 0) { return; } ListViewItem lvi = listView1.SelectedItems[0]; DesignLabelFormatItem fi = lvi.Tag as DesignLabelFormatItem; UpdateFormatItem(fi); lvi.Text = fi.数据值; lvi.SubItems[1].Text = fi.显示内容; lvi.SubItems[2].Text = fi.图标名称; lvi.SubItems[3].BackColor = fi.背景色; lvi.SubItems[4].BackColor = fi.前景色; } catch (Exception ex) { MsgBox.ShowException(ex, this); } }
private void UpdateFormatItem(DesignLabelFormatItem formatItem) { formatItem.数据值 = txtValue.Text; formatItem.显示内容 = txtDisplayValue.Text; formatItem.图标名称 = txtImgName.Text; formatItem.背景色 = labBkColor.Color; formatItem.前景色 = labForeColor.Color; }
private void butAdd_Click(object sender, EventArgs e) { try { DesignLabelFormatItem newItem = new DesignLabelFormatItem(); UpdateFormatItem(newItem); AddItemToList(newItem); } catch (Exception ex) { MsgBox.ShowException(ex, this); } }
private void AddItemToList(DesignLabelFormatItem fi) { ListViewItem itemNew = new ListViewItem(new string[] { fi.数据值, fi.显示内容, fi.图标名称, "", "" }, 0); itemNew.UseItemStyleForSubItems = false; itemNew.Tag = fi; itemNew.Name = fi.数据值; itemNew.SubItems[3].BackColor = fi.背景色; itemNew.SubItems[4].BackColor = fi.前景色; listView1.Items.Add(itemNew); }
private void listView1_SelectedIndexChanged(object sender, EventArgs e) { try { if (listView1.SelectedItems.Count <= 0) { return; } ListViewItem lvi = listView1.SelectedItems[0]; DesignLabelFormatItem fi = lvi.Tag as DesignLabelFormatItem; txtValue.Text = fi.数据值; txtDisplayValue.Text = fi.显示内容; txtImgName.Text = fi.图标名称; labBkColor.Color = fi.背景色; labForeColor.Color = fi.前景色; } catch (Exception ex) { MsgBox.ShowException(ex, this); } }
private void ReloadDictionary(Dictionary <string, object> dicts) { foreach (BaseLayoutItem bli in layoutControl1.Items) { DesignLabel dl = bli as DesignLabel; if (dl == null) { continue; } if (string.IsNullOrEmpty(dl.Formats.数据项名称)) { continue; } dl.Image = null; dl.AppearanceItemCaption.BackColor = dl.Formats.默认背景色; dl.AppearanceItemCaption.ForeColor = dl.Formats.默认前景色; if (dicts == null) { dl.Text = " "; continue; } string showDisplay = ""; bool isDataItem = dicts.ContainsKey(dl.Formats.数据项名称); if (isDataItem) { string value = Convert.ToString(dicts[dl.Formats.数据项名称]); showDisplay = value; if (dl.Formats.文本格式.Count > 0) { int vIndex = dl.Formats.文本格式.FindIndex(T => T.数据值 == value); if (vIndex >= 0) { DesignLabelFormatItem formatItem = dl.Formats.文本格式[vIndex]; dl.Image = Img24Resource.LoadImg(formatItem.图标名称); showDisplay = formatItem.显示内容; if (formatItem.背景色.Name != "0") { dl.AppearanceItemCaption.BackColor = formatItem.背景色; } if (formatItem.前景色.Name != "0") { dl.AppearanceItemCaption.ForeColor = formatItem.前景色; } } } } if (string.IsNullOrEmpty(showDisplay)) { showDisplay = " "; } dl.Text = showDisplay; } }