using System.Drawing; using System.Windows.Forms; namespace Dongke.WinForm.Controls.InvoiceLayout { internal partial class GraphicsItemSetting : Setting { #region 成员变量 private bool _isTransparent = false; // 背景是否透明 private Color _fillColor = Color.Black; // 背景颜色 #endregion 成员变量 #region 属性 /// /// X(mm) /// public float ShapeLocationX { get { return System.Convert.ToSingle(numlocationX.Value); } set { decimal d = System.Convert.ToDecimal(value); if (d < numlocationX.Minimum) { d = numlocationX.Minimum; } else if (numlocationX.Maximum < d) { d = numlocationX.Maximum; } numlocationX.Value = d; } } /// /// Y(mm) /// public float ShapeLocationY { get { return System.Convert.ToSingle(numlocationY.Value); } set { decimal d = System.Convert.ToDecimal(value); if (d < numlocationY.Minimum) { d = numlocationY.Minimum; } else if (numlocationY.Maximum < d) { d = numlocationY.Maximum; } numlocationY.Value = d; } } /// /// 宽(mm) /// public float ShapeWidth { 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; } } /// /// 高(mm) /// public float ShapeHeight { 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 Color LineColor { get { return lblLineColor.BackColor; } set { lblLineColor.BackColor = value; if (lblLineColor.BackColor != Color.White) { lblLineBColor.BackColor = lblLineColor.BackColor; } else { lblLineBColor.BackColor = Color.Black; } } } /// /// 背景颜色 /// public Color FillColor { get { return _fillColor; } set { _fillColor = value; SetFillColor(); } } /// /// 线宽 /// public float LineWidth { get { return System.Convert.ToSingle(numLineWidth.Value); } set { decimal d = System.Convert.ToDecimal(value); if (d < numLineWidth.Minimum) { d = numLineWidth.Minimum; } else if (numLineWidth.Maximum < d) { d = numLineWidth.Maximum; } numLineWidth.Value = d; } } /// /// 背景是否透明 /// public bool Transparent { get { return _isTransparent; } set { _isTransparent = value; SetFillColor(); } } /// /// 线型图形 /// public bool Line { get { return txtFillColor.Enabled; } set { txtFillColor.Enabled = !value; lblFillColor.Enabled = !value; lblFillBColor.Enabled = !value; btnSelectFillColor.Enabled = !value; btnFillTransparent.Enabled = !value; numWidth.Minimum = -999.9m; numHeight.Minimum = -999.9m; numHeight.Validating += new System.ComponentModel.CancelEventHandler(this.numHeight_Validating); numWidth.Validating += new System.ComponentModel.CancelEventHandler(this.numWidth_Validating); } } #endregion 属性 #region 构造函数 /// /// 构造函数 /// public GraphicsItemSetting() { InitializeComponent(); } #endregion 构造函数 #region 函数 /// /// 设置背景颜色 /// private void SetFillColor() { if (_isTransparent) { lblFillColor.BackColor = Color.Empty; lblFillBColor.BackColor = Color.Empty; } else { lblFillColor.BackColor = _fillColor; if (_fillColor != Color.White) { lblFillBColor.BackColor = _fillColor; } else { lblFillBColor.BackColor = Color.Black; } } } #endregion 函数 #region 事件处理 /// /// 设置线的颜色 /// /// 指定的对象 /// 提供的事件数据 private void btnSelectLineColor_Click(object sender, System.EventArgs e) { colorDialog.Color = (lblLineColor.BackColor == Color.Transparent) ? Color.Empty : lblLineColor.BackColor; if (colorDialog.ShowDialog() == DialogResult.OK) { LineColor = colorDialog.Color; } } /// /// 设置背景颜色 /// /// 指定的对象 /// 提供的事件数据 private void btnSelectFillColor_Click(object sender, System.EventArgs e) { colorDialog.Color = _isTransparent ? Color.Empty : _fillColor; if (colorDialog.ShowDialog() == DialogResult.OK) { _fillColor = colorDialog.Color; Transparent = false; } } /// /// 设置线段是否透明 /// /// 指定的对象 /// 提供的事件数据 private void btnSelectLineTransparent_Click(object sender, System.EventArgs e) { lblLineColor.BackColor = Color.Transparent; lblLineBColor.BackColor = Color.Transparent; } /// /// 设置背景是否透明 /// /// 指定的对象 /// 提供的事件数据 private void btnFillTransparent_Click(object sender, System.EventArgs e) { Transparent = true; } /// /// 图形的宽度验证 /// /// /// private void numWidth_Validating(object sender, System.ComponentModel.CancelEventArgs e) { if (numHeight.Value == 0 && numWidth.Value == 0) { numWidth.Value = 0.1m; } } /// /// 图形的高度验证 /// /// /// private void numHeight_Validating(object sender, System.ComponentModel.CancelEventArgs e) { if (numHeight.Value == 0 && numWidth.Value == 0) { numHeight.Value = 0.1m; } } #endregion 事件处理 } }