128 lines
4.3 KiB
C#
128 lines
4.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace ryPrint.Mod
|
|
{
|
|
public partial class myLabel : UserControl
|
|
{
|
|
public myLabel()
|
|
{
|
|
InitializeComponent();
|
|
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
|
|
this.DoubleBuffered = true;
|
|
this.BorderStyle = BorderStyle.FixedSingle;
|
|
|
|
}
|
|
public void SetAlign(string align)
|
|
{
|
|
switch (align)
|
|
{
|
|
case "Left":
|
|
Property.Align = HorizontalAlignment.Left;
|
|
break;
|
|
case "Right":
|
|
Property.Align = HorizontalAlignment.Right;
|
|
break;
|
|
case "Center":
|
|
Property.Align = HorizontalAlignment.Center;
|
|
break;
|
|
default:
|
|
Property.Align = HorizontalAlignment.Left;
|
|
break;
|
|
}
|
|
}
|
|
public string AlignStr
|
|
{
|
|
get
|
|
{
|
|
switch (Property.Align)
|
|
{
|
|
case HorizontalAlignment.Left:
|
|
return "Left";
|
|
case HorizontalAlignment.Right:
|
|
return "Right";
|
|
case HorizontalAlignment.Center:
|
|
return "Center";
|
|
default:
|
|
return "Left";
|
|
|
|
}
|
|
}
|
|
}
|
|
private ClsProperty _Property=new ClsProperty();
|
|
public ClsProperty Property
|
|
{
|
|
get
|
|
{
|
|
_Property.Size = new SizeF(RySet.Pixeltomm(this.Size.Width), RySet.Pixeltomm(this.Size.Height));
|
|
_Property.Postion = new PointF(RySet.Pixeltomm(this.Location.X), RySet.Pixeltomm(this.Location.Y));
|
|
_Property.FontSize = this.Font.Size;
|
|
return _Property;
|
|
}
|
|
|
|
set
|
|
{
|
|
_Property = value;
|
|
this.Font = new Font(this.Font.FontFamily, _Property.FontSize);
|
|
//this.Size=_Property.Size;
|
|
//this.Location = _Property.Postion;
|
|
Refresh();
|
|
}
|
|
}
|
|
private void myLabel_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void myLabel_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
StringFormat sf = new StringFormat();
|
|
e.Graphics.PageUnit = GraphicsUnit.Pixel;
|
|
if (Property.Multiline)
|
|
{
|
|
Brush fontBrush = SystemBrushes.ControlText;
|
|
//sf.Alignment = StringAlignment.Center;
|
|
//sf.LineAlignment = StringAlignment.Center;
|
|
RectangleF rect = new RectangleF(new PointF(0, 0), this.Size);
|
|
e.Graphics.DrawString(Property.Title, this.Font, fontBrush, rect, sf);
|
|
}
|
|
else
|
|
{
|
|
switch (Property.Align)
|
|
{
|
|
case HorizontalAlignment.Left:
|
|
sf.Alignment = StringAlignment.Near;
|
|
break;
|
|
case HorizontalAlignment.Right:
|
|
sf.Alignment = StringAlignment.Far;
|
|
break;
|
|
case HorizontalAlignment.Center:
|
|
sf.Alignment = StringAlignment.Center;
|
|
break;
|
|
}
|
|
//sf.LineAlignment = sf.Alignment;
|
|
this.Height = (int)e.Graphics.MeasureString(Property.Title, this.Font).Height;
|
|
if (sf.Alignment == StringAlignment.Center || sf.Alignment == StringAlignment.Far)
|
|
{
|
|
RectangleF rect = new RectangleF(new PointF(0, 0), new Size(Width,Height));
|
|
sf.LineAlignment = sf.Alignment;
|
|
e.Graphics.DrawString(Property.Title, this.Font, Brushes.Black, rect, sf);
|
|
}
|
|
else
|
|
{
|
|
e.Graphics.DrawString(Property.Title, this.Font, Brushes.Black, new PointF(0, 0));
|
|
}
|
|
}
|
|
}
|
|
|
|
private void myLabel_Resize(object sender, EventArgs e)
|
|
{
|
|
}
|
|
}
|
|
}
|