Hello Lothar Weidl-Walthe,
Sorry for the delay, but I have had many problems in my computer to execute the program because works using LogFont class, but, finally I have achieved it. First, I apologize, so I understood you had some problems in your code, I made a mistake, sorry for the confusion. In the other hand, I consider your project is a good solution but I think you must use general values to treat the position of text, for this reason, I have modified your code because it works in a optimize way for all versions of Windows CE. Moreover I think this code can help other client have a similar problem as you.
References needed:
Code: Select all
using Steema.TeeChart.Drawing;
using Steema.TeeChart.Styles;
using Steema.TeeChart.Pocket;
using Microsoft.WindowsCE.Forms;
Code:
Code: Select all
private TChart Chart1;
private FastLine Graph;
string LeftAxisTitle;
public Form1()
{
InitializeComponent();
//InitializeChart
Chart1 = new TChart();
this.Controls.Add(Chart1);
Chart1.Size = new Size(500, 300);
Chart1.Location = new Point(100, 20);
Chart1.Aspect.View3D = false;
Chart1.Legend.Visible = false;
Chart1.Chart.Panel.MarginLeft = 5; // give place for the title
//Add a Series
Graph = new FastLine(Chart1.Chart);
Graph.FillSampleValues(10);
//Customize axes values.
Chart1.Axes.Bottom.MinorTickCount = 4;
Chart1.Axes.Bottom.Automatic = false;
Chart1.Axes.Bottom.SetMinMax(0, 3);
Chart1.Axes.Bottom.Labels.Separation = 40;
Chart1.Axes.Bottom.Title.Text = "Time [s]";
LeftAxisTitle = "Torque [N.m]";
Chart1.Axes.Left.Automatic = false;
Chart1.Axes.Left.SetMinMax(0, Graph.YValues.Maximum);
Chart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(Chart1_AfterDraw);
Chart1.Invalidate();
}
protected void Chart1_AfterDraw(object sender, Graphics3D g)
{
int StrWidth; // length of the in pixel
int StartPos; // y value of the start position for writing (0 = top position)
Font myFont = CreateRotatedFont("Tahoma", 11, 90);
Brush myBrush = new SolidBrush(Color.Black);
//Use a general values.
StrWidth = Convert.ToInt32(LeftAxisTitle.Length * myFont.Size);
StartPos = (Chart1.Height+StrWidth) / 2;
RectangleF myRect = new RectangleF(8, StartPos, StrWidth, -StrWidth);
g.GDIplusCanvas.DrawString(LeftAxisTitle, myFont, myBrush, myRect);
myFont.Dispose();
myBrush.Dispose();
}
public static Font CreateRotatedFont(string fontname, int height, int angleInDegrees)
{
Microsoft.WindowsCE.Forms.LogFont logf = new LogFont();
logf.Height = -1 * height;
logf.FaceName = fontname;
logf.Escapement = angleInDegrees * 10;
logf.Orientation = logf.Escapement;
logf.CharSet = LogFontCharSet.Default;
logf.OutPrecision = LogFontPrecision.Default;
logf.ClipPrecision = LogFontClipPrecision.Default;
logf.Quality = LogFontQuality.ClearType;
logf.PitchAndFamily = LogFontPitchAndFamily.Default;
return Font.FromLogFont(logf);
}
Many thanks for your code.