public void ConvertFile() { // return; var dds = System.IO.Directory.GetDirectories(@"C:\Users\0115289\Documents\SharpDevelop Projects\SpoonSystem\TemplatePrint\bin\Debug\templates"); foreach (var ds in dds) { foreach (var f in System.IO.Directory.GetFiles(ds, "*.xml")) { // System.Diagnostics.Debug.WriteLine(f); if (System.IO.Path.GetExtension(f) != ".xml") { continue; } var olddoc = new System.Xml.XmlDocument(); olddoc.Load(f); var doc = Helper.XmlHelper.NewDocment(); wCanvas canvas = new wCanvas(); canvas.Author = "Elder Yao"; var size = olddoc.SelectSingleNode("/layout/size"); canvas.Size = new System.Drawing.Size(int.Parse(size.Attributes["width"].Value), int.Parse(size.Attributes["height"].Value)); var background = olddoc.SelectSingleNode("/layout/background"); canvas.BackgroundPath = @"C:\Users\0115289\Documents\SharpDevelop Projects\SpoonSystem\TemplatePrint\bin\Debug\" + background.Attributes["path"].Value; var ss = float.Parse(background.Attributes["scale"].Value); canvas.BackgroundRect = new Rectangle(0, 0, (int)(canvas.BackgroundImage.Width * ss), (int)(canvas.BackgroundImage.Height * ss)); foreach (System.Xml.XmlNode item in olddoc.SelectSingleNode("/layout/items").ChildNodes) { var lbl = new Controls.wLabel(); lbl.ShowBorder = false; lbl.Name = item.Attributes["name"].Value; lbl.Text = item.Attributes["value"].Value; lbl.Rectangle = new System.Drawing.Rectangle( int.Parse(item.Attributes["left"].Value), int.Parse(item.Attributes["top"].Value), int.Parse(item.Attributes["width"].Value), int.Parse(item.Attributes["height"].Value) ); var fc = new System.Drawing.FontConverter(); lbl.Font = fc.ConvertFromString(item.Attributes["font"].Value) as System.Drawing.Font; // lbl.ShowBorder = true; canvas.Controls.Add(lbl); } doc.AppendChild(canvas.ToXml(doc)); // doc.Save(f + "x"); Helper.UnitHelper.ArchiveFiles(doc, f.Replace(".xml", ".bg")); } } System.Diagnostics.Debug.WriteLine("OK"); }
void IXmlSerializable.ReadXml(XmlReader reader) { if (reader.IsEmptyElement) { return; } FontConverter fconv = new FontConverter(); if (reader.NodeType != System.Xml.XmlNodeType.EndElement) { this._font = (Font)fconv.ConvertFromString(reader.ReadString()); } reader.MoveToContent(); reader.ReadEndElement(); }
public void Convert() { var olddoc = new System.Xml.XmlDocument(); olddoc.Load(@"C:\Users\0115289\Documents\SharpDevelop Projects\SpoonSystem\TemplatePrint\bin\Debug\templates\1. 顺丰\sf.xml"); var doc = Helper.XmlHelper.NewDocment(); wCanvas canvas = new wCanvas(); canvas.Author = "Elder Yao"; var size = olddoc.SelectSingleNode("/layout/size"); canvas.Size = new System.Drawing.Size(int.Parse(size.Attributes["width"].Value), int.Parse(size.Attributes["height"].Value)); var background = olddoc.SelectSingleNode("/layout/background"); canvas.BackgroundPath = background.Attributes["path"].Value; canvas.BackgroundScale = float.Parse(background.Attributes["scale"].Value); foreach (System.Xml.XmlNode item in olddoc.SelectSingleNode("/layout/items").ChildNodes) { var lbl = new Controls.wLabel(); lbl.Name = item.Attributes["name"].Value; lbl.Text = item.Attributes["value"].Value; lbl.Rectangle = new System.Drawing.Rectangle( int.Parse(item.Attributes["left"].Value), int.Parse(item.Attributes["top"].Value), int.Parse(item.Attributes["width"].Value), int.Parse(item.Attributes["height"].Value) ); var fc = new System.Drawing.FontConverter(); lbl.Font = fc.ConvertFromString(item.Attributes["font"].Value) as System.Drawing.Font; lbl.ShowBorder = false; canvas.Controls.Add(lbl); } doc.AppendChild(canvas.ToXml(doc)); doc.Save(@"C:\Users\0115289\Documents\SharpDevelop Projects\SpoonSystem\TemplatePrint\bin\Debug\templates\1. 顺丰\sf.xmlx"); }
public static void SetValue(string key, string value) { try { var type = Default[key].GetType() .Name; switch (type) { case "Boolean": Default[key] = Convert.ToBoolean(value); break; case "Color": var cc = new ColorConverter(); var color = cc.ConvertFrom(value); Default[key] = color ?? Colors.Black; break; case "Double": Default[key] = Convert.ToDouble(value); break; case "Font": var fc = new FontConverter(); var font = fc.ConvertFromString(value); Default[key] = font ?? new Font(new FontFamily("Microsoft Sans Serif"), 12); break; default: Default[key] = value; break; } } catch (SettingsPropertyNotFoundException ex) { Logging.Log(LogManager.GetCurrentClassLogger(), "", ex); } catch (SettingsPropertyWrongTypeException ex) { Logging.Log(LogManager.GetCurrentClassLogger(), "", ex); } }
public void Deserialize(XmlNode node) { var converter = new FontConverter(); foreach (XmlNode childNode in node.ChildNodes) { int tempInt; bool tempBool; switch (childNode.Name) { case "Identifier": Guid tempGuid; if (Guid.TryParse(childNode.InnerText, out tempGuid)) Identifier = tempGuid; break; case "Enable": if (bool.TryParse(childNode.InnerText, out tempBool)) _enable = tempBool; break; case "Image": if (string.IsNullOrEmpty(childNode.InnerText)) _image = null; else _image = new Bitmap(new MemoryStream(Convert.FromBase64String(childNode.InnerText))); break; case "ImageAligement": if (int.TryParse(childNode.InnerText, out tempInt)) _imageAlignement = (Alignment)tempInt; break; case "ShowText": if (bool.TryParse(childNode.InnerText, out tempBool)) _showText = tempBool; break; case "Text": _text = childNode.InnerText; break; case "Font": try { _font = converter.ConvertFromString(childNode.InnerText) as Font; } catch { } break; case "ForeColor": if (int.TryParse(childNode.InnerText, out tempInt)) _foreColor = Color.FromArgb(tempInt); break; case "LastChanged": DateTime tempDateTime; if (DateTime.TryParse(childNode.InnerText, out tempDateTime)) _lastChanged = tempDateTime; break; } } Configured = true; }
public void Deserialize(XmlNode node) { var converter = new FontConverter(); foreach (XmlNode childNode in node.ChildNodes) { switch (childNode.Name) { case "Identifier": Guid tempGuid; if (Guid.TryParse(childNode.InnerText, out tempGuid)) Identifier = tempGuid; break; case "Font": try { Font = (Font)converter.ConvertFromString(childNode.InnerText); } catch { } break; case "ForeColor": int tempInt; if (int.TryParse(childNode.InnerText, out tempInt)) _foreColor = Color.FromArgb(tempInt); break; case "Note": _note = childNode.InnerText; break; } } }
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { try { object val = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; if (dataGridView1.Columns[e.ColumnIndex].Name == "Symbol") { int i = -1; if (val != null) if (!int.TryParse(val.ToString(), out i)) i = -1; resourcemanager.Form1 rm = new resourcemanager.Form1(i, 1); if (rm.ShowDialog() == DialogResult.OK) { dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = rm.pattern; } rm.Dispose(); } if (dataGridView1.Columns[e.ColumnIndex].Name == "Font") { FontConverter f = new FontConverter(); fontDialog1.Font = (Font)f.ConvertFromString(val.ToString()); if (fontDialog1.ShowDialog() == DialogResult.OK) { dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = f.ConvertToString(fontDialog1.Font); } } if (dataGridView1.Columns[e.ColumnIndex].Name == "Lithology") { int i = -1; if (val != null) if (!int.TryParse(val.ToString(), out i)) i = -1; resourcemanager.Form1 rm = new resourcemanager.Form1(i, 0); if (rm.ShowDialog() == DialogResult.OK) { dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = rm.pattern; } rm.Dispose(); } /* if ((dataGridView1.Columns[e.ColumnIndex].Name == "Name") || (dataGridView1.Columns[e.ColumnIndex].Name == "Material")) { int i = -1; if (val != null) if (!int.TryParse(val.ToString(), out i)) i = -1; // CollectionEditor ce = new CollectionEditor(typeof(LithologyCollection)); // ce.EditValue(new iserviceprovider,u[id].LithologySetting); //u[id].LithologySetting resourcemanager.Form1 rm = new resourcemanager.Form1(i, 0); if (rm.ShowDialog() == DialogResult.OK) { dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = rm.pattern; } rm.Dispose(); } */ if (dataGridView1.Columns[e.ColumnIndex].Name == "Contact") { int i = -1; if (val != null) if (!int.TryParse(val.ToString(), out i)) i = -1; resourcemanager.Form1 rm = new resourcemanager.Form1(i, 2); if (rm.ShowDialog() == DialogResult.OK) { dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = rm.pattern; } rm.Dispose(); } if (dataGridView1.Columns[e.ColumnIndex].Name == "Bitmap") { openFileDialog1.ShowDialog(); if (openFileDialog1.FileName != "") { DataGridViewImageColumn c = (DataGridViewImageColumn)dataGridView1.Columns[e.ColumnIndex]; c.ImageLayout = DataGridViewImageCellLayout.Zoom; dataGridView1.CurrentRow.Cells["Bitmap"].Value = Bitmap.FromFile(openFileDialog1.FileName); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void ReadSettings() { try { FontConverter fontconvert = new FontConverter(); ColorConverter colorconvert = new ColorConverter(); XmlReader xml = XmlReader.Create("settings.xml"); while (xml.Read()) { if (xml.NodeType == XmlNodeType.Element && xml.Name.CompareTo("scintilla") == 0) { while (xml.NodeType != XmlNodeType.EndElement) { xml.Read(); if (xml.Name.CompareTo("highlighting") == 0) { while (xml.NodeType != XmlNodeType.EndElement) { xml.Read(); if (xml.Name.CompareTo("default") == 0) { settings.defaulttext.font = (Font)fontconvert.ConvertFromString(xml.GetAttribute("font")); settings.defaulttext.forecolor = (Color)colorconvert.ConvertFromString(xml.GetAttribute("forecolor")); settings.defaulttext.backcolor = (Color)colorconvert.ConvertFromString(xml.GetAttribute("backcolor")); } } } } } } /* // Default xml.WriteStartElement("default"); xml.WriteAttributeString("font", fontconvert.ConvertToString(settings.defaulttext.font)); xml.WriteAttributeString("forecolor", colorconvert.ConvertToString(settings.defaulttext.forecolor)); xml.WriteAttributeString("backcolor", colorconvert.ConvertToString(settings.defaulttext.backcolor)); xml.WriteEndElement(); // Line Comment xml.WriteStartElement("linecomment"); xml.WriteAttributeString("font", fontconvert.ConvertToString(settings.linecomment.font)); xml.WriteAttributeString("forecolor", colorconvert.ConvertToString(settings.linecomment.forecolor)); xml.WriteAttributeString("backcolor", colorconvert.ConvertToString(settings.linecomment.backcolor)); xml.WriteEndElement(); // Stream Comment xml.WriteStartElement("streamcomment"); xml.WriteAttributeString("font", fontconvert.ConvertToString(settings.streamcomment.font)); xml.WriteAttributeString("forecolor", colorconvert.ConvertToString(settings.streamcomment.forecolor)); xml.WriteAttributeString("backcolor", colorconvert.ConvertToString(settings.streamcomment.backcolor)); xml.WriteEndElement(); // Number xml.WriteStartElement("number"); xml.WriteAttributeString("font", fontconvert.ConvertToString(settings.number.font)); xml.WriteAttributeString("forecolor", colorconvert.ConvertToString(settings.number.forecolor)); xml.WriteAttributeString("backcolor", colorconvert.ConvertToString(settings.number.backcolor)); xml.WriteEndElement(); xml.WriteEndElement(); // ================ xml.WriteEndElement(); xml.WriteEndDocument(); // End of scintilla }*/ xml.Close(); tabs.UpdateTabs(); } catch (Exception ex) { mainform.CaughtException(ex); } }
public Font string2font(string s) { var cvt = new FontConverter(); return cvt.ConvertFromString(s) as Font; }
/// <summary> /// Загрузить настройки /// </summary> /// <param name="root"></param> public void Load(XmlNode root) { if (slim.TryEnterWriteLock(500)) { try { if (root != null && root.Name == "panelItem") { if (root.HasChildNodes) { foreach (XmlNode child in root.ChildNodes) { switch (child.Name) { case "description": try { description = child.InnerText; } catch { } break; case "font": try { FontConverter cnv = new FontConverter(); font = (Font)cnv.ConvertFromString(child.InnerText); } catch { } break; case "color": try { color = Color.FromArgb(int.Parse(child.InnerText)); } catch { } break; case "identifier": try { identifier = new Guid(child.InnerText); } catch { } break; case "col_alarm": try { col_alarm = Color.FromArgb(int.Parse(child.InnerText)); } catch { } break; case "alarm": try { alarm = float.Parse(child.InnerText); } catch { } break; case "is_block_alarm": try { is_block_alarm = bool.Parse(child.InnerText); } catch { } break; default: break; } } } } } finally { slim.ExitWriteLock(); } } }
//Load settings from the registry and aply them to main window, //such as last position, dimensions and font family & size private void LoadLastPos() { int top ; int left ; int height ; int width ; int.TryParse(settings.GetSetting(WND_TOP), out top) ; int.TryParse(settings.GetSetting(WND_LEFT), out left) ; int.TryParse(settings.GetSetting(WND_WIDTH), out width) ; int.TryParse(settings.GetSetting(WND_HEIGHT), out height) ; if(top > 0) Top = top ; if(left > 0) Left = left ; if(height >= MinimumSize.Height) Height = height ; if(width >= MinimumSize.Width) Width = width ; //load font 'serialized' string and convert it into a Font object, via the FontConverter class string fontStr ; fontStr = settings.GetSetting(WND_FONT) ; if(fontStr != ""){ FontConverter fontCon = new FontConverter() ; try{ Font fontObj = (Font)fontCon.ConvertFromString(fontStr) ; textBoxGreek.Font = fontObj ; textBoxLatin.Font = fontObj ; }catch(Exception){ } } }
private void Form1_Load(object sender, EventArgs e) { for (int i = 0; i < Constant.DEVICE_LIST.Length; i++) { this.comboBox_instrumentprefix.Items.Add(Constant.DEVICE_LIST[i]); } string filepath = localpath +@"\default.ts"; if(File.Exists(filepath)) { TsFileHelper tfh = new TsFileHelper(); //get tabs from file List<Tabcontent> tabs = tfh.getTabs(filepath); //delete all current pages this.tabControl1.TabPages.Clear(); //init tabindex this._tabindex = 0; //add tabpage from tabs if(tabs.Count!=0) { foreach (Tabcontent tab in tabs) { this.AddTab(tab); } } else { Tabcontent tc = new Tabcontent(); this.AddTab(tc); } } else { string filePath = System.IO.Path.Combine(localpath, "default.ts"); File.Create(filePath); Tabcontent tc = new Tabcontent(); this.AddTab(tc); } //load config Dictionary<string, string> tempaddr = new Dictionary<string, string>(); ConfigHelper ch = new ConfigHelper(); tempaddr = ch.GetAddr(); this.addr.SetAddress(tempaddr,this.link); //load color this.backcolor = ch.GetConfig("disp_backcolor"); if (this.backcolor != "") { this.dataDisplayBox.BackColor = ColorTranslator.FromHtml(this.backcolor); } this.forecolor = ch.GetConfig("disp_forecolor"); if (this.forecolor != "") { this.dataDisplayBox.ForeColor = ColorTranslator.FromHtml(this.forecolor); } //load font FontConverter fc = new FontConverter(); this.fontstyle = ch.GetConfig("disp_font"); if (this.fontstyle != "") { this.dataDisplayBox.Font = (Font)fc.ConvertFromString(this.fontstyle); } //init instrument status //initInstrumentStatus(this.addr, this.addr,true); this.initInstrumentStatusbyVisa32(this.addr, this.addr, true); foreach (Control ctl in this.SerialpropertyBox.Controls) { if (ctl.Name == "label_rruport") { ctl.Text = this.addr.RRU; } else if (ctl.Name == "label_rrubaud") { ctl.Text = this.addr.Baudrate_rru; } else if (ctl.Name == "label_serial2port") { ctl.Text = this.addr.SERIAL2; } else if (ctl.Name == "label_serial2baud") { ctl.Text = this.addr.Baudrate_com2; } } //ipep ipep = new IPEndPoint(IPAddress.Any, int.Parse(this.addr.Server_Port)); //log LogManager.LogFielPrefix = "RTT "; //string logPath = System.Environment.CurrentDirectory + @"\log\"; if (!Directory.Exists(logPath)) Directory.CreateDirectory(logPath); LogManager.LogPath = logPath; LogManager.WriteLog(LogFile.Trace, "RTT start, version is "+ Assembly.GetExecutingAssembly().GetName().Version.ToString()); //update if (!Directory.Exists(updatePath)) Directory.CreateDirectory(updatePath); if (!Directory.Exists(backuppath)) Directory.CreateDirectory(backuppath); //snapshot //_snapPath = System.Environment.CurrentDirectory + @"\snapshot\"; if (!Directory.Exists(_snapPath)) Directory.CreateDirectory(_snapPath); //rxevm if (!Directory.Exists(_rxevmPath)) Directory.CreateDirectory(_rxevmPath); //cmd queue process thread cmdProcessThread_run = true; _cmdProcessThread = new Thread(new ThreadStart(cmdProcessThread)); _cmdProcessThread.Start(); //cqEventSender.QueueChanged += new cmdQueueEventSender.QueueChangHandler(cmdProcessThread); this.Text = "RTT v" + Assembly.GetExecutingAssembly().GetName().Version.ToString(); this.label_terminal_IP.Text = this.addr.DU_IP; this.Show(); //this.InputBox.Focus(); }
public static Font ConvertStringToFont(string fontString) { var cvt = new FontConverter(); return cvt.ConvertFromString(fontString + " Regular") as Font; }
public void Deserialize(XmlNode node) { var converter = new FontConverter(); foreach (var childNode in node.ChildNodes.OfType<XmlNode>()) { switch (childNode.Name) { case "Note": _note = childNode.InnerText; break; case "HoverNote": _hoverNote = childNode.InnerText; break; case "IsBold": { bool temp; if (bool.TryParse(childNode.InnerText, out temp)) _isBold = temp; } break; case "IsSpecialFormat": { bool temp; if (bool.TryParse(childNode.InnerText, out temp)) _isSpecialFormat = temp; } break; case "Font": try { Font = (Font)converter.ConvertFromString(childNode.InnerText); } catch { } break; case "ForeColor": { int temp; if (int.TryParse(childNode.InnerText, out temp)) _foreColor = Color.FromArgb(temp); } break; case "ForcePreview": { bool temp; if (bool.TryParse(childNode.InnerText, out temp)) _forcePreview = temp; } break; case "IsUrl365": { bool temp; if (bool.TryParse(childNode.InnerText, out temp)) _isUrl365 = temp; } break; case "IsForbidden": { bool temp; if (bool.TryParse(childNode.InnerText, out temp)) _isForbidden = temp; } break; case "IsRestricted": { bool temp; if (bool.TryParse(childNode.InnerText, out temp)) _isRestricted = temp; } break; case "NoShare": { bool temp; if (bool.TryParse(childNode.InnerText, out temp)) _noShare = temp; } break; case "AssignedUsers": _assignedUsers = childNode.InnerText; break; case "DeniedUsers": _deniedUsers = childNode.InnerText; break; case "GeneratePreviewImages": { bool temp; if (bool.TryParse(childNode.InnerText, out temp)) _generatePreviewImages = temp; } break; case "GenerateContentText": { bool temp; if (bool.TryParse(childNode.InnerText, out temp)) _generateContentText = temp; } break; } } }
private void SetupGraphics() { FontConverter fc = new FontConverter(); richTextBoxPreview.Font = (Font)fc.ConvertFromString(App.Settings.PreviewFont); hitBrush = new SolidBrush(App.Settings.HitBackColor); headerBrush = new SolidBrush(App.Settings.HeaderForeColor); hitPen = new Pen(App.Settings.HitBackColor); headerPen = new Pen(App.Settings.HeaderForeColor); }
public void Deserialize(XmlNode node) { var converter = new FontConverter(); foreach (XmlNode childNode in node.ChildNodes) { int tempInt = 0; DateTime tempDateTime; switch (childNode.Name) { case "Name": _name = childNode.InnerText; break; case "Identifier": Guid tempGuid; if (Guid.TryParse(childNode.InnerText, out tempGuid)) Identifier = tempGuid; break; case "RowOrder": if (int.TryParse(childNode.InnerText, out tempInt)) _rowOrder = tempInt; break; case "ColumnOrder": if (int.TryParse(childNode.InnerText, out tempInt)) _columnOrder = tempInt; break; case "BorderColor": if (int.TryParse(childNode.InnerText, out tempInt)) _borderColor = Color.FromArgb(tempInt); break; case "BackgroundWindowColor": if (int.TryParse(childNode.InnerText, out tempInt)) _backgroundWindowColor = Color.FromArgb(tempInt); break; case "ForeWindowColor": if (int.TryParse(childNode.InnerText, out tempInt)) _foreWindowColor = Color.FromArgb(tempInt); break; case "BackgroundHeaderColor": if (int.TryParse(childNode.InnerText, out tempInt)) _backgroundHeaderColor = Color.FromArgb(tempInt); break; case "ForeHeaderColor": if (int.TryParse(childNode.InnerText, out tempInt)) _foreHeaderColor = Color.FromArgb(tempInt); break; case "WindowFont": try { _windowFont = converter.ConvertFromString(childNode.InnerText) as Font; } catch { } break; case "HeaderFont": try { _headerFont = converter.ConvertFromString(childNode.InnerText) as Font; } catch { } break; case "HeaderAligment": if (int.TryParse(childNode.InnerText, out tempInt)) _headerAlignment = (Alignment)tempInt; break; case "EnableWidget": bool tempBool; if (bool.TryParse(childNode.InnerText, out tempBool)) _enableWidget = tempBool; break; case "Widget": if (!string.IsNullOrEmpty(childNode.InnerText)) _widget = new Bitmap(new MemoryStream(Convert.FromBase64String(childNode.InnerText))); break; case "BannerProperties": BannerProperties.Deserialize(childNode); break; case "AddDate": if (DateTime.TryParse(childNode.InnerText, out tempDateTime)) AddDate = tempDateTime; break; case "LastChanged": if (DateTime.TryParse(childNode.InnerText, out tempDateTime)) _lastChanged = tempDateTime; break; case "Files": Files.Clear(); foreach (XmlNode fileNode in childNode.ChildNodes) { LibraryLink libraryFile = null; var typeNode = fileNode.SelectSingleNode("Type"); if (typeNode != null && int.TryParse(typeNode.InnerText, out tempInt)) { var type = (FileTypes)tempInt; if (type == FileTypes.Folder) libraryFile = new LibraryFolderLink(this); } if (libraryFile == null) libraryFile = new LibraryLink(this); libraryFile.Deserialize(fileNode); Files.Add(libraryFile); } #region Order Bug Fix if (Files.Count > 0) { int maxOrder = Files.Select(x => x.Order).Max(); if (maxOrder == 0) for (int i = 0; i < Files.Count; i++) if (Files[i].Order != i) Files[i].Order = i; } #endregion Files.Sort((x, y) => x.Order.CompareTo(y.Order)); break; } } if (!BannerProperties.Configured) { BannerProperties.Text = _name; BannerProperties.Font = _headerFont; BannerProperties.ForeColor = _foreHeaderColor; } }
public void SetValue(string key, string value, IFormatProvider format = null) { try { if (format == null) { format = CultureInfo.CurrentCulture; } var type = Default[key].GetType() .Name; switch (type) { case "Boolean": Default[key] = Convert.ToBoolean(value); break; case "Color": var cc = new ColorConverter(); var color = cc.ConvertFrom(value); Default[key] = color ?? Colors.Black; break; case "Double": Default[key] = Double.Parse(value, NumberStyles.Any, format); break; case "Font": var fc = new FontConverter(); var font = fc.ConvertFromString(value); Default[key] = font ?? new Font(new FontFamily("Microsoft Sans Serif"), 12); break; case "Int32": Default[key] = Int32.Parse(value, NumberStyles.Any, format); break; default: Default[key] = value; break; } RaisePropertyChanged(key); } catch (SettingsPropertyNotFoundException ex) { LogHelper.Log(Logger, ex, LogLevel.Error); } catch (SettingsPropertyWrongTypeException ex) { LogHelper.Log(Logger, ex, LogLevel.Error); } catch (FormatException ex) { LogHelper.Log(Logger, ex, LogLevel.Error); } }
//---------------------------------------------------------------------- // OpenFile [ .mdファイルを開く ] //---------------------------------------------------------------------- private bool OpenFile(string FilePath, bool fOpenDialog = false) { //引数 FilePath = "" の場合は「無題」編集で開始する // Argument "FilePath" = "" => Start editing in 'no title' if (FilePath == "") { _fNoTitle = true; // No title flag } else { _fNoTitle = false; } //----------------------------------- //編集中のファイルがある if (richTextBox1.Modified == true) { //"問い合わせ" //"編集中のファイルがあります。保存してから終了しますか?" //"Question" //"This file being edited. Do you wish to save before exiting?" DialogResult ret = MessageBox.Show(Resources.MsgSaveFileToEnd, Resources.DialogTitleQuestion, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (ret == DialogResult.Yes) { if (SaveToEditingFile() == false) { //キャンセルで抜けてきた //Cancel return (false); } } else if (ret == DialogResult.Cancel) { return (false); } //編集履歴に残す //Save file path to editing history foreach (AppHistory data in MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles) { if (data.md == _MarkDownTextFilePath) { //いったん削除して ( delete once ... ) MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Remove(data); break; } } AppHistory HistroyData = new AppHistory(); HistroyData.md = _MarkDownTextFilePath; HistroyData.css = _SelectedCssFilePath; MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Insert(0, HistroyData); //先頭に挿入 ( Insert at the top ) } //----------------------------------- //オープンダイアログ表示 //View open file dialog if (fOpenDialog == true) { if (File.Exists(_MarkDownTextFilePath) == true) { //編集中のファイルがあればそのディレクトリを初期フォルダーに //Set parent directory of editing file to initial folder openFileDialog1.InitialDirectory = Path.GetDirectoryName(_MarkDownTextFilePath); //テンポラリファイルがあればここで削除 //Delete it if temporary file exists Delete_TemporaryHtmlFilePath(); } openFileDialog1.FileName = ""; if (openFileDialog1.ShowDialog() == DialogResult.OK) { FilePath = openFileDialog1.FileName; } else { return (false); } } //編集中のファイルパスとする //Set this file to 'editing file' path _MarkDownTextFilePath = FilePath; //----------------------------------- //文字コードを調査するためにテキストファイルを開く //Detect encoding if (_fNoTitle == false) { byte[] bs; using (FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read)) { bs = new byte[fs.Length]; fs.Read(bs, 0, bs.Length); } //文字コードを取得する //Get charcter encoding _EditingFileEncoding = GetCode(bs); } else { //「無題」はデフォルトのエンコーディング // Set this file to default encoding in 'No title' _EditingFileEncoding = Encoding.UTF8; } //ステータスバーに表示 //View in statusbar toolStripStatusLabelTextEncoding.Text = _EditingFileEncoding.EncodingName; //編集中のエンコーディングを使用する(&D)か //Use encoding of editing file if (MarkDownSharpEditor.AppSettings.Instance.HtmlEncodingOption == 0) { toolStripStatusLabelHtmlEncoding.Text = _EditingFileEncoding.EncodingName; } //----------------------------------- //ペアとなるCSSファイルがあるか探索してあれば適用する //Apply that the pair CSS file to this file exists foreach (AppHistory data in MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles) { if (data.md == _MarkDownTextFilePath) { if (File.Exists(data.css) == true) { _SelectedCssFilePath = data.css; break; } } } //選択中のCSSファイル名をステータスバーに表示 //View selected CSS file name to stausbar if (File.Exists(_SelectedCssFilePath) == true) { toolStripStatusLabelCssFileName.Text = Path.GetFileName(_SelectedCssFilePath); } else { toolStripStatusLabelCssFileName.Text = Resources.toolTipCssFileName; //"CSSファイル指定なし"; ( not selected CSS file) } _fConstraintChange = true; richTextBox1.Clear(); //RichEditBoxの「フォント」設定 // richTextBox1 font name setting var obj = MarkDownSharpEditor.AppSettings.Instance; FontConverter fc = new FontConverter(); try { richTextBox1.Font = (Font)fc.ConvertFromString(obj.FontFormat); } catch { } //RichEditBoxの「フォントカラー」設定 // richTextBox1 font color setting richTextBox1.ForeColor = Color.FromArgb(obj.richEditForeColor); //View them in statusbar toolStripStatusLabelFontInfo.Text = richTextBox1.Font.Name + "," + richTextBox1.Font.Size.ToString() + "pt"; //----------------------------------- //テキストファイルの読み込み //Read text file if (File.Exists(FilePath) == true) { richTextBox1.Text = File.ReadAllText(FilePath, _EditingFileEncoding); } richTextBox1.BeginUpdate(); richTextBox1.SelectionStart = richTextBox1.Text.Length; richTextBox1.ScrollToCaret(); //richTextBox1の全高さを求める //Get height of richTextBox1 ( for webBrowser sync ) _richEditBoxInternalHeight = richTextBox1.VerticalPosition; //カーソル位置を戻す //Restore cursor position richTextBox1.SelectionStart = 0; richTextBox1.EndUpdate(); //変更フラグOFF richTextBox1.Modified = false; //Undoバッファに追加 //Add all text to undo buffer UndoBuffer.Clear(); UndoBuffer.Add(richTextBox1.Rtf); undoCounter = UndoBuffer.Count; //プレビュー更新 PreviewToBrowser(); _fConstraintChange = false; FormTextChange(); return (true); }
//---------------------------------------------------------------------- // フォームをロード ( Load main form ) //---------------------------------------------------------------------- private void Form1_Load(object sender, EventArgs e) { var obj = MarkDownSharpEditor.AppSettings.Instance; //----------------------------------- //フォーム位置・サイズ ( Form position & size ) //----------------------------------- this.Location = obj.FormPos; this.Size = obj.FormSize; this.richTextBox1.Width = obj.richEditWidth; //ウィンドウ位置の調整(へんなところに行かないように戻す) // Ajust window position ( Set position into Desktop range ) if (this.Left < 0 || this.Left > Screen.PrimaryScreen.Bounds.Width) { this.Left = 0; } if (this.Top < 0 || this.Top > Screen.PrimaryScreen.Bounds.Height) { this.Top = 0; } if (obj.FormState == 1) { //最小化 ( Minimize ) this.WindowState = FormWindowState.Minimized; } else if (obj.FormState == 2) { //最大化 ( Maximize ) this.WindowState = FormWindowState.Maximized; } //メインメニュー表示 //View main menu this.menuViewToolBar.Checked = obj.fViewToolBar; this.toolStrip1.Visible = obj.fViewToolBar; this.menuViewStatusBar.Checked = obj.fViewStatusBar; this.statusStrip1.Visible = obj.fViewStatusBar; this.menuViewWidthEvenly.Checked = obj.fSplitBarWidthEvenly; //言語 ( Language ) if (obj.Lang == "ja") { menuViewJapanese.Checked = true; menuViewEnglish.Checked = false; } else { menuViewJapanese.Checked = false; menuViewEnglish.Checked = true; } //ブラウザープレビューまでの間隔 //Interval time of browser preview if (obj.AutoBrowserPreviewInterval > 0) { timer1.Interval = obj.AutoBrowserPreviewInterval; } //----------------------------------- //RichEditBox font FontConverter fc = new FontConverter(); try { richTextBox1.Font = (Font)fc.ConvertFromString(obj.FontFormat); } catch { } //RichEditBox font color richTextBox1.ForeColor = Color.FromArgb(obj.richEditForeColor); //ステータスバーに表示 //View in statusbar toolStripStatusLabelFontInfo.Text = richTextBox1.Font.Name + "," + richTextBox1.Font.Size.ToString() + "pt"; //エディターのシンタックスハイライター設定の反映 //Syntax highlighter of editor window is enabled _MarkdownSyntaxKeywordAarray = MarkdownSyntaxKeyword.CreateKeywordList(); //----------------------------------- //選択中のエンコーディングを表示 //View selected character encoding name foreach (EncodingInfo ei in Encoding.GetEncodings()) { if (ei.GetEncoding().IsBrowserDisplay == true) { if (ei.CodePage == obj.CodePageNumber) { toolStripStatusLabelHtmlEncoding.Text = ei.DisplayName; break; } } } //----------------------------------- //指定されたCSSファイル名を表示 //View selected CSS file name toolStripStatusLabelCssFileName.Text = Resources.toolTipCssFileName; //"CSSファイル指定なし"; ( No CSS file ) if (obj.ArrayCssFileList.Count > 0) { string FilePath = (string)obj.ArrayCssFileList[0]; if (File.Exists(FilePath) == true) { toolStripStatusLabelCssFileName.Text = Path.GetFileName(FilePath); _SelectedCssFilePath = FilePath; } } //----------------------------------- //出力するHTMLエンコーディング表示 //View HTML charcter encoding name for output if (obj.HtmlEncodingOption == 0) { // 編集中(RichEditBox側)のエンコーディング // 基本的にはテキストファイルが読み込まれたときに表示する // View encoding name of editor window toolStripStatusLabelHtmlEncoding.Text = _EditingFileEncoding.EncodingName; } else { //エンコーディングを指定する(&C) //Select encoding Encoding enc = Encoding.GetEncoding(obj.CodePageNumber); toolStripStatusLabelHtmlEncoding.Text = enc.EncodingName; } //----------------------------------- //検索フォーム・オプション //Search form options chkOptionCase.Checked = obj.fSearchOptionIgnoreCase ? false : true; }
/// <summary> /// Загрузить /// </summary> /// <param name="root">Корневой узел в котором содержится параметр</param> /// <param name="nameRoot">Имя узла</param> public void Load(XmlNode root, String nameRoot) { if (slim.TryEnterWriteLock(300)) { try { if (root != null) { if (root.HasChildNodes && root.Name == nameRoot) { foreach (XmlNode child in root.ChildNodes) { switch (child.Name) { case p_numberName: try { p_number = int.Parse(child.InnerText); } catch { } break; case identifierName: try { identifier = new Guid(child.InnerText); } catch { } break; case fontName: try { FontConverter converter = new FontConverter(); font = (Font)converter.ConvertFromString(child.InnerText); } catch { } break; case colorName: try { color = Color.FromArgb(int.Parse(child.InnerText)); } catch { } break; default: break; } } } } } finally { slim.ExitWriteLock(); } } }
//---------------------------------------------------------------------- // フォームをロード //---------------------------------------------------------------------- private void Form1_Load(object sender, EventArgs e) { var obj = MarkDownSharpEditor.AppSettings.Instance; //----------------------------------- //フォーム位置・サイズ //----------------------------------- this.Left = obj.FormPos.X; this.Top = obj.FormPos.Y; this.Width = obj.FormSize.Width; this.Height = obj.FormSize.Height; this.richTextBox1.Width = obj.richEditWidth; //メインメニュー表示 this.menuViewToolBar.Checked = obj.fViewToolBar; this.toolStrip1.Visible = obj.fViewToolBar; this.menuViewStatusBar.Checked = obj.fViewStatusBar; this.statusStrip1.Visible = obj.fViewStatusBar; this.menuViewWidthEvenly.Checked = obj.fSplitBarWidthEvenly; //ブラウザープレビューまでの間隔 if (obj.AutoBrowserPreviewInterval > 0) { timer1.Interval = obj.AutoBrowserPreviewInterval; } //----------------------------------- //RichEditBoxフォント FontConverter fc = new FontConverter(); try { richTextBox1.Font = (Font)fc.ConvertFromString(obj.FontFormat); } catch { } //RichEditBoxフォントカラー richTextBox1.ForeColor = Color.FromArgb(obj.richEditForeColor); //ステータスバーに表示 toolStripStatusLabelFontInfo.Text = richTextBox1.Font.Name + "," + richTextBox1.Font.Size.ToString() + "pt"; //エディターのシンタックスハイライター設定の反映 RefreshSyntaxHightlighterKeyword(); //----------------------------------- //選択中のエンコーディングを表示 foreach (EncodingInfo ei in Encoding.GetEncodings()) { if (ei.GetEncoding().IsBrowserDisplay == true) { if (ei.CodePage == obj.CodePageNumber) { toolStripStatusLabelHtmlEncoding.Text = ei.DisplayName; break; } } } //----------------------------------- //指定されたCSSファイル名を表示 toolStripStatusLabelCssFileName.Text = "CSSファイル指定なし"; if (obj.ArrayCssFileList.Count > 0) { string FilePath = (string)obj.ArrayCssFileList[0]; if (File.Exists(FilePath) == true) { toolStripStatusLabelCssFileName.Text = Path.GetFileName(FilePath); SelectedCssFilePath = FilePath; } } //----------------------------------- //出力するHTMLエンコーディング表示 if (obj.HtmlEncodingOption == 0) { // 編集中(RichEditBox側)のエンコーディング // デフォルト // 基本的にはテキストファイルが読み込まれたときに表示する toolStripStatusLabelHtmlEncoding.Text = EditingFileEncoding.EncodingName; } else { //エンコーディングを指定する(&C) Encoding enc = Encoding.GetEncoding(obj.CodePageNumber); toolStripStatusLabelHtmlEncoding.Text = enc.EncodingName; } }
public override void deserializeFromXml( XmlNode element ) { if (element.ChildNodes.Count < 1) return; XmlElement e = element.ChildNodes[0] as XmlElement; if (e == null) { return; } _text = e.InnerText; FontConverter fontConverter = new FontConverter(); ColorConverter colorConverter = new ColorConverter(); if (e.HasAttribute("Color")) { //_color = (Color)colorConverter.ConvertFromString(e.Attributes["Color"].Value); _color = (Color)colorConverter.ConvertFromString(null, System.Globalization.CultureInfo.InvariantCulture, e.Attributes["Color"].Value); } if (e.HasAttribute("Background") ) { _background = (Color)colorConverter.ConvertFromString(null,System.Globalization.CultureInfo.InvariantCulture, e.Attributes["Background"].Value); } if (e.HasAttribute("Font")) { _font = fontConverter.ConvertFromString(null, System.Globalization.CultureInfo.InvariantCulture, e.Attributes["Font"].Value ) as Font; } else { _font = SystemFonts.DefaultFont; } if ( e.HasAttribute("Alignment")) _alignment = StringToAlignment(e.Attributes["Alignment"].Value); }
protected LabelElement(SerializationInfo info, StreamingContext context) { // Get the set of serializable members for our class and base classes Type thisType = typeof(LabelElement); MemberInfo[] mi = FormatterServices.GetSerializableMembers(thisType, context); // Deserialize the base class's fields from the info object for (Int32 i = 0 ; i < mi.Length; i++) { // Don't deserialize fields for this class if (mi[i].DeclaringType == thisType) continue; // To ease coding, treat the member as a FieldInfo object FieldInfo fi = (FieldInfo) mi[i]; // Set the field to the deserialized value fi.SetValue(this, info.GetValue(fi.Name, fi.FieldType)); } // Deserialize the values that were serialized for this class this.ForeColor1 = (Color) info.GetValue("foreColor1", typeof(Color)); this.ForeColor2 = (Color) info.GetValue("foreColor2", typeof(Color)); this.BackColor1 = (Color) info.GetValue("backColor1", typeof(Color)); this.BackColor2 = (Color) info.GetValue("backColor2", typeof(Color)); this.Text = info.GetString("text"); this.Alignment = (StringAlignment) info.GetValue("alignment", typeof(StringAlignment)); this.LineAlignment = (StringAlignment) info.GetValue("lineAlignment", typeof(StringAlignment)); this.Trimming = (StringTrimming) info.GetValue("trimming", typeof(StringTrimming)); this.Wrap = info.GetBoolean("wrap"); this.Vertical = info.GetBoolean("vertical"); this.ReadOnly = info.GetBoolean("readOnly"); this.AutoSize = info.GetBoolean("autoSize"); FontConverter fc = new FontConverter(); this.Font = (Font) fc.ConvertFromString(info.GetString("font")); }
//---------------------------------------------------------------------- // TODO: .mdファイルを開く(OpenFile) //---------------------------------------------------------------------- private bool OpenFile(string FilePath) { if (richTextBox1.Modified == true) { DialogResult ret = MessageBox.Show( "編集中のファイルがあります。保存してか らファイルを開きますか?", "問い合わせ", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (ret == DialogResult.Yes) { if (SaveToEditingFile() == false) { //キャンセルで抜けてきた return (false); } } else if (ret == DialogResult.Cancel) { return (false); } //編集履歴に残す foreach (AppHistory data in MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles) { if (data.md == MarkDownTextFilePath) { //いったん削除して MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Remove(data); break; } } AppHistory HistroyData = new AppHistory(); HistroyData.md = MarkDownTextFilePath; HistroyData.css = SelectedCssFilePath; MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Insert(0, HistroyData); //先頭に挿入 } //ファイル名指定で来ている(ドラッグ&ドロップされた等) if (File.Exists(FilePath) == true) { } else { //オープンダイアログ表示 if (openFileDialog1.ShowDialog() == DialogResult.OK) { FilePath = openFileDialog1.FileName; } else { return (false); } } //テンポラリファイルがあればここで削除 DeleteTemporaryHtmlFilePath(); //テキストファイルを開く byte[] bs; using (FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read)) { bs = new byte[fs.Length]; fs.Read(bs, 0, bs.Length); } //文字コードを取得する EditingFileEncoding = GetCode(bs); //ステータスバーに表示 toolStripStatusLabelTextEncoding.Text = EditingFileEncoding.EncodingName; //編集中のエンコーディングを使用する(&D)か if (MarkDownSharpEditor.AppSettings.Instance.HtmlEncodingOption == 0) { toolStripStatusLabelHtmlEncoding.Text = EditingFileEncoding.EncodingName; } fConstraintChange = true; MarkDownTextFilePath = FilePath; //編集中のファイルパスとする fNoTitle = false; //無題フラグOFF //ペアとなるCSSファイルがあるか探索してあれば適用する foreach (AppHistory data in MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles) { if (data.md == MarkDownTextFilePath) { if (File.Exists(data.css) == true) { SelectedCssFilePath = data.css; break; } } } //選択中のCSSファイル名をステータスバーに表示 if (File.Exists(SelectedCssFilePath) == true) { toolStripStatusLabelCssFileName.Text = Path.GetFileName(SelectedCssFilePath); } else { toolStripStatusLabelCssFileName.Text = "CSSファイル指定なし"; } //RichEditBoxに表示 fConstraintChange = true; richTextBox1.Clear(); //RichEditBoxの「フォント」設定 var obj = MarkDownSharpEditor.AppSettings.Instance; FontConverter fc = new FontConverter(); try { richTextBox1.Font = (Font)fc.ConvertFromString(obj.FontFormat); } catch { } //RichEditBoxの「フォントカラー」設定 richTextBox1.ForeColor = Color.FromArgb(obj.richEditForeColor); //ステータスバーに表示 toolStripStatusLabelFontInfo.Text = richTextBox1.Font.Name + "," + richTextBox1.Font.Size.ToString() + "pt"; //テキストファイルの読み込み richTextBox1.Text = File.ReadAllText(FilePath, EditingFileEncoding); richTextBox1.Modified = false; //Undoバッファに追加 undoCount = 0; UndoBuffer.Clear(); UndoBuffer.Add(richTextBox1.Text.ToString()); fConstraintChange = false; FormTextChange(); //シンタックスハイライター SyntaxHightlighterWidthRegex(); //PreviewToBrowser(); if (timer1.Enabled == false) { timer1.Enabled = true; } return (true); }
//---------------------------------------------------------------------- // TODO: OpenFile [ .mdファイルを開く ] //---------------------------------------------------------------------- private bool OpenFile(string FilePath) { //引数 FilePath = "" の場合は「無題」編集で開始する if (FilePath == "") { fNoTitle = true; //無題フラグON } else { fNoTitle = false; } //----------------------------------- //編集中のファイルがある if (richTextBox1.Modified == true) { DialogResult ret = MessageBox.Show( "編集中のファイルがあります。保存してか らファイルを開きますか?", "問い合わせ", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (ret == DialogResult.Yes) { if (SaveToEditingFile() == false) { //キャンセルで抜けてきた return (false); } } else if (ret == DialogResult.Cancel) { return (false); } //編集履歴に残す foreach (AppHistory data in MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles) { if (data.md == MarkDownTextFilePath) { //いったん削除して MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Remove(data); break; } } AppHistory HistroyData = new AppHistory(); HistroyData.md = MarkDownTextFilePath; HistroyData.css = SelectedCssFilePath; MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles.Insert(0, HistroyData); //先頭に挿入 } //----------------------------------- //オープンダイアログ表示 if (fNoTitle == false && File.Exists(FilePath) == false) { if (File.Exists(MarkDownTextFilePath) == true) { //編集中のファイルがあればそのディレクトリを初期フォルダーに openFileDialog1.InitialDirectory = Path.GetDirectoryName(MarkDownTextFilePath); //テンポラリファイルがあればここで削除 DeleteTemporaryHtmlFilePath(); } openFileDialog1.FileName = ""; if (openFileDialog1.ShowDialog() == DialogResult.OK) { FilePath = openFileDialog1.FileName; } else { return (false); } } //編集中のファイルパスとする MarkDownTextFilePath = FilePath; //----------------------------------- //文字コードを調査するためにテキストファイルを開く if (fNoTitle == false) { byte[] bs; using (FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read)) { bs = new byte[fs.Length]; fs.Read(bs, 0, bs.Length); } //文字コードを取得する EditingFileEncoding = GetCode(bs); } else { //「無題」はデフォルトのエンコーディング EditingFileEncoding = Encoding.UTF8; } //ステータスバーに表示 toolStripStatusLabelTextEncoding.Text = EditingFileEncoding.EncodingName; //編集中のエンコーディングを使用する(&D)か if (MarkDownSharpEditor.AppSettings.Instance.HtmlEncodingOption == 0) { toolStripStatusLabelHtmlEncoding.Text = EditingFileEncoding.EncodingName; } //----------------------------------- //ペアとなるCSSファイルがあるか探索してあれば適用する foreach (AppHistory data in MarkDownSharpEditor.AppSettings.Instance.ArrayHistoryEditedFiles) { if (data.md == MarkDownTextFilePath) { if (File.Exists(data.css) == true) { SelectedCssFilePath = data.css; break; } } } //選択中のCSSファイル名をステータスバーに表示 if (File.Exists(SelectedCssFilePath) == true) { toolStripStatusLabelCssFileName.Text = Path.GetFileName(SelectedCssFilePath); } else { toolStripStatusLabelCssFileName.Text = "CSSファイル指定なし"; } //----------------------------------- //RichEditBoxに表示 fConstraintChange = true; richTextBox1.Clear(); //RichEditBoxの「フォント」設定 var obj = MarkDownSharpEditor.AppSettings.Instance; FontConverter fc = new FontConverter(); try { richTextBox1.Font = (Font)fc.ConvertFromString(obj.FontFormat); } catch { } //RichEditBoxの「フォントカラー」設定 richTextBox1.ForeColor = Color.FromArgb(obj.richEditForeColor); //ステータスバーに表示 toolStripStatusLabelFontInfo.Text = richTextBox1.Font.Name + "," + richTextBox1.Font.Size.ToString() + "pt"; //----------------------------------- //テキストファイルの読み込み if (fNoTitle == false) { richTextBox1.Text = File.ReadAllText(FilePath, EditingFileEncoding); } richTextBox1.BeginUpdate(); richTextBox1.SelectionStart = richTextBox1.Text.Length; richTextBox1.ScrollToCaret(); //richTextBox1の全高さを求める richEditBoxInternalHeight = richTextBox1.VerticalPosition; //カーソル位置を戻す richTextBox1.SelectionStart = 0; richTextBox1.EndUpdate(); //変更フラグOFF richTextBox1.Modified = false; //Undoバッファに追加 undoCounter = 0; UndoBuffer.Clear(); UndoBuffer.Add(richTextBox1.Text.ToString()); //シンタックスハイライター SyntaxHightlighterWidthRegex(); //プレビュー更新 PreviewToBrowser(); fConstraintChange = false; FormTextChange(); return (true); }
public void Deserialize(XmlNode node) { var converter = new FontConverter(); foreach (XmlNode childNode in node.ChildNodes) { int tempInt; bool tempBool; switch (childNode.Name) { case "Name": _name = childNode.InnerText; break; case "ColumnOrder": if (int.TryParse(childNode.InnerText, out tempInt)) _columnOrder = tempInt; break; case "BackgroundColor": if (int.TryParse(childNode.InnerText, out tempInt)) _backgroundColor = Color.FromArgb(tempInt); break; case "ForeColor": if (int.TryParse(childNode.InnerText, out tempInt)) _foreColor = Color.FromArgb(tempInt); break; case "HeaderFont": try { _headerFont = converter.ConvertFromString(childNode.InnerText) as Font; } catch { } break; case "EnableText": if (bool.TryParse(childNode.InnerText, out tempBool)) _enableText = tempBool; break; case "HeaderAligment": if (int.TryParse(childNode.InnerText, out tempInt)) _headerAlignment = (Alignment)tempInt; break; case "EnableWidget": if (bool.TryParse(childNode.InnerText, out tempBool)) _enableWidget = tempBool; break; case "Widget": if (!string.IsNullOrEmpty(childNode.InnerText)) _widget = new Bitmap(new MemoryStream(Convert.FromBase64String(childNode.InnerText))); break; case "BannerProperties": BannerProperties.Deserialize(childNode); break; case "LastChanged": DateTime tempDateTime; if (DateTime.TryParse(childNode.InnerText, out tempDateTime)) _lastChanged = tempDateTime; break; } } }
public void SetValue(string key, string value, CultureInfo cultureInfo) { try { var type = Default[key].GetType() .Name; switch (type) { case "Boolean": Default[key] = Boolean.Parse(value); break; case "Color": var cc = new ColorConverter(); var color = cc.ConvertFrom(value); Default[key] = color ?? Colors.Black; break; case "Double": Default[key] = Double.Parse(value, cultureInfo); break; case "Font": var fc = new FontConverter(); var font = fc.ConvertFromString(value); Default[key] = font ?? new Font(new FontFamily("Microsoft Sans Serif"), 12); break; case "Int32": Default[key] = Int32.Parse(value, cultureInfo); break; default: Default[key] = value; break; } } catch (Exception ex) { Logging.Log(LogManager.GetCurrentClassLogger(), "", ex); } RaisePropertyChanged(key); }
private void InitUI() { try { int left ; if(int.TryParse(properties[REG_LOGS_LEFT], out left)) this.Left = left ; int top ; if(int.TryParse(properties[REG_LOGS_TOP], out top)) this.Top = top ; int height ; if(int.TryParse(properties[REG_LOGS_HEIGHT], out height)) this.Height = height ; int width ; if(int.TryParse(properties[REG_LOGS_WIDTH], out width)) this.Width = width ; bool maximized ; bool.TryParse(properties[REG_LOGS_MAXIMIZED], out maximized) ; this.WindowState = (maximized) ? FormWindowState.Maximized : FormWindowState.Normal ; string lang = properties[REG_LANGUAGE] ; if(lang.Length == 2 && lang != "en") //for languages used the ISO 639-1, two-letter codes format LoadLang(lang) ; //use FontConverter to 'deserialize' the current Font object from string string storedFont = properties[REG_LOGS_FONT] ; if(storedFont != ""){ FontConverter fontCon = new FontConverter() ; Font font = (Font) fontCon.ConvertFromString(storedFont) ; textBoxCopiesFailed.Font = font ; textBoxCopiesDone.Font = font ; textBoxDeletionsDone.Font = font ; textBoxDeletionsFailed.Font = font ; } //use ColorConverter to 'deserialize' the current Color object from string string storedColor = properties[REG_LOGS_FORE_COLOR] ; if(storedColor != ""){ ColorConverter colorCon = new ColorConverter() ; Color color = (Color) colorCon.ConvertFromString(storedColor) ; textBoxCopiesDone.ForeColor = color ; textBoxCopiesFailed.ForeColor = color ; textBoxDeletionsDone.ForeColor = color ; textBoxDeletionsFailed.ForeColor = color ; //change backcolor to white instead of readonly gray, to make fore color visible textBoxCopiesDone.BackColor = Color.White ; textBoxCopiesFailed.BackColor = Color.White ; textBoxDeletionsDone.BackColor = Color.White ; textBoxDeletionsFailed.BackColor = Color.White ; } } catch (Exception) { } }
public Font GetEditorFont() { var cvt = new FontConverter(); return cvt.ConvertFromString(editorFont) as Font; }
private void buttonChangeFont_Click(object sender, EventArgs e) { FontDialog d = new FontDialog(); FontConverter fc = new FontConverter(); d.Font = (Font)fc.ConvertFromString(textBoxFont.Text); if (d.ShowDialog() == DialogResult.OK) { textBoxFont.Text = fc.ConvertToString(d.Font); } }
public bool EditValue(IWin32Window owner, XmlSchemaType type, string input, out string output) { output = input; FontConverter fc = new FontConverter(); Font f = null; try { f = (Font)fc.ConvertFromString(input); fd.Font = f; } catch { } if (fd.ShowDialog(owner) == DialogResult.OK) { output = fc.ConvertToString(fd.Font); return true; } else { return false; } }