private void listBox1_SelectedIndexChanged(object sender, EventArgs e) {// 切换配方项 ListBoxItemInfo itemInfo = listBox1.SelectedItem as ListBoxItemInfo; if (itemInfo == null) { return; } // 提示清零 clearZeroForm = new Form(); while (realTimeQuality != 0.0) { DialogResult res = MessageBox.Show(clearZeroForm, "请先清零!", null, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (res == DialogResult.Cancel) { break; } } timer2.Stop(); refreshRecipeInfoLabels(); currentSelectedItem = itemInfo; timer2.Start(); }
private void listBox1_DrawItem(object sender, DrawItemEventArgs e) { if (e.Index < 0) { return; } ListBoxItemInfo it = listBox1.Items[e.Index] as ListBoxItemInfo; Brush weightBrush; e.DrawBackground(); if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {// 如果被选中,则画出聚焦框 e.DrawFocusRectangle(); weightBrush = Brushes.Black; } else {// 否则根据item存储的颜色来画背景色 Brush br = new SolidBrush(it.BackColor); //Brush br = new SolidBrush(Color.Yellow); e.Graphics.FillRectangle(br, e.Bounds); weightBrush = Brushes.Gray; } e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; // 设置item的显示信息格式 var powderFont = new Font("微软雅黑", 16, FontStyle.Bold); e.Graphics.DrawString(it.PowderName, powderFont, Brushes.Black, e.Bounds, null); var standardWeightFont = new Font("微软雅黑", 10, FontStyle.Regular); e.Graphics.DrawString("标准质量为:" + it.StandardQuality + "g", standardWeightFont, weightBrush, e.Bounds.Left + 3, e.Bounds.Top + 32); }