private void btGenerateThemeClass_Click(object sender, EventArgs e) { if (textBox1.Text.Trim().Length == 0) { MessageBox.Show("Class Name is empty."); return; } StringBuilder sb = new StringBuilder(); sb.AppendLine("using System;"); sb.AppendLine("using System.Collections.Generic;"); sb.AppendLine("using System.Text;"); sb.AppendLine("using System.Drawing;"); sb.AppendLine(); sb.AppendLine("namespace System.Windows.Forms"); sb.AppendLine("{"); sb.AppendLine(" public class " + textBox1.Text + " : RibbonProfesionalRendererColorTable"); sb.AppendLine(" {"); sb.AppendLine(" public " + textBox1.Text + "()"); sb.AppendLine(" {"); sb.AppendLine(" // Rebuild the solution for the first time"); sb.AppendLine(" // for this ColorTable to take effect."); sb.AppendLine(" // Guide for applying new theme: http://officeribbon.codeplex.com/wikipage?title=How%20to%20Make%20a%20New%20Theme%2c%20Skin%20for%20this%20Ribbon%20Programmatically"); sb.AppendLine(); sb.AppendLine(" ThemeName = \"" + txtThemeName.Text + "\";"); sb.AppendLine(" ThemeAuthor = \"" + txtAuthor.Text + "\";"); sb.AppendLine(" ThemeAuthorWebsite = \"" + txtAuthorWebsite.Text + "\";"); sb.AppendLine(" ThemeAuthorEmail = \"" + txtAuthorEmail.Text + "\";"); sb.AppendLine(" ThemeDateCreated = \"" + txtDateCreated.Text + "\";"); sb.AppendLine(); int count = Enum.GetNames(typeof(RibbonColorPart)).Length; for (int i = 0; i < count; i++) { sb.AppendLine(" " + ((RibbonColorPart)i).ToString() + " = FromHex(\"" + (ribbon1.Renderer as RibbonProfessionalRenderer).ColorTable.GetColorHexStr((RibbonColorPart)i) + "\");"); } sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" public Color FromHex(string hex)"); sb.AppendLine(" {"); sb.AppendLine(" if (hex.StartsWith(\"#\"))"); sb.AppendLine(" hex = hex.Substring(1);"); sb.AppendLine(); sb.AppendLine(" if (hex.Length != 6) throw new Exception(\"Color not valid\");"); sb.AppendLine(); sb.AppendLine(" return Color.FromArgb("); sb.AppendLine(" int.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber),"); sb.AppendLine(" int.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber),"); sb.AppendLine(" int.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber));"); sb.AppendLine(" }"); sb.AppendLine(" }"); sb.AppendLine("}"); FormClassResult f = new FormClassResult(sb.ToString()); f.ShowDialog(); }
private void btGenerateThemeClass_Click(object sender, EventArgs e) { if (textBox1.Text.Trim().Length == 0) { MessageBox.Show("Class Name is empty."); return; } StringBuilder sb = new StringBuilder(); sb.AppendLine("using System;"); sb.AppendLine("using System.Collections.Generic;"); sb.AppendLine("using System.Text;"); sb.AppendLine("using System.Drawing;"); sb.AppendLine(); sb.AppendLine("namespace System.Windows.Forms"); sb.AppendLine("{"); sb.AppendLine(" public class " + textBox1.Text + " : RibbonProfesionalRendererColorTable"); sb.AppendLine(" {"); sb.AppendLine(" public " + textBox1.Text + "()"); sb.AppendLine(" {"); sb.AppendLine(" // Rebuild the solution for the first time"); sb.AppendLine(" // for this ColorTable to take effect."); sb.AppendLine(" // Guide for applying new theme: http://officeribbon.codeplex.com/wikipage?title=How%20to%20Make%20a%20New%20Theme%2c%20Skin%20for%20this%20Ribbon%20Programmatically"); sb.AppendLine(); sb.AppendLine(" ThemeName = \"" + txtThemeName.Text + "\";"); sb.AppendLine(" ThemeAuthor = \"" + txtAuthor.Text + "\";"); sb.AppendLine(" ThemeAuthorWebsite = \"" + txtAuthorWebsite.Text + "\";"); sb.AppendLine(" ThemeAuthorEmail = \"" + txtAuthorEmail.Text + "\";"); sb.AppendLine(" ThemeDateCreated = \"" + txtDateCreated.Text + "\";"); sb.AppendLine(); int count = Enum.GetNames(typeof(RibbonColorPart)).Length; for (int i = 0; i < count; i++) { sb.AppendLine(" " + ((RibbonColorPart)i).ToString() + " = FromHex(\"" + Theme.ColorTable.GetColorHexStr((RibbonColorPart)i) + "\");"); } sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" public Color FromHex(string hex)"); sb.AppendLine(" {"); sb.AppendLine(" if (hex.StartsWith(\"#\"))"); sb.AppendLine(" hex = hex.Substring(1);"); sb.AppendLine(); sb.AppendLine(" if (hex.Length != 6) throw new Exception(\"Color not valid\");"); sb.AppendLine(); sb.AppendLine(" return Color.FromArgb("); sb.AppendLine(" int.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber),"); sb.AppendLine(" int.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber),"); sb.AppendLine(" int.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber));"); sb.AppendLine(" }"); sb.AppendLine(" }"); sb.AppendLine("}"); FormClassResult f = new FormClassResult(sb.ToString()); f.ShowDialog(); }