Annotation String Position

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
lilo
Newbie
Newbie
Posts: 18
Joined: Thu Sep 12, 2013 12:00 am

Annotation String Position

Post by lilo » Mon Sep 16, 2013 6:41 am

I need to center the string on an annotation horizontally. If I use AnnotationChart.Shape.TextAlign = StringAlignment.Center, the string should be centered horizontally? However, I can only get it positioned in the left near position?

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Annotation String Position

Post by Sandra » Mon Sep 16, 2013 9:52 am

Hello lilo,

If you use the Annotation tool property TextAlign and choose Center option, the text is Centered in the center of the Annotation tool, if you choose near option, it is aligned to left bound of rectangle and if you choose far option, the text is aligned to right bound of rectangle. See next code to check it:

Code: Select all

    Steema.TeeChart.TChart tChart1; 
    public Form1()
    {
      InitializeComponent();
      tChart1 = new TChart();
      this.Controls.Add(tChart1);
     // tChart1.Dock = DockStyle.Fill;
      tChart1.Top = 150;
      tChart1.Left = 100;
      tChart1.Height = 400;
      tChart1.Width = 550; 
      tChart1.Aspect.View3D = false; 
      InitializeChart();
    }
    private void InitializeChart()
    {

      Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
      Steema.TeeChart.Tools.Annotation an = new Steema.TeeChart.Tools.Annotation(tChart1.Chart);
      bar1.FillSampleValues();
      an.Text = " Steema Software"; 
      an.TextAlign = StringAlignment.Center;
      button1.Click += button1_Click;
      checkBox1.Checked = true;
      checkBox2.Checked = false;
      checkBox3.Checked = false; 
      checkBox1.CheckedChanged += checkBox1_CheckedChanged;
      checkBox2.CheckedChanged += checkBox2_CheckedChanged;
      checkBox3.CheckedChanged += checkBox3_CheckedChanged;
    }

    void checkBox3_CheckedChanged(object sender, EventArgs e)
    {
      Steema.TeeChart.Tools.Annotation tool = (tChart1.Tools[0] as Steema.TeeChart.Tools.Annotation);
      if (checkBox3.Checked)
      {
        tool.TextAlign = StringAlignment.Far;
        checkBox1.Checked = false;
        checkBox2.Checked = false;
      }
    }

    void checkBox2_CheckedChanged(object sender, EventArgs e)
    {
      Steema.TeeChart.Tools.Annotation tool = (tChart1.Tools[0] as Steema.TeeChart.Tools.Annotation);
      if (checkBox2.Checked)
      {
        tool.TextAlign = StringAlignment.Near;
      }
      checkBox1.Checked = false;
      checkBox3.Checked = false;
    }

    void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
      Steema.TeeChart.Tools.Annotation tool = (tChart1.Tools[0] as Steema.TeeChart.Tools.Annotation); 
      if (checkBox1.Checked)
      {
        tool.TextAlign = StringAlignment.Center; 
      }
      checkBox2.Checked = false;
      checkBox3.Checked = false;
    }

    void button1_Click(object sender, EventArgs e)
    {
      tChart1.ShowEditor(); 
    }
Please, could you check my code and tell us if it works in your end? If you consider it doesn't work properly for you, could you please tell us why?

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

lilo
Newbie
Newbie
Posts: 18
Joined: Thu Sep 12, 2013 12:00 am

Re: Annotation String Position

Post by lilo » Mon Sep 16, 2013 10:12 am

Hi Sandra,

Thanks, it does work correctly...my problem was I did not set the annotation.width property correctly.

lilo

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Annotation String Position

Post by Sandra » Mon Sep 16, 2013 10:21 am

Hello lilo,

I am glad your problem solved. :D

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

lilo
Newbie
Newbie
Posts: 18
Joined: Thu Sep 12, 2013 12:00 am

Re: Annotation String Position

Post by lilo » Mon Sep 16, 2013 12:26 pm

Hi Sandra,

I struck another problem, the centering works fine for a text string with two characters or more, but does not work with one character. How can I center one character?

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Annotation String Position

Post by Sandra » Tue Sep 17, 2013 9:43 am

Hello lilo,

I have changed the Annotation Tools string Steema Software to A and it is centered correctly, you can check it in my attached project. If in my project your problem doesn't occurs, but in your project the problem appears, could you please send us your project and tell us which version are you using, because can suggest you a good solution?
TestVS2012.zip
(10.61 KiB) Downloaded 887 times
Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

lilo
Newbie
Newbie
Posts: 18
Joined: Thu Sep 12, 2013 12:00 am

Re: Annotation String Position

Post by lilo » Thu Sep 19, 2013 9:09 am

Thanks Sandra,

I can't open your project, as I am still using Visual Studio 2010...I might have to download an express version. In the meantime, I am able to workaround the problem by setting the annotation width and height manually to the character width and height.

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Annotation String Position

Post by Sandra » Fri Sep 20, 2013 11:06 am

Hello lilo,

I have modified my project, because you can use it in VS2010. Could you test my attached project?
TestVisualStudio2010.zip
(11.13 KiB) Downloaded 899 times
Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

lilo
Newbie
Newbie
Posts: 18
Joined: Thu Sep 12, 2013 12:00 am

Re: Annotation String Position

Post by lilo » Fri Sep 27, 2013 8:40 am

Hi Sandra,

Thanks, your project works fine. My project(s) will not work. I am using Visual Basic Net 2010 TeeChart V 4.1.2012.1312.

I am creating the annotation tools at runtime without the edit window.

Private Sub TChart1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TChart1.MouseDown
NumText = NumText + 1
ReDim Preserve AnnotationChart(NumText)
AnnotationChart(NumText) = New Steema.TeeChart.Tools.RectangleTool(TChart1.Chart)
AnnotationChart(NumText).PositionUnits = Steema.TeeChart.PositionUnits.Pixels
AnnotationChart(NumText).Shape.TextAlign = StringAlignment.Center
AnnotationChart(NumText).AllowResize = True
AnnotationChart(NumText).AllowEdit = True
AnnotationChart(NumText).AllowDrag = True
AnnotationChart(NumText).AutoSize = True
AnnotationChart(NumText).ClipText = True
AnnotationChart(NumText).Shape.Transparent = True
AnnotationChart(NumText).Shape.Font.Color = FontColor
AnnotationChart(NumText).Shape.Font.Name = NewTextFont
AnnotationChart(NumText).Shape.Font.Size = NewTextSize
AnnotationChart(NumText).Shape.Font.Bold = NewTextBold
AnnotationChart(NumText).Shape.Font.Italic = NewTextItalic
AnnotationChart(NumText).Shape.Font.Underline = NewTextUnderline
AnnotationChart(NumText).Shape.CustomPosition = True
AnnotationChart(NumText).Text = SymbolType
AnnotationChart(NumText).EndEdit()
AnnotationChart(NumText).Left = e.X - (AnnotationChart(NumText).Width / 2)
AnnotationChart(NumText).Top = e.Y - (AnnotationChart(NumText).Bounds.Height / 2)
AnnotationChart(NumText).Shape.Visible = True

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Annotation String Position

Post by Sandra » Fri Sep 27, 2013 3:38 pm

Hello lilo,

Could you please, send us your project because we can reproduce your problem here and try to find the issue and try to give you a solution?

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

lilo
Newbie
Newbie
Posts: 18
Joined: Thu Sep 12, 2013 12:00 am

Re: Annotation String Position

Post by lilo » Sat Sep 28, 2013 3:44 am

Hi Sandra,

Attached is a project for visual studio 2010.
Attachments
CenterAnnotationTest (2).zip
(178.72 KiB) Downloaded 875 times

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Annotation String Position

Post by Sandra » Mon Sep 30, 2013 9:50 am

Hello lilo,

I have found your problem. It seems appears when you access to the RectangleTool TextAlign property, using the Shape of this tool as do in next line of code:

Code: Select all

 AnnotationChart(NumText).Shape.TextAlign = StringAlignment.Center
In this point, you must know you can access to RectangleTool TextAlign property directly, without using shape. I have changed it in your code and the problem of align disappears. You can see the modification, in next lines of code:

Code: Select all

    Private Sub TChart1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles TChart1.MouseDown
        NumText = NumText + 1
        ReDim Preserve AnnotationChart(NumText)
        AnnotationChart(NumText) = New Steema.TeeChart.Tools.RectangleTool(TChart1.Chart)
        AnnotationChart(NumText).PositionUnits = Steema.TeeChart.PositionUnits.Pixels
        AnnotationChart(NumText).TextAlign = StringAlignment.Center
        AnnotationChart(NumText).AllowResize = True
        AnnotationChart(NumText).AllowEdit = True
        AnnotationChart(NumText).AllowDrag = True
        AnnotationChart(NumText).AutoSize = True
        AnnotationChart(NumText).ClipText = True
        'Change Shape.
        AnnotationChart(NumText).Shape.Visible = True
        AnnotationChart(NumText).Shape.Pen.Visible = True
        AnnotationChart(NumText).Shape.Transparent = False 'True
        AnnotationChart(NumText).Shape.Font.Color = Color.Black
        AnnotationChart(NumText).Shape.Font.Name = "Arial" 'NewTextFont
        AnnotationChart(NumText).Shape.Font.Size = 26 'NewTextSize
        AnnotationChart(NumText).Shape.Font.Bold = False 'NewTextBold
        AnnotationChart(NumText).Shape.Font.Italic = False 'NewTextItalic
        AnnotationChart(NumText).Shape.Font.Underline = False 'NewTextUnderline
        AnnotationChart(NumText).Shape.CustomPosition = True
        AnnotationChart(NumText).Text = "+"
        AnnotationChart(NumText).EndEdit()
        AnnotationChart(NumText).Left = e.X - (AnnotationChart(NumText).Width / 2)
        AnnotationChart(NumText).Top = e.Y - (AnnotationChart(NumText).Bounds.Height / 2)
    End Sub
Could you tell us if previous code solve your problem?

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

lilo
Newbie
Newbie
Posts: 18
Joined: Thu Sep 12, 2013 12:00 am

Re: Annotation String Position

Post by lilo » Thu Oct 03, 2013 12:33 am

Thanks Sandra,

This solved the problem.

Post Reply