/// <summary>
/// 在内存中以XML格式生成所有用户输入信息
/// </summary>
/// <returns>返回XmlDocument对象</returns>
private XmlDocument SaveToXml()
{
this.xmlString = "<TextFormatInfo>";
PreFontName = this.EditBox.SelectionFont.Name;//前一个字的字体
PreFontSize = this.EditBox.SelectionFont.Size;//前一个字大小
PreColor = this.EditBox.SelectionColor.Name;//前一个字的颜色
PreAlignment = this.EditBox.SelectionAlignment.ToString();//前一个字的对齐方式
PreBold = this.EditBox.SelectionFont.Bold;//前一个字是否为粗体
PreItalic = this.EditBox.SelectionFont.Italic;//前一个字是否为斜体
PreUnderLine = this.EditBox.SelectionFont.Underline;//前一个字是否有下划线
//初始化第一个字的格式信息
xmlString += "<Text Font='"+PreFontName+"' Size='"+PreFontSize.ToString()+"' Color='"+PreColor+"' Alignment='"+PreAlignment+"' Bold='"+PreBold.ToString()+"' Italic='"+PreItalic.ToString()+"' UnderLine='"+PreUnderLine.ToString()+"'>";
textInfo = this.EditBox.SelectedText;
//遍历输入的所有内容
for(int i=0;i<this.EditBox.Text.Length;i++)
{
this.EditBox.Select(i,1);
if(this.EditBox.SelectionFont.Name != PreFontName)//如果前后两个字体不同
{
textInfo = this.EditBox.SelectedText;
PreFontName = this.EditBox.SelectionFont.Name;
PreFontSize = this.EditBox.SelectionFont.Size;
PreColor = this.EditBox.SelectionColor.Name;
PreAlignment = this.EditBox.SelectionAlignment.ToString();
PreBold = this.EditBox.SelectionFont.Bold;
PreItalic = this.EditBox.SelectionFont.Italic;
PreUnderLine = this.EditBox.SelectionFont.Underline;
xmlString += "</Text><Text Font='"+PreFontName+"' Size='"+PreFontSize.ToString()+"' Color='"+PreColor+"' Alignment='"+PreAlignment+"' Bold='"+PreBold.ToString()+"' Italic='"+PreItalic.ToString()+"' UnderLine='"+PreUnderLine.ToString()+"'>";
xmlString += textInfo;
}
else
{
if(this.EditBox.SelectionFont.Size != PreFontSize)//如果前后两个大小不同
{
textInfo = this.EditBox.SelectedText;
PreFontName = this.EditBox.SelectionFont.Name;
PreFontSize = this.EditBox.SelectionFont.Size;
PreColor = this.EditBox.SelectionColor.Name;
PreAlignment = this.EditBox.SelectionAlignment.ToString();
PreBold = this.EditBox.SelectionFont.Bold;
PreItalic = this.EditBox.SelectionFont.Italic;
PreUnderLine = this.EditBox.SelectionFont.Underline;
xmlString += "</Text><Text Font='"+PreFontName+"' Size='"+PreFontSize.ToString()+"' Color='"+PreColor+"' Alignment='"+PreAlignment+"' Bold='"+PreBold.ToString()+"' Italic='"+PreItalic.ToString()+"' UnderLine='"+PreUnderLine.ToString()+"'>";
xmlString += textInfo;
}
else
{
if(this.EditBox.SelectionColor.Name != PreColor)//如果前后两个颜色不同
{
textInfo = this.EditBox.SelectedText;
PreFontName = this.EditBox.SelectionFont.Name;
PreFontSize = this.EditBox.SelectionFont.Size;
PreColor = this.EditBox.SelectionColor.Name;
PreAlignment = this.EditBox.SelectionAlignment.ToString();
PreBold = this.EditBox.SelectionFont.Bold;
PreItalic = this.EditBox.SelectionFont.Italic;
PreUnderLine = this.EditBox.SelectionFont.Underline;
xmlString += "</Text><Text Font='"+PreFontName+"' Size='"+PreFontSize.ToString()+"' Color='"+PreColor+"' Alignment='"+PreAlignment+"' Bold='"+PreBold.ToString()+"' Italic='"+PreItalic.ToString()+"' UnderLine='"+PreUnderLine.ToString()+"'>";
xmlString += textInfo;
}
else
{
if(this.EditBox.SelectionAlignment.ToString() != PreAlignment)//如果前后两个对齐方式不同
{
textInfo = this.EditBox.SelectedText;
PreFontName = this.EditBox.SelectionFont.Name;
PreFontSize = this.EditBox.SelectionFont.Size;
PreColor = this.EditBox.SelectionColor.Name;
PreAlignment = this.EditBox.SelectionAlignment.ToString();
PreBold = this.EditBox.SelectionFont.Bold;
PreItalic = this.EditBox.SelectionFont.Italic;
PreUnderLine = this.EditBox.SelectionFont.Underline;
xmlString += "</Text><Text Font='"+PreFontName+"' Size='"+PreFontSize.ToString()+"' Color='"+PreColor+"' Alignment='"+PreAlignment+"' Bold='"+PreBold.ToString()+"' Italic='"+PreItalic.ToString()+"' UnderLine='"+PreUnderLine.ToString()+"'>";
xmlString += textInfo;
}
else
{
if(this.EditBox.SelectionFont.Bold != PreBold)
{
textInfo = this.EditBox.SelectedText;
PreFontName = this.EditBox.SelectionFont.Name;
PreFontSize = this.EditBox.SelectionFont.Size;
PreColor = this.EditBox.SelectionColor.Name;
PreAlignment = this.EditBox.SelectionAlignment.ToString();
PreBold = this.EditBox.SelectionFont.Bold;
PreItalic = this.EditBox.SelectionFont.Italic;
PreUnderLine = this.EditBox.SelectionFont.Underline;
xmlString += "</Text><Text Font='"+PreFontName+"' Size='"+PreFontSize.ToString()+"' Color='"+PreColor+"' Alignment='"+PreAlignment+"' Bold='"+PreBold.ToString()+"' Italic='"+PreItalic.ToString()+"' UnderLine='"+PreUnderLine.ToString()+"'>";
xmlString += textInfo;
}
else
{
if(this.EditBox.SelectionFont.Italic != PreItalic)
{
textInfo = this.EditBox.SelectedText;
PreFontName = this.EditBox.SelectionFont.Name;
PreFontSize = this.EditBox.SelectionFont.Size;
PreColor = this.EditBox.SelectionColor.Name;
PreAlignment = this.EditBox.SelectionAlignment.ToString();
PreBold = this.EditBox.SelectionFont.Bold;
PreItalic = this.EditBox.SelectionFont.Italic;
PreUnderLine = this.EditBox.SelectionFont.Underline;
xmlString += "</Text><Text Font='"+PreFontName+"' Size='"+PreFontSize.ToString()+"' Color='"+PreColor+"' Alignment='"+PreAlignment+"' Bold='"+PreBold.ToString()+"' Italic='"+PreItalic.ToString()+"' UnderLine='"+PreUnderLine.ToString()+"'>";
xmlString += textInfo;
}
else
{
if(this.EditBox.SelectionFont.Underline != PreUnderLine)
{
textInfo = this.EditBox.SelectedText;
PreFontName = this.EditBox.SelectionFont.Name;
PreFontSize = this.EditBox.SelectionFont.Size;
PreColor = this.EditBox.SelectionColor.Name;
PreAlignment = this.EditBox.SelectionAlignment.ToString();
PreBold = this.EditBox.SelectionFont.Bold;
PreItalic = this.EditBox.SelectionFont.Italic;
PreUnderLine = this.EditBox.SelectionFont.Underline;
xmlString += "</Text><Text Font='"+PreFontName+"' Size='"+PreFontSize.ToString()+"' Color='"+PreColor+"' Alignment='"+PreAlignment+"' Bold='"+PreBold.ToString()+"' Italic='"+PreItalic.ToString()+"' UnderLine='"+PreUnderLine.ToString()+"'>";
xmlString += textInfo;
}
else
{
textInfo = this.EditBox.SelectedText;
xmlString += textInfo;
}
}
}
}
}
}
}
this.EditBox.Select(i+1,0);
}
XmlDocument doc = new XmlDocument();
this.XmlTextBox.Text = xmlString + "</Text></TextFormatInfo>";
doc.LoadXml(xmlString+"</Text></TextFormatInfo>");
return doc;
}