2011-12-17 05:22:40 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2012-04-24 10:49:27 -03:00
|
|
|
|
namespace ArdupilotMega.Controls
|
2011-12-17 05:22:40 -04:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2012-04-24 10:49:27 -03:00
|
|
|
|
/// profiling showed that the built in Label function was using alot of call time.
|
2011-12-17 05:22:40 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class MyLabel : Control //: Label
|
|
|
|
|
{
|
|
|
|
|
string label = "";
|
|
|
|
|
int noofchars = 0;
|
|
|
|
|
bool autosize = false;
|
|
|
|
|
|
|
|
|
|
[System.ComponentModel.Browsable(true)]
|
|
|
|
|
public bool resize { get { return autosize; } set { autosize = value; } }
|
|
|
|
|
|
|
|
|
|
public MyLabel()
|
|
|
|
|
{
|
|
|
|
|
}
|
2012-02-14 10:13:11 -04:00
|
|
|
|
|
2011-12-17 05:22:40 -04:00
|
|
|
|
public override string Text
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return label;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2012-02-14 10:13:11 -04:00
|
|
|
|
|
2011-12-17 05:22:40 -04:00
|
|
|
|
if (value == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (label == value)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
label = value;
|
|
|
|
|
|
|
|
|
|
if (noofchars != label.Length && resize)
|
|
|
|
|
{
|
|
|
|
|
noofchars = label.Length;
|
|
|
|
|
Size textSize = TextRenderer.MeasureText(value, this.Font);
|
|
|
|
|
this.Width = textSize.Width;
|
2012-02-14 10:13:11 -04:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-12 11:06:22 -03:00
|
|
|
|
if (this.Visible && ThisReallyVisible())
|
|
|
|
|
this.Invalidate();
|
2011-12-17 05:22:40 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-12 11:06:22 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// this is to fix a mono off screen drawing issue
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool ThisReallyVisible()
|
|
|
|
|
{
|
|
|
|
|
if (Parent != null)
|
|
|
|
|
return this.Bounds.IntersectsWith(Parent.ClientRectangle);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-12-17 05:22:40 -04:00
|
|
|
|
SolidBrush s = new SolidBrush(Color.White);
|
|
|
|
|
SolidBrush b = new SolidBrush(Color.Black);
|
|
|
|
|
|
|
|
|
|
StringFormat stringFormat = new StringFormat();
|
|
|
|
|
|
|
|
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
|
|
|
{
|
2012-07-16 10:37:35 -03:00
|
|
|
|
|
|
|
|
|
TextRenderer.DrawText(e.Graphics, label, this.Font, new Point(0, 0), ForeColor);
|
|
|
|
|
/*
|
|
|
|
|
//return;
|
|
|
|
|
|
2011-12-17 05:22:40 -04:00
|
|
|
|
stringFormat.Alignment = StringAlignment.Near;
|
|
|
|
|
stringFormat.LineAlignment = StringAlignment.Center;
|
|
|
|
|
|
|
|
|
|
s = new SolidBrush(ForeColor);
|
|
|
|
|
|
|
|
|
|
e.Graphics.DrawString(label, this.Font, s, new PointF(0, this.Height / 2.0f), stringFormat);
|
2012-07-16 10:37:35 -03:00
|
|
|
|
*/
|
2011-12-17 05:22:40 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnPaintBackground(PaintEventArgs pevent)
|
|
|
|
|
{
|
|
|
|
|
b = new SolidBrush(BackColor);
|
|
|
|
|
|
|
|
|
|
pevent.Graphics.FillRectangle(b, this.ClientRectangle);
|
|
|
|
|
|
|
|
|
|
base.OnPaintBackground(pevent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void WndProc(ref Message m) // seems to crash here on linux... so try ignore it
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
base.WndProc(ref m);
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|