1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mapscope.BcTools;
using System.Drawing;
using System.Windows.Forms;
namespace TestFloatingText
{
public class C_PrintObj
{
static Font _defaultFont = new Font("Arial", 10);
static Color _defaultTxtColor = Color.Black;
static Color _defaultBackColor = Color.Beige;
// static Bitmap bmp = new Bitmap(16, 16);
// static Graphics StaticG = Graphics.FromImage(bmp);
public C_PrintObj()
{
this.Fnt = FontSerializable.FromFont(_defaultFont);
this.TextColor = ColorSerializable.FromColor(_defaultTxtColor);
this.BackColor = ColorSerializable.FromColor(_defaultBackColor);
}
public C_PrintObj(Font TxtFnt,Color FntColor,Color BackColor)
{
this.Fnt = FontSerializable.FromFont(TxtFnt);
this.TextColor = ColorSerializable.FromColor(FntColor);
this.BackColor = ColorSerializable.FromColor(BackColor);
}
public int TP; // 0=bitmap 2=txt
public string Country; // Quel Country
public string LayerID; // Quel layer
public string Code { get; set; } // Quel code externe
public UInt32 ID { get; set; } // Code Interne si possible
private string _text; // Texte a afficher
public ColorSerializable TextColor; // Couleur texte
public ColorSerializable BackColor; // Couleur fond
public int BackAlpha; // Alpha channel Couleur fond
public FontSerializable Fnt; // Font Texte
public PointF MapPosition;
public Point PagePosition;
public Rectangle Bounds;
public Bitmap Bmp;
public bool DrawBorder;
/// <summary>
/// Indique si l'element est activé pour déplacement et ne fera pas partie du fond statique
/// UN SEUL par liste
/// </summary>
public bool Moving;
public string Text
{
get
{
return _text;
}
set
{
_text = value;
if ((this.TP == 0) && (_text != string.Empty))
{
this.Bmp = ToImage(value, this.Fnt.ToFont(), TextColor.ToColor(), BackColor.ToColor());
this.Bounds = new Rectangle(0, 0, Bmp.Width, Bmp.Height);
}
}
}
// ***************************************************************************************
private static Bitmap ToImage(string curStr, Font font, Color color, Color BackColor)
{
StringFormat format = new StringFormat();
SolidBrush LgdBrush = new SolidBrush(color);
format.Alignment = StringAlignment.Center;
SizeF szTxt = TextRenderer.MeasureText(curStr, font);
// +2 pour cadre eventuel
Bitmap bmpTxt = new Bitmap((int)szTxt.Width + 2, (int)szTxt.Height + 2);
Graphics txtG = Graphics.FromImage(bmpTxt);
RectangleF cellarea = new RectangleF(0, 0, szTxt.Width, szTxt.Height);
SolidBrush BackColorBr = new SolidBrush(Color.FromArgb(255, BackColor));
txtG.FillRectangle(BackColorBr, cellarea);
txtG.DrawString(curStr, font, LgdBrush, cellarea, format);
return bmpTxt;
}
class PrSettings
{
}
}
} |
Partager