c++ - 在 MFC 中显示 .NET 图表控件
问题描述
我想在 MFC 对话框中显示一个 .NET 图表控件。我通过 CWinFormsControl 实例使用了托管控件。在 .NET 方面,我创建了一个带有 TextBox、Button 和 Chart 控件的 UserControl。
不幸的是,我无法设置图表控件的属性。尽管 Chart 控件本身已被识别,但它的任何属性或方法都无法识别/访问。
在表单/.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 的所有公共成员生成此错误。
有什么建议么?
解决方案
推荐阅读
- java - “找不到适合 jdbc:sqlite 的驱动程序”问题。我究竟做错了什么?
- java - 从通知“应用程序正在后台运行”打开应用程序
- r - 插入行以反映缺失的数据
- xcode - 为什么添加打字稿后XCode编译非常慢?
- flutter - 构建 QuizPage(dirty, state: _QuizPageState#307d6): The getter 'length' was called on null
- r - 执行 bake() 后,它不会在结果中显示所有预测变量和结果
- php - 从 HTML 表单格式化日期时出现 PHP 错误
- c - 使用 echo 写入的文件中行字符串(十六进制)的最后一个字符是什么
- c# - 在 C# 中,默认结构不调用隐式运算符
- html - 如何为 Safari 14 创建网站图标?