using System.Drawing;
using System.Windows.Forms;
namespace Dongke.WinForm.Controls.InvoiceLayout
{
internal partial class PageNumItemSetting : Setting
{
#region 成员变量
private TextAlignment _textAlign = TextAlignment.LeftOrTop; // 文本对齐方式
private TextAlignment _textAlignVertical = TextAlignment.LeftOrTop; // 文本垂直对齐方式
private bool _isInit = true;
#endregion
#region 属性
///
/// 文本字体
///
public Font TextFont
{
get
{
return txtPreview.Font;
}
set
{
txtPreview.Font = value;
}
}
///
/// 文本颜色
///
public Color TextColor
{
get
{
return txtPreview.ForeColor;
}
set
{
txtPreview.ForeColor = value;
}
}
///
/// 文本对齐方式
///
public TextAlignment TextAlign
{
get
{
return _textAlign;
}
set
{
if (_textAlign != value)
{
_textAlign = value;
}
}
}
///
/// 文本垂直对齐方式
///
public TextAlignment TextAlignVertical
{
get
{
return _textAlignVertical;
}
set
{
if (_textAlignVertical != value)
{
_textAlignVertical = value;
}
}
}
///
/// X
///
public float TextLocationY
{
get
{
return System.Convert.ToSingle(numLoctionY.Value);
}
set
{
decimal d = System.Convert.ToDecimal(value);
if (d < numLoctionY.Minimum)
{
d = numLoctionY.Minimum;
}
else if (numLoctionY.Maximum < d)
{
d = numLoctionY.Maximum;
}
numLoctionY.Value = d;
}
}
///
/// Y
///
public float TextLocationX
{
get
{
return System.Convert.ToSingle(numLoctionX.Value);
}
set
{
decimal d = System.Convert.ToDecimal(value);
if (d < numLoctionX.Minimum)
{
d = numLoctionX.Minimum;
}
else if (numLoctionX.Maximum < d)
{
d = numLoctionX.Maximum;
}
numLoctionX.Value = d;
}
}
///
/// 宽
///
public float TextWidth
{
get
{
return System.Convert.ToSingle(numWidth.Value);
}
set
{
decimal d = System.Convert.ToDecimal(value);
if (d < numWidth.Minimum)
{
d = numWidth.Minimum;
}
else if (numWidth.Maximum < d)
{
d = numWidth.Maximum;
}
numWidth.Value = d;
}
}
///
/// 高
///
public float TextHeight
{
get
{
return System.Convert.ToSingle(numHeight.Value);
}
set
{
decimal d = System.Convert.ToDecimal(value);
if (d < numHeight.Minimum)
{
d = numHeight.Minimum;
}
else if (numHeight.Maximum < d)
{
d = numHeight.Maximum;
}
numHeight.Value = d;
}
}
///
/// 文本格式
///
public string TextFormat
{
get
{
return txtPageNumFormat.Text;
}
set
{
txtPageNumFormat.Text = value;
if (string.IsNullOrEmpty(txtPageNumFormat.Text))
{
this.txtPreview.Text = "";
}
else
{
this.txtPreview.Text = txtPageNumFormat.Text.Replace("&[页码]", "1").Replace("&[总页数]", "1");
}
}
}
#endregion
#region 构造函数
///
/// 构造函数
///
public PageNumItemSetting()
{
InitializeComponent();
TextWidth = LayoutCommon.DefaultTextItemSizeWidth;
TextHeight = LayoutCommon.DefaultTextItemSizeHeight;
}
#endregion
#region 事件处理
///
/// 文本设置
///
/// 指定的对象
/// 提供的事件数据
private void TextItemSetting_Shown(object sender, System.EventArgs e)
{
try
{
if (grbTextAlignment.Enabled)
{
switch (_textAlign)
{
case TextAlignment.LeftOrTop:
rbtnLeft.Checked = true;
txtPreview.TextAlign = HorizontalAlignment.Left;
break;
case TextAlignment.RightOrBottom:
rbtnRight.Checked = true;
txtPreview.TextAlign = HorizontalAlignment.Right;
break;
case TextAlignment.Center:
rbtnCenter.Checked = true;
txtPreview.TextAlign = HorizontalAlignment.Center;
break;
case TextAlignment.Evenness:
rbtnEvenness.Checked = true;
txtPreview.TextAlign = HorizontalAlignment.Left;
break;
}
}
if (grbTextAlignmentV.Enabled)
{
switch (_textAlignVertical)
{
case TextAlignment.LeftOrTop:
rbtnTop.Checked = true;
break;
case TextAlignment.RightOrBottom:
rbtnBottom.Checked = true;
break;
case TextAlignment.Center:
rbtnCenterV.Checked = true;
break;
default:
rbtnTop.Checked = true;
break;
}
}
}
finally
{
_isInit = false;
}
}
///
/// 设置文本颜色
///
/// 指定的对象
/// 提供的事件数据
private void btnSelectColor_Click(object sender, System.EventArgs e)
{
colorDialog.Color = txtPreview.ForeColor;
if (colorDialog.ShowDialog() == DialogResult.OK)
{
txtPreview.ForeColor = colorDialog.Color;
}
}
///
/// 设置文本对齐方式
///
/// 指定的对象
/// 提供的事件数据
private void rbtnTextAlignment_CheckedChanged(object sender, System.EventArgs e)
{
if (_isInit)
{
return;
}
if (rbtnLeft.Checked)
{
txtPreview.TextAlign = HorizontalAlignment.Left;
_textAlign = TextAlignment.LeftOrTop;
}
else if (rbtnRight.Checked)
{
txtPreview.TextAlign = HorizontalAlignment.Right;
_textAlign = TextAlignment.RightOrBottom;
}
else if (rbtnCenter.Checked)
{
txtPreview.TextAlign = HorizontalAlignment.Center;
_textAlign = TextAlignment.Center;
}
else
{
txtPreview.TextAlign = HorizontalAlignment.Left;
_textAlign = TextAlignment.Evenness;
}
if (rbtnTop.Checked)
{
_textAlignVertical = TextAlignment.LeftOrTop;
}
else if (rbtnBottom.Checked)
{
_textAlignVertical = TextAlignment.RightOrBottom;
}
else if (rbtnCenterV.Checked)
{
_textAlignVertical = TextAlignment.Center;
}
else
{
_textAlignVertical = TextAlignment.LeftOrTop;
}
}
///
/// 设置文本字体。
///
/// 指定的对象
/// 提供的事件数据
private void btnFont_Click(object sender, System.EventArgs e)
{
fontDialog.Font = TextFont;
if (fontDialog.ShowDialog() == DialogResult.OK)
{
TextFont = fontDialog.Font;
}
}
///
/// 设置文本格式
///
/// 指定的对象
/// 提供的事件数据
private void txtPageNumFormat_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
if (string.IsNullOrEmpty(txtPageNumFormat.Text))
{
this.txtPreview.Text = "";
}
else
{
this.txtPreview.Text = txtPageNumFormat.Text.Replace("&[页码]", "1").Replace("&[总页数]", "1");
}
}
#endregion 事件处理
}
}