在MFC中显示.NET图表控件

时间:2018-08-31 11:19:27

标签: c++ .net winforms charts mfc

我想在MFC对话框中显示.NET图表控件。我通过CWinFormsControl实例使用了托管控件。在.NET端,我创建了一个带有文本框,按钮和图表控件的UserControl。

不幸的是,我无法设置Chart控件的属性。尽管可以识别Chart控件本身,但不能识别/访问其任何属性或方法。

在Forms / .NET中:

namespace HostableUserControl
{
partial class UserControl1
{
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Component Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify 
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
        System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
        this.button1 = new System.Windows.Forms.Button();
        this.textBox1 = new System.Windows.Forms.TextBox();
        this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();
        ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit();
        this.SuspendLayout();
        // 
        // button1
        // 
        this.button1.Location = new System.Drawing.Point(39, 25);
        this.button1.Name = "button1";
        this.button1.Size = new System.Drawing.Size(75, 23);
        this.button1.TabIndex = 0;
        this.button1.Text = "button1";
        this.button1.UseVisualStyleBackColor = true;
        // 
        // textBox1
        // 
        this.textBox1.Location = new System.Drawing.Point(140, 163);
        this.textBox1.Name = "textBox1";
        this.textBox1.Size = new System.Drawing.Size(98, 20);
        this.textBox1.TabIndex = 1;
        this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
        // 
        // chart1
        // 
        this.chart1.BorderSkin.SkinStyle = System.Windows.Forms.DataVisualization.Charting.BorderSkinStyle.FrameThin1;
        chartArea1.Name = "ChartArea1";
        this.chart1.ChartAreas.Add(chartArea1);
        this.chart1.Location = new System.Drawing.Point(140, 23);
        this.chart1.Name = "chart1";
        series1.ChartArea = "ChartArea1";
        series1.Name = "Series1";
        this.chart1.Series.Add(series1);
        this.chart1.Size = new System.Drawing.Size(251, 134);
        this.chart1.TabIndex = 2;
        this.chart1.Text = "chart1";
        // 
        // UserControl1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
        this.Controls.Add(this.chart1);
        this.Controls.Add(this.textBox1);
        this.Controls.Add(this.button1);
        this.Name = "UserControl1";
        this.Size = new System.Drawing.Size(394, 200);
        ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit();
        this.ResumeLayout(false);
        this.PerformLayout();

    }

    #endregion

    public System.Windows.Forms.Button button1;
    public System.Windows.Forms.TextBox textBox1;
    public System.Windows.Forms.DataVisualization.Charting.Chart chart1;
}

}

//在MFC中(代码段):

CWinFormsControl<HostableUserControl::UserControl1> m_ctrl1;

{
    m_ctrl1.GetControl()->textBox1->Text = "hello world";  // this works
    m_ctrl1.GetControl()->chart1->Text = "hello world";    // this generates compiler error
}

编译器错误(VS2017):

错误C2039:“文本”:不是System :: Windows :: Forms :: DataVisualization :: Charting :: Chart'的成员

此错误是针对Chart的所有公共成员生成的。

有什么建议吗?

0 个答案:

没有答案