public void popWinThread() { Random random = new Random(); String message = ""; // Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); RegeditMng myReg = new RegeditMng(ToolName); ReadWriteFile rFile = new ReadWriteFile(); String fileSize_new = rFile.getFileSize(System.AppDomain.CurrentDomain.BaseDirectory + @"\" + level + @".txt"); //前回情報取得 int line_pre; int wordNum_pre; int wordNumCount_pre; String base64_pre = myReg.getRegValue("base64_" + level); String fileSize_pre = myReg.getRegValue("fileSize_" + level); Util.isNumberic(myReg.getRegValue("line_" + level), out line_pre); Util.isNumberic(myReg.getRegValue("wordNum_" + level), out wordNum_pre); Util.isNumberic(myReg.getRegValue("wordNumCount_" + level), out wordNumCount_pre); messageWin.label1.ForeColor = ColorTranslator.FromHtml(myReg.getRegValue("font_color")); Font newFont = new Font(messageWin.label1.Font.FontFamily, float.Parse(myReg.getRegValue("font_size"))); messageWin.label1.Font = newFont; messageWin.line_pre = line_pre; messageWin.wordNum_pre = wordNum_pre; messageWin.wordNumCount_pre = wordNumCount_pre; if (fileSize_pre != fileSize_new) { //前後サイズ違い messageWin.line_pre = 0; messageWin.wordNum_pre = wordNum; messageWin.wordNumCount_pre = 0; myReg.setRegValue("line_" + level, messageWin.line_pre + ""); myReg.setRegValue("wordNum_" + level, messageWin.wordNum_pre + ""); myReg.setRegValue("wordNumCount_" + level, messageWin.wordNumCount_pre + ""); myReg.setRegValue("fileSize_" + level, fileSize_new); } else if (messageWin.wordNum_pre != wordNum) { messageWin.wordNumCount_pre = 0; messageWin.wordNum_pre = wordNum; myReg.setRegValue("wordNumCount_" + level, messageWin.wordNumCount_pre + ""); myReg.setRegValue("wordNum_" + level, messageWin.wordNum_pre + ""); } Boolean breakToTopFlg = false; while (true) { breakToTopFlg = false; if (!isHidden && (!isStoped || isPrev)) //没有隐藏,没有停止或正在翻页 { isPrev = false; if (messageWin.line_pre >= wordList.Count) { //messageWin.Close(); messageWin.label1.Text = "<结束>"; break; } if (wordList != null && wordList.Count > 0) { if (messageWin.wordNumCount_pre * messageWin.wordNum_pre >= wordList[messageWin.line_pre].Length) { message = ""; } else { message = wordList[messageWin.line_pre].Substring(messageWin.wordNumCount_pre * messageWin.wordNum_pre); while (message.Length > 0) { if (isStoped) { messageWin.label1.Text = message.Substring(0, Math.Min(wordNum, message.Length)) + "<停止中>"; } else { messageWin.label1.Text = message.Substring(0, Math.Min(wordNum, message.Length)); } message = message.Substring(Math.Min(wordNum, message.Length)); for (int i = 0; i < delayTime * 2; i++) { Thread.Sleep(500); if (isPrev) { breakToTopFlg = true; break; } } if (breakToTopFlg) { break; } messageWin.wordNumCount_pre = messageWin.wordNumCount_pre + 1; myReg.setRegValue("wordNumCount_" + level, messageWin.wordNumCount_pre + ""); while ((isStoped || isHidden) && !isPrev) //隐藏 或者 停止 且 没在翻页 { Thread.Sleep(500); } } if (breakToTopFlg) { continue; } } /* while (message.Length > wordNum) { * messageWin.label1.Text = message.Substring(0,wordNum); * message = message.Substring(wordNum); * Thread.Sleep(delayTime * 1000); * * messageWin.wordNumCount_pre = messageWin.wordNumCount_pre + 1; * myReg.setRegValue("wordNumCount_" + level, messageWin.wordNumCount_pre + ""); * * while (isStoped || isHidden) * { * Thread.Sleep(delayTime * 1000); * } * } * if (message.Length > 0) { * messageWin.label1.Text = message; * Thread.Sleep(delayTime * 1000); * }*/ messageWin.line_pre = messageWin.line_pre + 1; messageWin.wordNumCount_pre = 0; myReg.setRegValue("line_" + level, messageWin.line_pre + ""); myReg.setRegValue("wordNumCount_" + level, messageWin.wordNumCount_pre + ""); } else { messageWin.label1.Text = "<没有内容>"; //messageWin.Close(); break; } } else { Thread.Sleep(500); } } }
private void button1_Click(object sender, EventArgs e) { // レーベルが選択されない場合 if (!this.radioButton4.Checked && !this.radioButton3.Checked && !this.radioButton2.Checked && !this.radioButton1.Checked) { MessageBox.Show("请选择1,2,3,4"); return; } // 時間が設定されない場合 if (!Util.isNumberic(this.textBox1.Text, out delayTime)) { MessageBox.Show("持续时间没有设置"); return; } // 文字数を設定 if (!Util.isNumberic(this.textBox2.Text, out wordNum)) { MessageBox.Show("一次显示字数没有设置"); return; } // 热键check if (this.hidden_key.Text.Length != 1 || this.stop_key.Text.Length != 1 || this.pre_key.Text.Length != 1) { MessageBox.Show("快捷键没有设置字母"); return; } RegeditMng myReg = new RegeditMng(ToolName); myReg.setRegValue("level", level); myReg.setRegValue("time_" + level, this.textBox1.Text); myReg.setRegValue("wordNum_" + level, this.textBox2.Text); myReg.setRegValue("line_" + level, this.text_nowLine.Text); myReg.setRegValue("base64_" + level, this.checkBox1.Checked.ToString()); myReg.setRegValue("hidden_ctrl", this.hidden_ctrl.Checked.ToString()); myReg.setRegValue("hidden_alt", this.hidden_alt.Checked.ToString()); myReg.setRegValue("hidden_shift", this.hidden_shift.Checked.ToString()); myReg.setRegValue("hidden_key", this.hidden_key.Text); myReg.setRegValue("stop_ctrl", this.stop_ctrl.Checked.ToString()); myReg.setRegValue("stop_alt", this.stop_alt.Checked.ToString()); myReg.setRegValue("stop_shift", this.stop_shift.Checked.ToString()); myReg.setRegValue("stop_key", this.stop_key.Text); myReg.setRegValue("pre_ctrl", this.pre_ctrl.Checked.ToString()); myReg.setRegValue("pre_alt", this.pre_alt.Checked.ToString()); myReg.setRegValue("pre_shift", this.pre_shift.Checked.ToString()); myReg.setRegValue("pre_key", this.pre_key.Text); myReg.setRegValue("next_ctrl", this.next_ctrl.Checked.ToString()); myReg.setRegValue("next_alt", this.next_alt.Checked.ToString()); myReg.setRegValue("next_shift", this.next_shift.Checked.ToString()); myReg.setRegValue("next_key", this.next_key.Text); myReg.setRegValue("font_color", ColorTranslator.ToHtml(this.button_fontColor.ForeColor)); myReg.setRegValue("font_size", this.comboBox_fontSize.Text); myReg.CloseReg(); //若设置界面是可见的,隐藏 if (panel1.Visible) { panel1.Visible = false; this.Height = this.Height - this.panel1.Height; } // 最小化 到 任务栏 this.WindowState = FormWindowState.Minimized; this.ShowInTaskbar = false; this.notifyIcon1.Icon = IconResource.MiniIco; this.notifyIcon1.Visible = true; isHidden = false; ReadWriteFile rFile = new ReadWriteFile(); wordList = rFile.readFile(System.AppDomain.CurrentDomain.BaseDirectory + @"\" + level + @".txt", this.checkBox1.Checked); /*if (messageWin == null || messageWin.IsDisposed) * { * messageWin = new Form2(); * messageWin.Show(); * * messageWin.level = level; * * //thread start * messageThread = new Thread(popWinThread); * messageThread.Start(); * } else if (!messageWin.Visible) { * messageWin.Visible = true; * isHidden = false; * }*/ if (messageWin != null) { messageWin.Close(); } if (messageThread != null) { messageThread.Abort(); } messageWin = new Form2(); messageWin.Owner = this; messageWin.Show(); messageWin.level = level; //thread start messageThread = new Thread(popWinThread); messageThread.Start(); }