本人只学习过C语言,对.NET几乎小白。自己看了些资料做了个软件,是毕业设计!现在需要在两个窗口间传递数据,查看了好多资料看的我云里雾里,没办法,实在是不懂!
希望从Form1中将数组传递到Form2中去,我把(自己认为的)一些没必要的代码我就删去了,免得大家看的麻烦!
就是将Form1最下面申请的buf内存地址传递给Form2中最下面的 huidu数组,只要告诉我怎么写代码就可以了,顺便说出方法就更好了,谢谢!
对了,Form1和Form2不是MDI父子关系,因为设成MDI父子关系,Form1中的pictureBox就把Form2挡住了!
PS:我是小白,如果下面删掉了某些需要知道的代码,跟我说,我再贴上,灰常感谢!
Form1代码如下:
//Form1.h
#pragma once
#include <math.h>
#include "Form2.h"
namespace picture {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Form1 摘要
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: 在此处添加构造函数代码
//
}
protected:
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
protected:
中间代码省略!
中间代码省略!
中间代码省略!
private: System::Void 灰度直方图ToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
int *buf = new int[256]; //申请内存
for(i=0; i<256; i++)
buf[i]=0;
Form2^ form2 = gcnew Form2();
form2 -> ShowDialog(); //显示Form2
}
};
}
Form2代码如下:
//Form2.h
#pragma once
namespace picture {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Drawing::Drawing2D;
/// <summary>
/// Form2 摘要
/// </summary>
public ref class Form2 : public System::Windows::Forms::Form
{
public:
Form2(void)
{
InitializeComponent();
//
//TODO: 在此处添加构造函数代码
//
}
protected:
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
~Form2()
{
if (components)
{
delete components;
}
}
private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
System::ComponentModel::Container ^components;
中间代码省略!
中间代码省略!
中间代码省略!
private: System::Void Form2_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
array<int>^ huidu = gcnew array<int> (256){ 0 };
/**** 此处将Form1最下面申请的buf内存给huidu数组****/
DrawHuidu(e->Graphics, huidu); // 绘制灰度分布图
}
};
}
PS:我是小白,如果下面删掉了某些需要知道的代码,跟我说,我再贴上,灰常感谢!
不知道你们需不需要解决方案资源管理器,现在把图贴上,如下:
发帖时的被邀请人是系统推荐的,所以不要怪我邀请了你们,如有打扰多多见谅,谢谢。。。。