public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { this._errorCount = 0; StringBuilder sb = new StringBuilder(); foreach (string line in lines) { sb.AppendLine(line); } string rtf = sb.ToString().Trim(); if (!rtf.StartsWith("{\\rtf")) { return; } RichTextBox rtBox = new RichTextBox(); try { rtBox.Rtf = rtf; } catch (Exception exception) { Debug.WriteLine(exception.Message); return; } string text = rtBox.Text; rtBox.Dispose(); this.LoadF4TextSubtitle(subtitle, text); }
public override string ToText(Subtitle subtitle, string title) { StringBuilder sb = new StringBuilder(); sb.AppendLine("#\tAppearance\tCaption\t"); sb.AppendLine(); int count = 1; for (int i = 0; i < subtitle.Paragraphs.Count; i++) { Paragraph p = subtitle.Paragraphs[i]; string text = HtmlUtil.RemoveHtmlTags(p.Text); sb.AppendLine(string.Format("{0}\t{1}\t{2}\t", count.ToString().PadLeft(5, ' '), MakeTimeCode(p.StartTime), text)); sb.AppendLine("\t\t\t\t"); Paragraph next = subtitle.GetParagraphOrDefault(i + 1); if (next == null || Math.Abs(p.EndTime.TotalMilliseconds - next.StartTime.TotalMilliseconds) > 50) { count++; sb.AppendLine(string.Format("{0}\t{1}", count.ToString().PadLeft(5, ' '), MakeTimeCode(p.EndTime))); } count++; } RichTextBox rtBox = new RichTextBox(); rtBox.Text = sb.ToString(); string rtf = rtBox.Rtf; rtBox.Dispose(); return rtf; }
public override string ToText(Subtitle subtitle, string title) { RichTextBox rtBox = new RichTextBox(); rtBox.Text = base.ToText(subtitle, title); string rtf = rtBox.Rtf; rtBox.Dispose(); return rtf; }
public override string ToText(Subtitle subtitle, string title) { const string format = "[{0}]{3}{3}{2}{3}{3}[{1}]{3}"; StringBuilder sb = new StringBuilder(); foreach (Paragraph p in subtitle.Paragraphs) { sb.AppendLine(string.Format(format, EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime), p.Text, Environment.NewLine)); } RichTextBox rtBox = new RichTextBox(); rtBox.Text = sb.ToString(); string rtf = rtBox.Rtf; rtBox.Dispose(); return rtf; }
public override string ToText(Subtitle subtitle, string title) { const string format = "{0}: {1} {2} [{3}]"; StringBuilder sb = new StringBuilder(); int count = 1; foreach (Paragraph p in subtitle.Paragraphs) { sb.AppendLine(string.Format(format, count, EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime), p.Text.Length)); sb.AppendLine(p.Text); sb.AppendLine(); count++; } RichTextBox rtBox = new RichTextBox(); rtBox.Text = sb.ToString(); string rtf = rtBox.Rtf; rtBox.Dispose(); return rtf; }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { this._errorCount = 0; StringBuilder sb = new StringBuilder(); foreach (string line in lines) { sb.AppendLine(line); } string rtf = sb.ToString().Trim(); if (!rtf.StartsWith("{\\rtf")) { return; } string[] arr = null; RichTextBox rtBox = new RichTextBox(); try { rtBox.Rtf = rtf; arr = rtBox.Text.Replace("\r\n", "\n").Split('\n'); } catch (Exception exception) { Debug.WriteLine(exception.Message); return; } finally { rtBox.Dispose(); } List<string> list = new List<string>(); foreach (string s in arr) { list.Add(s); } base.LoadSubtitle(subtitle, list, fileName); }
private void LoadTextFile(string fileName) { try { SubtitleListview1.Items.Clear(); Encoding encoding = Utilities.GetEncodingFromFile(fileName); textBoxText.Text = File.ReadAllText(fileName, encoding); // check for RTF file if (fileName.ToLower().EndsWith(".rtf") && !textBoxText.Text.Trim().StartsWith("{\\rtf")) { var rtBox = new RichTextBox(); rtBox.Rtf = textBoxText.Text; textBoxText.Text = rtBox.Text; rtBox.Dispose(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public override string ToText(Subtitle subtitle, string title) { StringBuilder sb = new StringBuilder(); sb.AppendLine(@"0 2 1.0 1.0 3.0 048 0400 0040 0500 100 100 0 100 0 6600 6600 01 CRULIC R1 ST 0 EB 3.10 @"); int index = 0; foreach (Paragraph p in subtitle.Paragraphs) { // 1 00:50:34:22 00:50:39:13 // Ich muss dafür sorgen, // dass die Epsteins weiterleben index++; sb.AppendLine(string.Format("* {0}-{1} 00.00 00.0 1 {2} 00 16-090-090{3}{4}{3}@", EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime), index.ToString().PadLeft(4, '0'), Environment.NewLine, HtmlUtil.RemoveHtmlTags(p.Text))); } RichTextBox rtBox = new RichTextBox(); rtBox.Text = sb.ToString(); string rtf = rtBox.Rtf; rtBox.Dispose(); return rtf; }
public static void downloadChangeLog(bool calledFromConfig) { // sort the list of patches with the newest first, this correctly display the change log updateCheck.patchList.Sort(delegate(updateCheck.patches p1, updateCheck.patches p2) { return p2.patchVersion.CompareTo(p1.patchVersion); }); RichTextBox richTextBoxInput = new RichTextBox(); RichTextBox richTextBoxOutput = new RichTextBox(); // // Download the change logs // foreach (updateCheck.patches thePatch in updateCheck.patchList) { if (thePatch.patchChangeLog.StartsWith("C:\\")) { System.IO.File.Copy(thePatch.patchChangeLog, Path.Combine(Path.GetTempPath(), "ChangeLog.rtf"), true); return; } WebClient client = new WebClient(); try { client.DownloadFile(thePatch.patchChangeLog, Path.Combine(Path.GetTempPath(), "ChangeLog-" + thePatch.patchVersion.MinorRevision.ToString() + ".rtf")); } catch (Exception e) { if (calledFromConfig) MessageBox.Show("Unable to access ChangeLog-" + thePatch.patchVersion.MinorRevision.ToString() + ".rtf\n\n" + e.Message, "ChangeLog access issue"); //smcLog.WriteLog("Unable to access ChangeLog-" + thePatch.patchVersion.MinorRevision.ToString() + ".rtf > " + e.Message, LogLevel.Error); return; } // smcLog.WriteLog("Downloaded File : " + Path.Combine(Path.GetTempPath(), "ChangeLog-" + thePatch.patchVersion.MinorRevision.ToString() + ".rtf"), LogLevel.Info); } // // And combine them into a single change log // if (File.Exists(Path.Combine(Path.GetTempPath(), "ChangeLog.rtf"))) File.Delete(Path.Combine(Path.GetTempPath(), "ChangeLog.rtf")); //smcLog.WriteLog("Processing Change Log...", LogLevel.Info); try { // Add each file and save as ChangeLog.rtf int patchCnt = 1; AvalonGUIConfig.theRevisions = "Patch: "; foreach (updateCheck.patches thePatch in updateCheck.patchList) { richTextBoxInput.LoadFile(Path.Combine(Path.GetTempPath(), "ChangeLog-" + thePatch.patchVersion.MinorRevision.ToString() + ".rtf")); richTextBoxInput.SelectAll(); richTextBoxInput.Copy(); richTextBoxOutput.Paste(); System.IO.File.Delete(Path.Combine(Path.GetTempPath(), "ChangeLog-" + thePatch.patchVersion.MinorRevision.ToString() + ".rtf")); if (patchCnt < updateCheck.patchList.Count) AvalonGUIConfig.theRevisions = AvalonGUIConfig.theRevisions + thePatch.patchVersion.ToString() + " / "; else AvalonGUIConfig.theRevisions = AvalonGUIConfig.theRevisions + thePatch.patchVersion.ToString(); patchCnt++; } richTextBoxOutput.SaveFile(Path.Combine(Path.GetTempPath(), "ChangeLog.rtf")); richTextBoxInput.Dispose(); richTextBoxOutput.Dispose(); } catch (Exception ex) { Log.Error("Exception Reading Change Logs: " + ex.Message + "\\n" + ex.StackTrace); } }
/// <summary> /// ���RTF�ı� /// </summary> /// <param name="text"></param> void P3AddRtfMsg(string rtf) { int selStart = this.rtbP3Msg.Text.Length; this.rtbP3Msg.Select(selStart, 0); try { this.rtbP3Msg.SelectedRtf = rtf; } catch //����������ȵط����ͼ�ʱ��Ϣʱ�����Ϊ��RTF��ʽ������ { RichTextBox box = new RichTextBox(); box.Text = rtf; this.rtbP3Msg.SelectedRtf = box.Rtf; box.Dispose(); } //�������� this.rtbP3Msg.Select(selStart, this.rtbP3Msg.Text.Length); this.rtbP3Msg.SelectionIndent = 16; this.rtbP3Msg.Select(this.rtbP3Msg.Text.Length, 0); this.rtbP3Msg.ScrollToCaret(); }
/// <summary> /// Builds the notedocks. /// </summary> void BuildNoteDocks() { try { // step 1: delete any existing notedocks if (CaptionLabel != null && CaptionLabel.Items != null && CaptionLabel.Items.Count > 0) for (int i = CaptionLabel.Items.Count-1; i >=0; i--) { ToolStripItem control = (ToolStripItem)CaptionLabel.Items [i]; if (control.Tag != null) { if (control.Tag.ToString () == "NoteDock") { CaptionLabel.Items.Remove ((ToolStripItem)control); } } } // // 03/11/2014 // // Add custom button links (to give user ability to pair development notes with chapters) // //string customNoteLinks = "note1*44159e01-b2c6-4b1f-9b68-8d3c85755f14*chapter1;[[wordcount]]*44159e01-b2c6-4b1f-9b68-8d3c85755f14*chapter1"; // quick test just fake it //foreach (string link in customNoteLinks) { // breakdown strings string[] links = this.Notedocks.Split (new char[1]{';'}, StringSplitOptions.RemoveEmptyEntries); if (links != null && links.Length > 0) { foreach (string link_unit in links) { string[] units = link_unit.Split (new char[1]{'*'}, StringSplitOptions.RemoveEmptyEntries); // anchor optional if (units != null && units.Length >= 2) { ToolStripButton noteLink = new ToolStripButton (); noteLink.Text = units [0]; // // tag contains GUID plus anchor reference. // noteLink.Tag = units[1]; // // // final anchor is optional // if (units.Length == 3) // { // noteLink.Tag = units[1] + "*" + units[2]; // } noteLink.Tag = "NoteDock"; if (units [0] == "[[wordcount]]") { noteLink.Text = "<press for word count>"; noteLink.Click += (object sender, EventArgs e) => { if (this.IsPanel) { int maxwords = 0; int maxwords2=0; // able to show three numbers. Document 0/2309 (next stage) / 99999 max Int32.TryParse (units [1], out maxwords); if (units.Length == 3) { Int32.TryParse (units [2], out maxwords2); } int words = 0; //NewMessage.Show ("boo"); // iterate through all notes foreach (NoteDataInterface note_ in this.ListOfSubnotesAsNotes()) { //NewMessage.Show (note_.Caption); if (note_ is NoteDataXML_RichText) { // fetch word count //((NoteDataXML_RichText)note_).GetRichTextBox(). if (LayoutDetails.Instance.WordSystemInUse != null) { try{ // we fetch data1 because the actual rich text box is NOT loaded // but I found the word count quite excessive so we load it instead RichTextBox faker = new RichTextBox(); faker.Rtf = ((NoteDataXML_RichText)note_).Data1; string ftext = faker.Text; faker.Dispose (); words = words + LayoutDetails.Instance.WordSystemInUse.CountWords(ftext); } catch(System.Exception) { NewMessage.Show (Loc.GetStr("ERROR: Internal Word System Word Counting Error")); } } else { NewMessage.Show (Loc.GetStr("Is there a Word system installed for counting words?")); } } } if (maxwords2 > 0) { noteLink.Text = String.Format ("{0}/{1}/{2}", words, maxwords, maxwords2); } else if (maxwords > 0) { noteLink.Text = String.Format ("{0}/{1}", words, maxwords); } else { noteLink.Text = String.Format ("{0}", words); } } else { NewMessage.Show (Loc.Instance.GetString ("Word Count only works if attached to a Layout Note")); } }; } else noteLink.Click += (object sender, EventArgs e) => { string theNoteGuid = units [1]; string linkanchor = ""; if (units.Length == 3) { linkanchor = units [2]; } LayoutPanelBase SuperParent = null; if (this.Layout.GetIsChild == true) SuperParent = this.Layout.GetAbsoluteParent (); else SuperParent = this.Layout; NoteDataInterface theNote = this.Layout.GetNoteOnSameLayout (theNoteGuid, false); //NewMessage.Show ("hi " + theNoteGuid); // GetNonteOnSameLayout always returns a valid note. if (theNote != null && theNote.Caption != "findme") { // // Toggle Visibility State // if (theNote.Visible == true) { //NewMessage.Show ("Hide"); theNote.Visible = false; theNote.UpdateLocation (); } else { //NewMessage.Show ("Show"); int theNewX = this.Location.X; int theNewY = this.Location.Y; if (this.Layout.GetIsChild) { //NewMessage.Show ("child"); //ok this seems convulted but I need to get the Note containing this layout // and there does not seem to be a short cut for it. string GuidOfLayoutNote = this.Layout.GUID; NoteDataInterface parentNote = SuperParent.GetNoteOnSameLayout (GuidOfLayoutNote, false); if (parentNote != null) { //NewMessage.Show (GuidOfLayoutNote); // if we are a child then use the coordinates of the layoutpanel itself theNewX = parentNote.Location.X; theNewY = parentNote.Location.Y; theNote.Height = Math.Max (0, parentNote.Height / 2); theNote.Width = Math.Max (0, parentNote.Width - 4); } else { NewMessage.Show ("Parent note with GUID was blank " + GuidOfLayoutNote); } } else { // get width and height from non-layout enclosed note theNote.Height = Math.Max (0, this.Height / 2); theNote.Width = Math.Max (0, this.Width - 4); } // now offset a bit theNewX = theNewX + 25; theNewY = theNewY + 100; theNote.Location = new Point (theNewX, theNewY); theNote.Visible = true; theNote.UpdateLocation (); // so size changes stick //theNote.BringToFrontAndShow (); theNote = this.Layout.GetNoteOnSameLayout (theNoteGuid, true, linkanchor); } // this.Layout.GoToNote(theNote); } else { NewMessage.Show (Loc.Instance.GetStringFmt ("The guid {0} was null", theNoteGuid)); } }; // The click CaptionLabel.Items.Add (noteLink); // do this after adding to INHERIT the proper styles from TOOLBAR // reverse color scheme // coloring should happen in UPDATE apeparance // Color foreC = CaptionLabel.BackColor; // Color backC = CaptionLabel.ForeColor; noteLink.Font = new Font (noteLink.Font.FontFamily, noteLink.Font.Size - 1); // noteLink.BackColor = app.captionBackground;; // noteLink.ForeColor = backC; } } } } } catch (System.Exception ex) { NewMessage.Show (ex.ToString ()); } }
/// <summary> /// The load subtitle. /// </summary> /// <param name="subtitle"> /// The subtitle. /// </param> /// <param name="lines"> /// The lines. /// </param> /// <param name="fileName"> /// The file name. /// </param> public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { this._errorCount = 0; StringBuilder sb = new StringBuilder(); foreach (string line in lines) { sb.AppendLine(line); } string rtf = sb.ToString().Trim(); if (!rtf.StartsWith("{\\rtf")) { return; } string text = string.Empty; RichTextBox rtBox = new RichTextBox(); try { rtBox.Rtf = rtf; text = rtBox.Text.Replace("\r\n", "\n"); } catch (Exception exception) { Debug.WriteLine(exception.Message); return; } finally { rtBox.Dispose(); } lines = new List<string>(); foreach (string line in text.Split('\n')) { lines.Add(line); } this._errorCount = 0; Paragraph p = null; sb = new StringBuilder(); foreach (string line in lines) { string s = line.TrimEnd(); if (RegexTimeCode1.IsMatch(s)) { try { if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } sb = new StringBuilder(); string[] arr = s.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (arr.Length == 3) { p = new Paragraph(DecodeTimeCode(arr[1]), DecodeTimeCode(arr[2]), string.Empty); } } catch { this._errorCount++; p = null; } } else if (p != null && s.Length > 0) { sb.AppendLine(s.Trim()); } else if (!string.IsNullOrWhiteSpace(s)) { this._errorCount++; } } if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } subtitle.Renumber(); }
public string ReadingPassageONQuestion(int questionNO, int spiltQuestionNO) { RichTextBox box = new RichTextBox(); if (spiltQuestionNO != 0) { string text; string str2; RichTextBox box2 = new RichTextBox(); int num = 0; int index = 0; if (questionNO <= spiltQuestionNO) { box2.Rtf = this.FullRTF; text = box2.Text; num = text.IndexOf("<PASSAGE1>") + 10; index = text.IndexOf("</PASSAGE1>"); box2.SelectionStart = num; box2.SelectionLength = index - num; box.Rtf = box2.SelectedRtf; box2.Rtf = this.FullTranslation; str2 = box2.Text; num = str2.IndexOf("<TRANSLATION1>") + 14; index = str2.IndexOf("</TRANSLATION1>"); box2.SelectionStart = num; box2.SelectionLength = index - num; this.Translation = box2.SelectedRtf; } else { box2.Rtf = this.FullRTF; text = box2.Text; num = text.IndexOf("<PASSAGE2>") + 10; index = text.IndexOf("</PASSAGE2>"); box2.SelectionStart = num; box2.SelectionLength = index - num; box.Rtf = box2.SelectedRtf; box2.Rtf = this.FullTranslation; str2 = box2.Text; num = str2.IndexOf("<TRANSLATION2>") + 14; index = str2.IndexOf("</TRANSLATION2>"); box2.SelectionStart = num; box2.SelectionLength = index - num; this.Translation = box2.SelectedRtf; } } else { box.Rtf = this.FullRTF; this.Translation = this.FullTranslation; } for (int i = 1; i < ConstantValues.MAXQUESTIONCOUNT; i++) { string str3; string str4; int num4; int num5; if (i == questionNO) { str3 = "<" + i.ToString() + ">"; str4 = "</" + i.ToString() + ">"; num4 = box.Text.IndexOf(str3); num5 = box.Text.IndexOf(str4); RichTextBox box3 = new RichTextBox(); while ((num4 >= 0) && (num5 >= 0)) { box.SelectionStart = num4; box.SelectionLength = str3.Length; box.Cut(); box.SelectedRtf = ""; box.SelectionStart = num5 - str3.Length; box.SelectionLength = str4.Length; box.Cut(); box.SelectedRtf = ""; num4 = box.Text.IndexOf(str3); num5 = box.Text.IndexOf(str4); } str3 = "[" + i.ToString() + "]"; str4 = "[/" + i.ToString() + "]"; num4 = box.Text.IndexOf(str3); num5 = box.Text.IndexOf(str4); if (num4 >= 0) { box.SelectionStart = num4; box.SelectionLength = str3.Length; box.Cut(); box.SelectedRtf = ""; } if (num5 >= 0) { box.SelectionStart = num5 - str3.Length; box.SelectionLength = str4.Length; box.Cut(); box.SelectedRtf = ""; } str3 = "{" + i.ToString() + "}"; str4 = "{/" + i.ToString() + "}"; num4 = box.Text.IndexOf(str3); num5 = box.Text.IndexOf(str4); while ((num4 >= 0) || (num5 >= 0)) { if (num4 >= 0) { box.SelectionStart = num4; box.SelectionLength = str3.Length; box.Cut(); box.SelectedRtf = ""; } if (num5 >= 0) { box.SelectionStart = num5 - str3.Length; box.SelectionLength = str4.Length; box.Cut(); box.SelectedRtf = ""; } num4 = box.Text.IndexOf(str3); num5 = box.Text.IndexOf(str4); } } else { string str5 = "<" + i.ToString() + ">◆</" + i.ToString() + ">"; int num6 = box.Text.IndexOf(str5); while (num6 >= 0) { box.SelectionStart = num6; box.SelectionLength = str5.Length; box.Cut(); box.SelectedRtf = ""; num6 = box.Text.IndexOf(str5); } str5 = "{" + i.ToString() + "}█{/" + i.ToString() + "}"; for (num6 = box.Text.IndexOf(str5); num6 >= 0; num6 = box.Text.IndexOf(str5)) { box.SelectionStart = num6; box.SelectionLength = str5.Length; box.Cut(); box.SelectedRtf = ""; } str3 = "[" + i.ToString() + "]"; str4 = "[/" + i.ToString() + "]"; num4 = box.Text.IndexOf(str3); num5 = box.Text.IndexOf(str4); if (num4 >= 0) { box.SelectionStart = num4; box.SelectionLength = str3.Length; box.Cut(); box.SelectedRtf = ""; } if (num5 >= 0) { box.SelectionStart = num5 - str3.Length; box.SelectionLength = str4.Length; box.Cut(); box.SelectedRtf = ""; } if (num5 > num4) { box.SelectionStart = num4 - 1; box.SelectionLength = ((num5 - num4) - str3.Length) + 2; string selectedText = box.SelectedText; box.SelectedText = selectedText; } } } string rtf = box.Rtf; box.Dispose(); return rtf; }
private void htmEdit1_OnNewDocument(object sender, EventArgs e) { if (winTextBox1.Modified == false) { //新建立的文件名自动重命名 RichTextBox tmpRichTextBox1 = new RichTextBox(); tmpRichTextBox1.Text = htmEdit1.webBrowser1.Document.Body.InnerText; //移动空行 string s = ""; for (int i = 0; i < tmpRichTextBox1.Lines.Length; i++) { if (tmpRichTextBox1.Lines[i].Trim() != "\r\n") s += tmpRichTextBox1.Lines[i] + "\r\n"; } tmpRichTextBox1.Text = tmpRichTextBox1.Text.Trim(); WinTextBox tmpWinTextBox1 = new WinTextBox(); tmpWinTextBox1.Text = tmpRichTextBox1.Lines[0]; string filename = Path.GetDirectoryName(FullFileName) + "\\" + tmpWinTextBox1.Text + ".htm"; filename = FileCore.NewName(filename); if (!File.Exists(filename)) { string name1 = Path.GetFileNameWithoutExtension(filename); if (name1.Length <= winTextBox1.MaxLength) { winTextBox1.Text = name1; winTextBox1_LostFocus(sender, e); } } tmpRichTextBox1.Dispose(); tmpWinTextBox1.Dispose(); } }
public void OnRecievedData(IAsyncResult ar) { Socket sock = (Socket)ar.AsyncState; if (!uiRichTextBoxHistory.InvokeRequired) { try { int nBytesRec = sock.EndReceive(ar); if (nBytesRec > 0) { //string sRecieved = Encoding.Unicode.GetString(buffer, 0, nBytesRec); if (buffer == null) buffer = new byte[nBytesRec]; MemoryStream msgStream = new MemoryStream(); ClientCommand msgCommand = new ClientCommand(); msgStream.Write(buffer, 0, nBytesRec); BinaryFormatter deserializer = new BinaryFormatter(); msgStream.Position = 0; msgCommand = (ClientCommand)deserializer.Deserialize(msgStream); // OnAddMessage(sRecieved); // View Messages here if (msgCommand.MessageType == ClientCommand.msgType.JoinRoom || msgCommand.MessageType == ClientCommand.msgType.LeaveRoom) { LoadMembers(); } else if (msgCommand.Sender != CurrentUser.Client.Name) { RichTextBox temp = new RichTextBox(); temp.Text = msgCommand.Sender + " says : \n\r" + msgCommand.Message; temp.Select(0, temp.Text.IndexOf(" says :") + 7); temp.SelectionFont = new System.Drawing.Font(temp.SelectionFont.FontFamily, temp.Font.Size, FontStyle.Bold); foreach (var item in CurrentUser.Emotions) { int _index; if ((_index = temp.Find(item.Key)) > -1) { temp.Select(_index, item.Key.Length); InsertImage(new Bitmap(this.Parent.Parent.GetType(), item.Value), temp); } } uiRichTextBoxHistory.SelectedRtf = temp.Rtf; temp.Dispose(); } SetupRecieveCallback(sock); } else { sock.Shutdown(SocketShutdown.Both); sock.Close(); } } catch (Exception) { } } else { HandleOnRecievedDataCallBack b = new HandleOnRecievedDataCallBack(OnRecievedData); this.Invoke(b, new object[] { ar }); } }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { // * 00001.00-00003.00 02.01 00.0 1 0001 00 16-090-090 // CRULIC R1 // pour Bobi // @ this._errorCount = 0; StringBuilder sb = new StringBuilder(); foreach (string line in lines) { sb.AppendLine(line); } string rtf = sb.ToString().Trim(); if (!rtf.StartsWith("{\\rtf")) { return; } string[] arr = null; RichTextBox rtBox = new RichTextBox(); try { rtBox.Rtf = rtf; arr = rtBox.Text.Replace("\r\n", "\n").Split('\n'); } catch (Exception exception) { Debug.WriteLine(exception.Message); return; } finally { rtBox.Dispose(); } Paragraph p = null; subtitle.Paragraphs.Clear(); foreach (string line in arr) { if (regexTimeCodes.IsMatch(line.Trim())) { string[] temp = line.Substring(1).Trim().Substring(0, 17).Split('-'); if (temp.Length == 2) { string start = temp[0]; string end = temp[1]; string[] startParts = start.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries); string[] endParts = end.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries); if (startParts.Length == 2 && endParts.Length == 2) { p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), string.Empty); subtitle.Paragraphs.Add(p); } } } else if (string.IsNullOrWhiteSpace(line) || line.Trim() == "@") { // skip these lines } else if (!string.IsNullOrWhiteSpace(line) && p != null) { if (p.Text.Length > 2000) { return; // wrong format } if (string.IsNullOrEmpty(p.Text)) { p.Text = line; } else { p.Text = p.Text + Environment.NewLine + line; } } } subtitle.Renumber(); }
public void Build(RichTextBox rtb) { if(rtb == null) throw new ArgumentNullException("rtb"); RichTextBox rtbOp = new RichTextBox(); rtbOp.Visible = false; // Ensure invisibility rtbOp.DetectUrls = false; rtbOp.HideSelection = true; rtbOp.Multiline = true; rtbOp.WordWrap = false; rtbOp.Text = m_sb.ToString(); Debug.Assert(rtbOp.Text == m_sb.ToString()); // Test committed if(m_fDefault != null) { rtbOp.Select(0, rtbOp.TextLength); rtbOp.SelectionFont = m_fDefault; } string strRtf = rtbOp.Rtf; rtbOp.Dispose(); foreach(RtfbTag rTag in m_vTags) strRtf = strRtf.Replace(rTag.IdCode, rTag.RtfCode); rtb.Rtf = strRtf; }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { this._errorCount = 0; StringBuilder sb = new StringBuilder(); foreach (string line in lines) { sb.AppendLine(line); } string rtf = sb.ToString().Trim(); if (!rtf.StartsWith("{\\rtf")) { return; } string[] arr = null; RichTextBox rtBox = new RichTextBox(); try { rtBox.Rtf = rtf; arr = rtBox.Text.Replace("\r", string.Empty).Split('\n'); } catch (Exception exception) { Debug.WriteLine(exception.Message); return; } finally { rtBox.Dispose(); } Paragraph p = new Paragraph(); subtitle.Paragraphs.Clear(); foreach (string line in arr) { string s = line.Trim(); if (s.StartsWith('[') && s.EndsWith('>') && s.Length > 13 && s[12] == ']') { s = s.Substring(0, 13); } Match match = regexTimeCodes.Match(s); if (match.Success) { string[] parts = s.Replace("[", string.Empty).Replace("]", string.Empty).Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 1) { try { if (!string.IsNullOrEmpty(p.Text)) { p.EndTime = DecodeTimeCode(parts[0]); subtitle.Paragraphs.Add(p); p = new Paragraph(); } else { p.StartTime = DecodeTimeCode(parts[0]); } } catch (Exception exception) { this._errorCount++; Debug.WriteLine(exception.Message); } } } else if (string.IsNullOrWhiteSpace(line)) { } else { p.Text = (p.Text + Environment.NewLine + line).Trim(); if (p.Text.Length > 500) { this._errorCount += 10; return; } while (p.Text.Contains(Environment.NewLine + " ")) { p.Text = p.Text.Replace(Environment.NewLine + " ", Environment.NewLine); } } } if (!string.IsNullOrEmpty(p.Text)) { subtitle.Paragraphs.Add(p); } subtitle.RemoveEmptyLines(); subtitle.Renumber(); }
private void rtb_Passage_MouseClick(object sender, MouseEventArgs e) { int charIndexFromPosition = this.rtb_Passage.GetCharIndexFromPosition(e.Location); if (this.QuestionNO > 0) { Question question = (Question)this.TestQuestions.Questions[this.QuestionNO - 1]; if ((question.QuestionType == QuestionType.INSERT) && this.rtb_Passage.Text[charIndexFromPosition].Equals('█')) { int textLength = 1; if (this.PreInsertPosition != -1) { RichTextBox box = new RichTextBox(); box.Rtf = this.InsertSetenceRtf; textLength = box.TextLength; box.Dispose(); this.rtb_Passage.SelectionStart = this.PreInsertPosition; this.rtb_Passage.SelectionLength = textLength; this.rtb_Passage.SelectedText = "█"; this.rtb_Passage.DeselectAll(); } if (this.PreInsertPosition > charIndexFromPosition) { this.rtb_Passage.SelectionStart = charIndexFromPosition; this.rtb_Passage.SelectionLength = 1; this.rtb_Passage.SelectedRtf = this.InsertSetenceRtf; this.PreInsertPosition = charIndexFromPosition; } else if (this.PreInsertPosition < charIndexFromPosition) { charIndexFromPosition = (charIndexFromPosition - textLength) + 1; this.rtb_Passage.SelectionStart = charIndexFromPosition; this.rtb_Passage.SelectionLength = 1; this.rtb_Passage.SelectedRtf = this.InsertSetenceRtf; this.PreInsertPosition = charIndexFromPosition; } else { this.PreInsertPosition = -1; } int index = this.rtb_Passage.Text.Substring(0, charIndexFromPosition).Split(new char[] { '█' }).Length - 1; this.CkbReading[index].Checked = true; this.rtb_Passage.DeselectAll(); } } }
private void HandleMsg(IMessage oMessage) { switch (oMessage.Type) { case MessageType.MESSAGE_AUTH_ACCEPT: break; case MessageType.MESSAGE_AUTH_DECLINE: break; case MessageType.MESSAGE_AUTH_REQUEST: break; case MessageType.MESSAGE_AUTO_RESPONSE: break; case MessageType.MESSAGE_CUSTOM_AWAY: break; case MessageType.MESSAGE_ERROR: break; case MessageType.MESSAGE_IM: case MessageType.MESSAGE_IM_OFFLINE: if (!oMessage.Message.StartsWith("##ConfCall##")) { RichTextBox temp = new RichTextBox(); temp.Text = oMessage.Sender + " says :\n\r " + oMessage.Message; temp.Select(0, temp.Text.IndexOf(" says :") + 7); temp.SelectionFont = new System.Drawing.Font(temp.SelectionFont.FontFamily, temp.Font.Size, FontStyle.Bold); foreach (var item in CurrentUser.Emotions) { int _index; if ((_index = temp.Find(item.Key)) > -1) { temp.Select(_index, item.Key.Length); InsertImage(new Bitmap(typeof(uiFormMain), item.Value), temp); } } // temp.Text = oMessage.Sender + " says :\n\r " + temp.Text; uiRichTextBoxHistory.SelectedRtf = temp.Rtf; temp.Dispose(); } else { Calluser(oMessage.Message.Substring(oMessage.Message.LastIndexOf("##") + 2)); InCall = true; } break; case MessageType.MESSAGE_TYPING: break; case MessageType.MESSAGE_TYPING_OFF: break; case MessageType.MESSAGE_WARNING: break; default: break; } }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { subtitle.Paragraphs.Clear(); subtitle.Header = null; byte[] buffer = FileUtil.ReadAllBytesShared(fileName); int i = 128; Paragraph last = null; while (i < buffer.Length - 20) { if (buffer[i] == 0x0b) { string timeCode = Encoding.ASCII.GetString(buffer, i + 1, 11); if (timeCode != "00:00:00:00" && regexTimeCodes.IsMatch(timeCode)) { Paragraph p = new Paragraph(); p.StartTime = DecodeTimeCode(timeCode.Split(':')); bool italic = buffer[i + 22] == 3; // 3=italic, 1=normal int textStart = i + 25; // text starts 25 chars after time code int textLength = 0; while (textStart + textLength < buffer.Length && buffer[textStart + textLength] != 0) { textLength++; } if (textLength > 0) { p.Text = Encoding.GetEncoding(1252).GetString(buffer, textStart, textLength); int rtIndex = p.Text.IndexOf("{\\rtf1", StringComparison.Ordinal); if (rtIndex >= 0 && rtIndex < 10) { RichTextBox rtBox = new RichTextBox(); try { rtBox.Rtf = p.Text.Substring(rtIndex); p.Text = rtBox.Text; } catch (Exception exception) { Debug.WriteLine(exception.Message); } rtBox.Dispose(); } else if (italic) { p.Text = "<i>" + p.Text + "</i>"; } } else { p.Text = string.Empty; } last = p; subtitle.Paragraphs.Add(p); } } i++; } if (last != null) { last.EndTime.TotalMilliseconds = last.StartTime.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(last.Text); } for (i = 0; i < subtitle.Paragraphs.Count - 1; i++) { subtitle.Paragraphs[i].EndTime.TotalMilliseconds = subtitle.Paragraphs[i + 1].StartTime.TotalMilliseconds; } for (i = subtitle.Paragraphs.Count - 1; i >= 0; i--) { if (string.IsNullOrEmpty(subtitle.Paragraphs[i].Text)) { subtitle.Paragraphs.RemoveAt(i); } } List<int> deletes = new List<int>(); for (i = 0; i < subtitle.Paragraphs.Count - 1; i++) { if (subtitle.Paragraphs[i].StartTime.TotalMilliseconds == subtitle.Paragraphs[i + 1].StartTime.TotalMilliseconds) { subtitle.Paragraphs[i].Text += Environment.NewLine + subtitle.Paragraphs[i + 1].Text; subtitle.Paragraphs[i].EndTime = subtitle.Paragraphs[i + 1].EndTime; deletes.Add(i + 1); } } deletes.Reverse(); foreach (int index in deletes) { subtitle.Paragraphs.RemoveAt(index); } for (i = 0; i < subtitle.Paragraphs.Count - 1; i++) { if (subtitle.Paragraphs[i].StartTime.TotalMilliseconds == subtitle.Paragraphs[i + 1].StartTime.TotalMilliseconds) { } else if (subtitle.Paragraphs[i].EndTime.TotalMilliseconds == subtitle.Paragraphs[i + 1].StartTime.TotalMilliseconds) { subtitle.Paragraphs[i].EndTime.TotalMilliseconds = subtitle.Paragraphs[i + 1].StartTime.TotalMilliseconds - 1; } } subtitle.Renumber(); // adjust all times if (buffer.Length > 1364) { try { string adjust = Encoding.GetEncoding(1252).GetString(buffer, 1354, 11); // 00:59:59:28 TimeCode tc = DecodeTimeCode(adjust.Split(':')); if (tc.TotalMilliseconds > 0) { subtitle.AddTimeToAllParagraphs(TimeSpan.FromMilliseconds(-tc.TotalMilliseconds)); } } catch { } } }
///<summary>We need this special function to draw strings just like the RichTextBox control does, because sheet text is displayed using RichTextBoxes within FormSheetFillEdit. ///Graphics.DrawString() uses a different font spacing than the RichTextBox control does.</summary> private void DrawRTFstring(int index,string str,Font font,Brush brush,Graphics g) { str=str.Replace("\r","");//For some reason '\r' throws off character position calculations. \n still handles the CRs. SheetFieldDef field=SheetDefCur.SheetFieldDefs[index]; //Font spacing is different for g.DrawString() as compared to RichTextBox and TextBox controls. //We create a RichTextBox here in the same manner as in FormSheetFillEdit, but we only use it to determine where to draw text. //We do not add the RichTextBox control to this form, because its background will overwrite everything behind that we have already drawn. bool doCalc=true; object[] data=(object[])HashRtfStringCache[index.ToString()]; if(data!=null) {//That field has been calculated //If any of the following factors change, then that could potentially change text positions. if(field.FontName.CompareTo(data[1])==0//Has font name changed since last pass? && field.FontSize.CompareTo(data[2])==0//Has font size changed since last pass? && field.FontIsBold.CompareTo(data[3])==0//Has font boldness changed since last pass? && field.Width.CompareTo(data[4])==0//Has field width changed since last pass? && field.Height.CompareTo(data[5])==0//Has field height changed since last pass? && str.CompareTo(data[6])==0//Has field text changed since last pass? && field.TextAlign.CompareTo(data[7])==0)//Has field text align changed since last pass? { doCalc=false;//Nothing has changed. Do not recalculate. } } if(doCalc) { //Data has not yet been cached for this text field, or the field has changed and needs to be recalculated. //All of these textbox fields are set using the same logic as in FormSheetFillEdit, so that text in this form matches exaclty. RichTextBox textbox=new RichTextBox(); textbox.Visible=false; textbox.BorderStyle=BorderStyle.None; textbox.ScrollBars=RichTextBoxScrollBars.None; textbox.SelectionAlignment=field.TextAlign; textbox.Location=new Point(field.XPos,field.YPos); textbox.Width=field.Width; textbox.Height=field.Height; textbox.Font=font; textbox.ForeColor=((SolidBrush)brush).Color; if(field.Height<textbox.Font.Height+2) {//Same logic as FormSheetFillEdit. textbox.Multiline=false; } else { textbox.Multiline=true; } textbox.Text=str; Point[] positions=new Point[str.Length]; for(int j=0;j<str.Length;j++) { positions[j]=textbox.GetPositionFromCharIndex(j);//This line is slow, so we try to minimize calling it by chaching positions each time there are changes. } textbox.Dispose(); data=new object[] { positions,field.FontName,field.FontSize,field.FontIsBold,field.Width,field.Height,str,field.TextAlign }; HashRtfStringCache[index.ToString()]=data; } Point[] charPositions=(Point[])data[0]; for(int j=0;j<charPositions.Length;j++) { //This will draw text below the bottom line if the text is long. This is by design, so the user can see that the text is too big. g.DrawString(str.Substring(j,1),font,brush,field.Bounds.X+charPositions[j].X,field.Bounds.Y+charPositions[j].Y); } }
/// <summary> /// Parses the note into table -- will added each line /// </summary> /// <param name='note'> /// Note. /// </param> void ParseNoteIntoTable(NoteDataInterface note) { RichTextBox tmp = new RichTextBox(); tmp.Rtf = note.Data1; string Source = tmp.Text; tmp.Dispose(); // assuming is not null, already tested for this string[] ImportedItems = Source.Split (new string[2]{"\r\n","\n"}, StringSplitOptions.RemoveEmptyEntries); if (ImportedItems != null && ImportedItems.Length > 0) { //int count = 0; foreach (string item in ImportedItems) { if (item != Constants.BLANK) { if (IsTextAlreadyInTable(item) == false) { int count = RowCount(); this.AddRow (new object[3]{count.ToString (),item, "0"}); //count++; } } // if text IS IN table, we don't do anything during a parse. } } }
int WriteANote(NoteDataInterface note, bool bGetWords, ref string sWordInformation, StreamWriter writer) { int words = 0; if (note != null && (note is NoteDataXML_RichText)) { RichTextBox tempBox = new RichTextBox(); tempBox.Rtf = note.Data1; SaveTextLineByLine(writer, tempBox.Lines, note.Caption); if (true == bGetWords) { int Words = LayoutDetails.Instance.WordSystemInUse.CountWords(tempBox.Text); words = Words;//TotalWords = TotalWords + Words; sWordInformation = sWordInformation + String.Format("{0}: {1}{2}", note.Caption, Words.ToString(), Environment.NewLine); } tempBox.Dispose(); } return words; }
private void HelpForm_Load(object sender, EventArgs e) { string strRtf = string.Empty; Cursor.Current=Cursors.WaitCursor; try { if (File.Exists(Application.StartupPath + @"\Effects\" + "ShapeMaker.rtf")) { using (TextReader tr = File.OpenText(Application.StartupPath + @"\Effects\" + "ShapeMaker.rtf")) { strRtf = tr.ReadToEnd(); } } else { MessageBox.Show("Help File Not Found!"); Cursor.Current = Cursors.Default; return; } } catch (Exception c) { MessageBox.Show("File Load Error - " + c); Cursor.Current = Cursors.Default; return; } if (strRtf == string.Empty) { Cursor.Current = Cursors.Default; return; } int result = 0; int result2 = 0; int indexer = 0; int stopper = 0; RichTextBox rtbTmp = new RichTextBox(); //find bookmarks string seek = @"{\*\bkmkstart "; do { result = strRtf.IndexOf(seek, result); if (result != -1) { result2 = strRtf.IndexOf("}", result); int pos = result + seek.Length; rtbTmp.Rtf = strRtf.Substring(0, result) + "}"; targets.Add(strRtf.Substring(pos, result2 - pos), rtbTmp.Text.Length); result = result2; } } while (result != -1); //find nyperlinks result = 0; seek = "HYPERLINK "; do { result = strRtf.IndexOf(@seek, result); if (result != -1) { string look = "{\\field"; result2 = strRtf.LastIndexOf(@look, result); look = "" + (char)34; int res = strRtf.IndexOf(look, result) + 1; indexer = strRtf.IndexOf(look, res); int counter = 0; int len = result2; do { string countchar = strRtf.Substring(len++, 1); counter = (countchar == "{") ? counter + 1 : (countchar == "}") ? counter - 1 : counter; } while (counter != 0); stopper = len; rtbTmp.Rtf = strRtf.Substring(0, result2) + "}"; int start2 = rtbTmp.Text.Length; rtbTmp.Rtf = strRtf.Substring(0, stopper) + "}"; int end2 = rtbTmp.Text.Length; hotspots.Add(new bmark() { BookMark = strRtf.Substring(res, indexer - res) , start = start2, end = end2 }); result = stopper + 1; } } while (result != -1); RTB.Rtf = strRtf; strRtf = String.Empty; rtbTmp.Dispose(); Cursor.Current = Cursors.Default; }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { this._errorCount = 0; StringBuilder sb = new StringBuilder(); foreach (string line in lines) { sb.AppendLine(line); } string rtf = sb.ToString().Trim(); if (!rtf.StartsWith("{\\rtf")) { return; } string text = string.Empty; RichTextBox rtBox = new RichTextBox(); try { rtBox.Rtf = rtf; text = rtBox.Text.Replace("\r\n", "\n"); } catch (Exception exception) { Debug.WriteLine(exception.Message); return; } finally { rtBox.Dispose(); } lines = new List<string>(); foreach (string line in text.Split('\n')) { lines.Add(line); } this._errorCount = 0; Paragraph p = null; foreach (string line in lines) { string s = line.TrimEnd(); if (RegexTimeCode1.IsMatch(s)) { try { if (p != null) { subtitle.Paragraphs.Add(p); } string[] arr = s.Split('\t'); if (arr.Length > 2) { p = new Paragraph(DecodeTimeCode(arr[1]), new TimeCode(0, 0, 0, 0), arr[2].Trim()); } else { p = new Paragraph(DecodeTimeCode(arr[1]), new TimeCode(0, 0, 0, 0), string.Empty); } } catch { this._errorCount++; p = null; } } else if (s.StartsWith("\t\t")) { if (p != null) { p.Text = p.Text + Environment.NewLine + s.Trim(); } } else if (!string.IsNullOrWhiteSpace(s)) { this._errorCount++; } } if (p != null) { subtitle.Paragraphs.Add(p); } for (int j = 0; j < subtitle.Paragraphs.Count - 1; j++) { p = subtitle.Paragraphs[j]; Paragraph next = subtitle.Paragraphs[j + 1]; p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines; } if (subtitle.Paragraphs.Count > 0) { p = subtitle.Paragraphs[subtitle.Paragraphs.Count - 1]; p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(p.Text); } subtitle.RemoveEmptyLines(); subtitle.Renumber(); }
private void timer1_Tick(object sender, EventArgs e) { try { if (Form1.strMess.Trim().Length > 0) { string[] strU = Form1.strMess.Split(':'); string strM = string.Empty; if (strU[0] == strUser) { for (int i = 1; i < strU.Length; i++) { strM = strM + strU[i]; } rtbMessage.SelectedText = strU[0] + ": "; rtbMessage.SelectedRtf = strM; Form1.strMess = ""; rtbMessage.ScrollToCaret(); FlashWindowEx(this); } if (this.WindowState == FormWindowState.Minimized && Form1.bNoAlert == false) { int iRw = 0; int iHt = 0; NotifyWindow nw; RichTextBox rtb = new RichTextBox(); rtb.Rtf = strM; if (rtb.Text.Trim().Length == 0) { nw = new NotifyWindow(strU[0].ToString(), "Emotions"); nw.SetDimensions(220, 70); } else { iRw = (rtb.Text.Length / 30); iRw = iRw + 1; iHt = (iRw * 25) + 40; nw = new NotifyWindow(strU[0].ToString(), rtb.Text); nw.SetDimensions(220, iHt); } font = new Font("Verdana", 8.25F); nw.Font = font; nw.Notify(); rtb.Dispose(); //font.Dispose(); } } } catch (Exception ex) { //MessageBox.Show("Error in connecting to the chat server."); } }