using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.PowerPoint;
using GeneralLib;
namespace SunVoteARSPPT
{
public partial class FrmAllChartSet : Form
{
private int chkNum = 0;
//保存字体颜色参数值
ManageChart Chart;
private System.Drawing.Font ItemLabelFont;
private Color ItemLabelColor;
private System.Drawing.Font DataLabelFont;
private Color DataLabelColor;
///
/// 是否正在加载,不处理控件事件
/// 创建:杨斌 2012-06-26
///
bool IsLoad = false;
public FrmAllChartSet()
{
InitializeComponent();
}
private void FrmAllChartSet_Load(object sender, EventArgs e)
{
IsLoad = true;
GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
lvwColorSet.HeaderStyle = ColumnHeaderStyle.None;
for (int i = 0; i < 10; i++)
{
//lvwColorSet.Items[i].BackColor = Color.FromArgb(TagSet.LoadValue(TagKey.ChartColor_, i, GlobalInfo.ChartColors[i]).ToInt);
lvwColorSet.Items[i].BackColor = GlobalInfo.ChartColors[i];
}
lvwColorSet.Font = new System.Drawing.Font(lvwColorSet.Font.Name, 17);
cboFontName.Items.Clear();
foreach (FontFamily font in FontFamily.Families)
{
cboFontName.Items.Add(font.Name);
}
//参照Offic字号列表
cboFontSize.Items.Clear();
cboFontSize.Items.Add(8);
cboFontSize.Items.Add(9);
cboFontSize.Items.Add(10);
cboFontSize.Items.Add(10.5);
cboFontSize.Items.Add(11);
cboFontSize.Items.Add(12);
cboFontSize.Items.Add(14);
cboFontSize.Items.Add(16);
cboFontSize.Items.Add(18);
cboFontSize.Items.Add(20);
cboFontSize.Items.Add(24);
cboFontSize.Items.Add(28);
cboFontSize.Items.Add(32);
cboFontSize.Items.Add(36);
cboFontSize.Items.Add(40);
cboFontSize.Items.Add(44);
cboFontSize.Items.Add(48);
cboFontSize.Items.Add(54);
cboFontSize.Items.Add(60);
cboFontSize.Items.Add(66);
cboFontSize.Items.Add(72);
cboFontSize.Items.Add(80);
cboFontSize.Items.Add(88);
cboFontSize.Items.Add(96);
Chart = Globals.SunVoteARSAddIn.PPTEdit.SlideChart;
ItemLabelFont = Chart.ItemLabelFont.Clone() as System.Drawing.Font;
ItemLabelColor = Chart.ItemLabelColor;
DataLabelFont = Chart.DataLabelFont.Clone() as System.Drawing.Font;
DataLabelColor = Chart.DataLabelColor;
cboFontObject.SelectedIndex = 0;
picFontColor.BackColor = Color.Black;
cboFontName.SelectedIndex = 2;
cboFontSize.Text = "16";
cboFontObject_SelectedIndexChanged(null, null);
IsLoad = false;
}
private void lvwColorSet_MouseUp(object sender, MouseEventArgs e)
{
if (chkChartColor.Checked)
{
try
{
ColorDialog cdlg = new ColorDialog();
cdlg.Color = lvwColorSet.SelectedItems[0].BackColor;
//杨斌 2014-10-16
if (GlobalInfo.MyCustomColors != null)
cdlg.CustomColors = GlobalInfo.MyCustomColors;
cdlg.ShowDialog();
GlobalInfo.MyCustomColors = cdlg.CustomColors;//杨斌 2014-10-16
lvwColorSet.SelectedItems[0].BackColor = cdlg.Color;
}
catch
{
}
}
}
private void picFontColor_Click(object sender, EventArgs e)
{
if (!chkFontColor.Checked) return;
try
{
ColorDialog cdlg = new ColorDialog();
cdlg.Color = picFontColor.BackColor;
cdlg.ShowDialog();
picFontColor.BackColor = cdlg.Color;
switch (cboFontObject.SelectedIndex)
{
case 0://选项标签
ItemLabelColor = picFontColor.BackColor;
break;
case 1://数据标签
DataLabelColor = picFontColor.BackColor;
break;
default:
return;
}
}
catch
{
}
}
private void chkFontName_CheckedChanged(object sender, EventArgs e)
{
cboFontName.Enabled = chkFontName.Checked;
chkNum = chkNum + (chkFontName.Checked ? 1 : -1);
btnOK.Enabled = chkNum > 0;
}
private void chkFontSize_CheckedChanged(object sender, EventArgs e)
{
cboFontSize.Enabled = chkFontSize.Checked;
chkNum = chkNum + (chkFontSize.Checked ? 1 : -1);
btnOK.Enabled = chkNum > 0;
}
private void chkFontType_CheckedChanged(object sender, EventArgs e)
{
chkFontBold.Enabled = chkFontType.Checked;
chkFontItalic.Enabled = chkFontType.Checked;
chkNum = chkNum + (chkFontType.Checked ? 1 : -1);
btnOK.Enabled = chkNum > 0;
}
private void chkChartColor_CheckedChanged(object sender, EventArgs e)
{
chkNum = chkNum + (chkChartColor.Checked ? 1 : -1);
btnOK.Enabled = chkNum > 0;
}
private void chkFontColor_CheckedChanged(object sender, EventArgs e)
{
chkNum = chkNum + (chkFontColor.Checked ? 1 : -1);
btnOK.Enabled = chkNum > 0;
}
private void btnCancel_Click(object sender, EventArgs e)
{
Close();
}
private void btnOK_Click(object sender, EventArgs e)
{
TagSet tagSet = new TagSet();
foreach (Slide s in Globals.SunVoteARSAddIn.PPTEdit.PPT.ActivePresentation.Slides)
{
tagSet.Tags = s.Tags;
ResponseType responseType = EnumName.GetEnum(tagSet.GetValue(TagKey.ResponseType).Value);
//杨斌 2015-06-01
if (chkChartColorAll.Checked)
{
for (int i = 0; i < 10; i++)
{
tagSet.SetValue(TagKey.ChartColor_, i, picChartColorAll.BackColor.ToArgb());
//GlobalInfo.ChartColors[i] = lvwColorSet.Items[i].BackColor;
}
}
else if (chkChartColor.Checked)//杨斌 2015-06-01
{
for (int i = 0; i < 10; i++)
{
tagSet.SetValue(TagKey.ChartColor_, i, lvwColorSet.Items[i].BackColor.ToArgb());
//GlobalInfo.ChartColors[i] = lvwColorSet.Items[i].BackColor;
}
}
if (chkFontName.Checked)
{
tagSet.SetValue(TagKey.ChartPara_ItemLabelFontName, ItemLabelFont.Name);
tagSet.SetValue(TagKey.ChartPara_DataLabelFontName, DataLabelFont.Name);
}
if (chkFontSize.Checked)
{
tagSet.SetValue(TagKey.ChartPara_ItemLabelFontSize, ItemLabelFont.Size);
tagSet.SetValue(TagKey.ChartPara_DataLabelFontSize, DataLabelFont.Size);
}
if (chkFontType.Checked)
{
tagSet.SetValue(TagKey.ChartPara_ItemLabelFontBold, ItemLabelFont.Bold);
tagSet.SetValue(TagKey.ChartPara_DataLabelFontBold, DataLabelFont.Bold);
tagSet.SetValue(TagKey.ChartPara_ItemLabelFontItalic, ItemLabelFont.Italic);
tagSet.SetValue(TagKey.ChartPara_DataLabelFontItalic, DataLabelFont.Italic);
}
if (chkFontColor.Checked)
{
tagSet.SetValue(TagKey.ChartPara_ItemLabelFontColor, ItemLabelColor.ToArgb());
tagSet.SetValue(TagKey.ChartPara_DataLabelFontColor, DataLabelColor.ToArgb());
}
//2012-06-13 设置颜色时,图表未显示
Globals.SunVoteARSAddIn.PPTEdit.InitChart(true, s);
}
MessageBox.Show(GlobalInfo.SysLanguage.LPT.ReadString(this.Name,"GlobalSetSucceed","设置成功"),
GlobalInfo.SysLanguage.LPT.ReadString(this.Name,"Prompt","提示"));
}
private void Font_Changed(object sender, EventArgs e)
{
if (IsLoad) return;
float fontSize = 0;
float.TryParse(cboFontSize.Text, out fontSize);
FontStyle style = FontStyle.Regular;
if (chkFontBold.Checked) style = style | FontStyle.Bold;
if (chkFontItalic.Checked) style = style | FontStyle.Italic;
//if (cboFontType.SelectedIndex == 0) style = style | FontStyle.Regular;
//if (cboFontType.SelectedIndex == 1) style = style | FontStyle.Bold;
//if (cboFontType.SelectedIndex == 2) style = style | FontStyle.Italic;
string fontName = cboFontName.Text;
switch (cboFontObject.SelectedIndex)
{
case 0://选项标签
if (fontSize == 0) fontSize = ItemLabelFont.Size;
ItemLabelFont = new System.Drawing.Font(fontName, fontSize, style);
break;
case 1://数据标签
if (fontSize == 0) fontSize = DataLabelFont.Size;
DataLabelFont = new System.Drawing.Font(fontName, fontSize, style);
break;
default:
return;
}
}
private void cboFontObject_SelectedIndexChanged(object sender, EventArgs e)
{
if (Chart == null) return;
IsLoad = true;
System.Drawing.Font font = null;
Color color = Color.Black;
switch (cboFontObject.SelectedIndex)
{
case 0://选项标签
font = ItemLabelFont;
color = ItemLabelColor;
break;
case 1://数据标签
font = DataLabelFont;
color = DataLabelColor;
break;
default:
return;
}
string fontName = font.Name;
if (!cboFontName.Items.Contains(fontName)) cboFontName.Items.Add(fontName);
cboFontName.Text = fontName;
cboFontSize.Text = font.Size.ToString();
picFontColor.BackColor = color;
IsLoad = false;
}
private void chkChartColorAll_CheckedChanged(object sender, EventArgs e)
{
chkChartColor.Enabled = !chkChartColorAll.Checked;
if (chkChartColorAll.Checked && chkChartColor.Checked)
chkChartColor.Checked = false;
chkNum = chkNum + (chkChartColorAll.Checked ? 1 : -1);
btnOK.Enabled = chkNum > 0;
}
private void picChartColorAll_MouseUp(object sender, MouseEventArgs e)
{
if (chkChartColorAll.Checked)
{
try
{
ColorDialog cdlg = new ColorDialog();
cdlg.Color = picChartColorAll.BackColor;
//杨斌 2014-10-16
if (GlobalInfo.MyCustomColors != null)
cdlg.CustomColors = GlobalInfo.MyCustomColors;
cdlg.ShowDialog();
GlobalInfo.MyCustomColors = cdlg.CustomColors;//杨斌 2014-10-16
picChartColorAll.BackColor = cdlg.Color;
}
catch
{
}
}
}
}
}