WPF TeeChart with ElementHost

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
MVUser6
Newbie
Newbie
Posts: 30
Joined: Wed Jul 11, 2012 12:00 am

WPF TeeChart with ElementHost

Post by MVUser6 » Wed Aug 15, 2012 7:37 am

Hi,

i have WPF teechart control inside an ElementHost(in winforms application).
i want the TeeChart to invoke the AfterDraw event.

i tried to use DoInvalidate,Invalidate,InvalidateVisual, ... and ElementHost.Referesh, ElementHost.Invalidate... , but i can't make the event invoke.
When does the afterdraw event occur and how can i make it invoke inside an ElementHost?

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

Re: WPF TeeChart with ElementHost

Post by Sandra » Thu Aug 16, 2012 8:33 am

Hello MVUser6,

Can you please try to arrange a simple code because we can reproduce your problem here? On the other hand, you can try use Bitmap in winforms or BitmapSource in WPF to repaint as do in next lines of code:

Code: Select all

Bitmap bmp = tChart1.Chart.Bitmap();
or

Code: Select all

BitmapSource bmp = tChart1.Chart.Bitmap();

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

MVUser6
Newbie
Newbie
Posts: 30
Joined: Wed Jul 11, 2012 12:00 am

Re: WPF TeeChart with ElementHost

Post by MVUser6 » Thu Aug 16, 2012 10:36 am

Here is a sample project.

i want to somehow make the teechart call the afterdraw, with function call from the elementhost\the teechart itself.
Attachments
TeeChartTestWithElementHost.rar
(14.46 KiB) Downloaded 516 times

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

Re: WPF TeeChart with ElementHost

Post by Sandra » Thu Aug 16, 2012 1:39 pm

Hello MVUser6,

If you want TeeChart call AfterDraw Event, you must use the BitmapSource to achieve the Chart draw again. BitmapSource is behaved as bitmap and method Draw() of winforms. I have modified your button click event because the chart is repainted.

Code: Select all

  public partial class Form1 : Form
    {
        private Steema.TeeChart.WPF.TChart TChartControl;        

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            InitTChartProperties();
        }

        private void InitTChartProperties()
        {
            this.SuspendLayout();

            TChartControl = new Steema.TeeChart.WPF.TChart();
            
            elementHost1.Visible = false;

            this.pictureBox1.Controls.Add(this.elementHost1);
            this.TChartControl.Aspect.View3D = false;
            this.elementHost1.BackColor = System.Drawing.Color.Transparent;


            this.elementHost1.Size = new System.Drawing.Size(916, 474);
            this.TChartControl.TabIndex = 3;
             Steema.TeeChart.WPF.Styles.Line line = new Steema.TeeChart.WPF.Styles.Line(TChartControl.Chart);
            this.TChartControl[0].FillSampleValues();
            this.TChartControl.AfterDraw  = new Steema.TeeChart.WPF.PaintChartEventHandler(TChartControl_AfterDraw);
           
            elementHost1.Child = TChartControl;
            elementHost1.Dock = DockStyle.Fill;
            this.ResumeLayout();
            elementHost1.Visible = true;
            
        }

        void TChartControl_AfterDraw(object sender, Steema.TeeChart.WPF.Drawing.Graphics3D g)
        {
            richTextBox1.Text  = "AfterDraw Invoked"   Environment.NewLine;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            elementHost1.Refresh();
            BitmapSource bitmap = TChartControl.Chart.Bitmap();
        }
Does it work as you expect?

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

Post Reply