//窗口加载时执行的初始化函数 private void TabPage4() { try { ColorBar = new MyColorBar[13]; Loop = new MyColorLoop[5]; TP4_panel_ColorBar = new Panel(); } catch (Exception) { MessageBox.Show("内存空间不足"); Close(); } for (int i = 0; i < 5; i++) { try { Loop[i] = new MyColorLoop(i); Loop[i].MouseEnter += new EventHandler(Loop_MouseEnter); Loop[i].BackColorChanged += new EventHandler(Loop_BackColorChanged); } catch (Exception) { MessageBox.Show("内存空间不足"); Close(); } Loop[i].Height = TP4_panel_Resistor.Height; Loop[i].Width = CB_With; Loop[i].Top = 0; Loop[i].Text = Color_String(Loop[i].BackColor); if (Loop[i].BackColor == Color.White || Loop[i].BackColor == Color.Yellow) Loop[i].ForeColor = Color.Black; else Loop[i].ForeColor = Color.White; } TP4_panel_Resistor.Controls.AddRange(Loop); for (int i = 0; i < 13; i++) { try { ColorBar[i] = new MyColorBar(i); ColorBar[i].MouseClick += new MouseEventHandler(ColorBar_MouseClick); ColorBar[i].MouseEnter += new EventHandler(ColorBar_MouseEnter); } catch (Exception) { MessageBox.Show("内存空间不足"); Close(); } ColorBar[i].Width = CB_With; ColorBar[i].Height = CB_Height; ColorBar[i].Left = 0; } tabPage4.Controls.Add(TP4_panel_ColorBar); TP4_panel_ColorBar.BorderStyle = BorderStyle.FixedSingle; TP4_panel_ColorBar.Visible = false; TP4_panel_ColorBar.Controls.AddRange(ColorBar); TP4_panel_ColorBar.Width = CB_With; TP4_panel_ColorBar.Top = TP4_panel_Resistor.Bottom - 1; Loop[0].Dock = DockStyle.Left; Loop[4].Dock = DockStyle.Right; TP4_comboBox_RUnit.SelectedIndex = 0; TP4_comboBox_Precision.Text = "±5%(J)"; TP4_textBox_RValue.Text = "25"; SetLoopCount(4); }
//当鼠标进入某色环时执行的操作 void Loop_MouseEnter(object sender, EventArgs e) { if (!TP4_panel_ColorBar.Visible) { CurrentLoop = (MyColorLoop)sender; OldColor = CurrentLoop.BackColor; ColorBar_Show(); } }