/// <summary> /// 添加位域信息的按钮点击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddBitFiledInfButton_Click(object sender, EventArgs e) { BitFieldInf newBitFiledInf = new BitFieldInf(); MakeNewRegInfForm(newBitFiledInf, "newReg" + bitFiledCount.ToString()); bitFiledInfSet.Add(newBitFiledInf); newBitFiledInf.Show(); }
/// <summary> /// 创建一个新的位域信息控件,并且显示 /// </summary> /// <param name="newBitFiledInf"></param> /// <param name="bitFiledInfName"></param> private void MakeNewRegInfForm(BitFieldInf newBitFiledInf, string bitFiledInfName) { this.bitFiledShowPanel.Controls.Add(newBitFiledInf); if (bitFiledCount == 0) { newBitFiledInf.Location = new System.Drawing.Point(0, 0); } else { newBitFiledInf.Location = new System.Drawing.Point(0, bitFiledInfSet[bitFiledCount - 1].Location.Y + 190); } newBitFiledInf.Name = bitFiledInfName; bitFiledCount++; //bitFiledInfNewLocationY += 190; }
/// <summary> /// 读取标签化配置信息,逻辑很简单 /// </summary> /// <param name="fileContent"></param> public void ReadFile_RegInf(string fileContent) { string regInfStr; string bitFiledSetStr; int bitFiledIndex = 0; bitFiledIndex = fileContent.IndexOf("[bitFiled]"); string[] regInfStrSet; if (bitFiledIndex == -1) //没有位域信息,可以直接走人了 { regInfStrSet = fileContent.Split('\n'); regInfStr = GetValueInFileString(regInfStrSet[0]); if (regInfStr == "%") { regNameTextBox.Text = ""; } else { regNameTextBox.Text = regInfStr; } regInfStr = GetValueInFileString(regInfStrSet[1]); if (regInfStr == "%") { regAddrTextBox.Text = ""; } else { regAddrTextBox.Text = regInfStr; } return; } regInfStr = fileContent.Substring(0, bitFiledIndex - 3); regInfStrSet = regInfStr.Split('\n'); regInfStr = GetValueInFileString(regInfStrSet[0]); if (regInfStr == "%") { regNameTextBox.Text = ""; } else { regNameTextBox.Text = regInfStr; } regInfStr = GetValueInFileString(regInfStrSet[1]); if (regInfStr == "%") { regAddrTextBox.Text = ""; } else { regAddrTextBox.Text = regInfStr; } bitFiledSetStr = fileContent.Substring(bitFiledIndex); for (int i = 0; i < bitFiledInfSet.Count; i++) { bitFiledInfSet[i].Hide(); bitFiledInfSet[i].Dispose(); } bitFiledInfSet.Clear(); int bitFiledLabelStartIndex = 0; int bitFiledLabelEndIndex = bitFiledSetStr.IndexOf("[#bitFiled]"); while (true) { BitFieldInf newBitFiledInf = new BitFieldInf(); MakeNewRegInfForm(newBitFiledInf, "newBitFiled" + bitFiledInfSet.Count); newBitFiledInf.ReadFile_BitFiledInf(bitFiledSetStr.Substring(bitFiledLabelStartIndex + 11, bitFiledLabelEndIndex - bitFiledLabelStartIndex - 3 - 11)); bitFiledLabelStartIndex = bitFiledSetStr.IndexOf("[bitFiled]", bitFiledLabelEndIndex + 1); bitFiledInfSet.Add(newBitFiledInf); if (bitFiledLabelStartIndex == -1) { break; } bitFiledLabelEndIndex = bitFiledSetStr.IndexOf("[#bitFiled]", bitFiledLabelStartIndex); } }