private void VisualSettingControl_Load(object sender, EventArgs e) { var asm = Assembly.GetEntryAssembly(); if (asm != null) { var colorDirectory = Path.Combine( asm.Location, @"resources\color"); if (Directory.Exists(colorDirectory)) { this.OpenFileDialog.InitialDirectory = colorDirectory; this.SaveFileDialog.InitialDirectory = colorDirectory; } } this.WidthNumericUpDown.Value = this.BarSize.Width; this.HeightNumericUpDown.Value = this.BarSize.Height; this.RefreshSampleImage(); this.ChangeFontItem.Click += (s1, e1) => { this.FontDialog.Font = this.TextFont; if (this.FontDialog.ShowDialog(this) != DialogResult.Cancel) { this.TextFont = this.FontDialog.Font; this.RefreshSampleImage(); } }; this.ChangeFontColorItem.Click += (s1, e1) => { this.ColorDialog.Color = this.FontColor; if (this.ColorDialog.ShowDialog(this) != DialogResult.Cancel) { this.FontColor = this.ColorDialog.Color; this.RefreshSampleImage(); } }; this.ChangeFontOutlineColorItem.Click += (s1, e1) => { this.ColorDialog.Color = this.FontOutlineColor; if (this.ColorDialog.ShowDialog(this) != DialogResult.Cancel) { this.FontOutlineColor = this.ColorDialog.Color; this.RefreshSampleImage(); } }; this.ChangeBarColorItem.Click += (s1, e1) => { this.ColorDialog.Color = this.BarColor; if (this.ColorDialog.ShowDialog(this) != DialogResult.Cancel) { this.BarColor = this.ColorDialog.Color; this.RefreshSampleImage(); } }; this.ChangeBarOutlineColorItem.Click += (s1, e1) => { this.ColorDialog.Color = this.BarOutlineColor; if (this.ColorDialog.ShowDialog(this) != DialogResult.Cancel) { this.BarOutlineColor = this.ColorDialog.Color; this.RefreshSampleImage(); } }; this.WidthNumericUpDown.ValueChanged += (s1, e1) => { this.RefreshSampleImage(); }; this.HeightNumericUpDown.ValueChanged += (s1, e1) => { this.RefreshSampleImage(); }; this.LoadColorSetItem.Click += (s1, e1) => { if (this.OpenFileDialog.ShowDialog(this) != DialogResult.Cancel) { using (var sr = new StreamReader(this.OpenFileDialog.FileName, new UTF8Encoding(false))) { var xs = new XmlSerializer(typeof(ColorSet)); var colorSet = xs.Deserialize(sr) as ColorSet; if (colorSet != null) { this.FontColor = colorSet.FontColor.FromHTML(); this.FontOutlineColor = colorSet.FontOutlineColor.FromHTML(); this.BarColor = colorSet.BarColor.FromHTML(); this.BarOutlineColor = colorSet.BarOutlineColor.FromHTML(); this.RefreshSampleImage(); // カラーパレットに登録する this.ColorDialog.CustomColors = new int[] { ColorTranslator.ToOle(colorSet.FontColor.FromHTML()), ColorTranslator.ToOle(colorSet.FontOutlineColor.FromHTML()), ColorTranslator.ToOle(colorSet.BarColor.FromHTML()), ColorTranslator.ToOle(colorSet.BarOutlineColor.FromHTML()), }; } } } }; this.SaveColorSetItem.Click += (s1, e1) => { if (string.IsNullOrWhiteSpace(this.SaveFileDialog.FileName)) { this.SaveFileDialog.FileName = "スペスペ配色セット.xml"; } if (this.SaveFileDialog.ShowDialog(this) != DialogResult.Cancel) { var colorSet = new ColorSet() { FontColor = this.FontColor.ToHTML(), FontOutlineColor = this.FontOutlineColor.ToHTML(), BarColor = this.BarColor.ToHTML(), BarOutlineColor = this.BarOutlineColor.ToHTML() }; using (var sw = new StreamWriter(this.SaveFileDialog.FileName, false, new UTF8Encoding(false))) { var xs = new XmlSerializer(typeof(ColorSet)); xs.Serialize(sw, colorSet); } } }; }
private void VisualSettingControl_Load(object sender, EventArgs e) { var asm = Assembly.GetEntryAssembly(); if (asm != null) { var colorDirectory = Path.Combine( asm.Location, @"resources\color"); if (Directory.Exists(colorDirectory)) { this.OpenFileDialog.InitialDirectory = colorDirectory; this.SaveFileDialog.InitialDirectory = colorDirectory; } } this.WidthNumericUpDown.Value = this.BarSize.Width; this.HeightNumericUpDown.Value = this.BarSize.Height; this.RefreshSampleImage(); this.ChangeFontItem.Click += (s1, e1) => { this.FontDialog.Font = this.TextFont; if (this.FontDialog.ShowDialog(this) != DialogResult.Cancel) { this.TextFont = this.FontDialog.Font; this.RefreshSampleImage(); } }; this.ChangeFontColorItem.Click += (s1, e1) => { this.ColorDialog.Color = this.FontColor; if (this.ColorDialog.ShowDialog(this) != DialogResult.Cancel) { this.FontColor = this.ColorDialog.Color; this.RefreshSampleImage(); } }; this.ChangeFontOutlineColorItem.Click += (s1, e1) => { this.ColorDialog.Color = this.FontOutlineColor; if (this.ColorDialog.ShowDialog(this) != DialogResult.Cancel) { this.FontOutlineColor = this.ColorDialog.Color; this.RefreshSampleImage(); } }; this.ChangeBarColorItem.Click += (s1, e1) => { this.ColorDialog.Color = this.BarColor; if (this.ColorDialog.ShowDialog(this) != DialogResult.Cancel) { this.BarColor = this.ColorDialog.Color; this.RefreshSampleImage(); } }; this.ChangeBarOutlineColorItem.Click += (s1, e1) => { this.ColorDialog.Color = this.BarOutlineColor; if (this.ColorDialog.ShowDialog(this) != DialogResult.Cancel) { this.BarOutlineColor = this.ColorDialog.Color; this.RefreshSampleImage(); } }; this.WidthNumericUpDown.ValueChanged += (s1, e1) => { this.RefreshSampleImage(); }; this.HeightNumericUpDown.ValueChanged += (s1, e1) => { this.RefreshSampleImage(); }; this.LoadColorSetItem.Click += (s1, e1) => { if (this.OpenFileDialog.ShowDialog(this) != DialogResult.Cancel) { using (var sr = new StreamReader(this.OpenFileDialog.FileName, new UTF8Encoding(false))) { var xs = new XmlSerializer(typeof(ColorSet)); var colorSet = xs.Deserialize(sr) as ColorSet; if (colorSet != null) { this.FontColor = colorSet.FontColor.FromHTML(); this.FontOutlineColor = colorSet.FontOutlineColor.FromHTML(); this.BarColor = colorSet.BarColor.FromHTML(); this.BarOutlineColor = colorSet.BarOutlineColor.FromHTML(); this.RefreshSampleImage(); // カラーパレットに登録する this.ColorDialog.CustomColors = new int[] { ColorTranslator.ToOle(colorSet.FontColor.FromHTML()), ColorTranslator.ToOle(colorSet.FontOutlineColor.FromHTML()), ColorTranslator.ToOle(colorSet.BarColor.FromHTML()), ColorTranslator.ToOle(colorSet.BarOutlineColor.FromHTML()), }; } } } }; this.SaveColorSetItem.Click += (s1, e1) => { if (string.IsNullOrWhiteSpace(this.SaveFileDialog.FileName)) { this.SaveFileDialog.FileName = "スペスペ配色セット.xml"; } if (this.SaveFileDialog.ShowDialog(this) != DialogResult.Cancel) { var colorSet = new ColorSet() { FontColor = this.FontColor.ToHTML(), FontOutlineColor = this.FontOutlineColor.ToHTML(), BarColor = this.BarColor.ToHTML(), BarOutlineColor = this.BarOutlineColor.ToHTML() }; using (var sw = new StreamWriter(this.SaveFileDialog.FileName, false, new UTF8Encoding(false))) { var xs = new XmlSerializer(typeof(ColorSet)); xs.Serialize(sw, colorSet); } } }; }