如何将参数从一个类传递到另一个类 [英] How to pass a parameter from one class to another
问题描述
我希望从按下一个按钮到主按钮时从窗口获取一个值(1或0)但在运行时说"参数无效"时会出现错误。我不确定我做错了什么,除了显而易见的是我实现参数的方式有一些
错误。
< pre class ="prettyprint">使用System;
使用System.Windows.Forms;
//使用System.Drawing.Imaging成像
;使用System.Drawing
;
命名空间DataCollection
{
public partial class SortpBoundaryImages:Form
{
public int tempFlag = 0;
public int TmpFlag
{
get
{
return tempFlag;
}
设置
{
tempFlag = value;
}
}
public SortpBoundaryImages()
{
InitializeComponent();
//将图像加载到表格中
位图bmp =新位图(@"C:\ ELEC Project \ temp.bmp");
pictureBox1.Image = bmp;
bmp.Dispose();
}
//公共类ResultFromFrmMain
// {
// public DialogResult Result {get;组; }
// public int Getvalue {get;组; }
//}
private void button1_Click(object sender,EventArgs e)
{
//如果用户将图像分类为重要点,则存储它在PboundaryIntrest文件夹中
int fileNum = Data.ImageCount.ImageSum(" PboundaryIntrest");
位图bmp =新位图(@"C:\ ELEC Project \ temp.bmp");
bmp.Save(@" C:\ ELEC Project \ PboundaryIntrest\" + fileNum +" .bmp");
bmp.Dispose();
关闭();
}
private void pictureBox1_Click(object sender,EventArgs e)
{
}
private void pointOther_Click(object sender,EventArgs e)
{
//如果用户将点分类为不重要,则将其存储为普通P边界
var tFalg = new SortpBoundaryImages();
tFalg.tempFlag = 1;
关闭();
}
}
class DataCollection
{
public static void main()
{
//添加临时图像获取者
var Psort = new SortpBoundaryImages();
Psort.Show();
var Tflag = Psort.tempFlag;
string gt =" \ nboolvaluer is" + Tflag;
Application.ShowAlertDialog(gt);
}
}
}
至少尝试这些变化:
private void pointOther_Click(object sender,EventArgs e)
{
TmpFlag = 1;
关闭();
}
。 。 。
Psort.ShowDialog();
var Tflag = Psort.TmpFlag;
I want to get a value (1 or 0) from windows from when a button in pressed back into main but it comes up with an error when run saying "parameter is not valid". I am not sure what I am doing wrong apart from the obvious that there is something wrong with how I am implementing the parameter.
using System;
using System.Windows.Forms;
//Imaging
using System.Drawing.Imaging;
using System.Drawing;
namespace DataCollection
{
public partial class SortpBoundaryImages : Form
{
public int tempFlag = 0;
public int TmpFlag
{
get
{
return tempFlag;
}
set
{
tempFlag = value;
}
}
public SortpBoundaryImages()
{
InitializeComponent();
//Load up the image into the form
Bitmap bmp = new Bitmap(@"C:\ELEC Project\temp.bmp");
pictureBox1.Image = bmp;
bmp.Dispose();
}
//public class ResultFromFrmMain
//{
// public DialogResult Result { get; set; }
// public int Getvalue { get; set; }
//}
private void button1_Click(object sender, EventArgs e)
{
//If the users classifies the image as an impotant point then store it in the PboundaryIntrest folder
int fileNum = Data.ImageCount.ImageSum("PboundaryIntrest");
Bitmap bmp = new Bitmap(@"C:\ELEC Project\temp.bmp");
bmp.Save(@"C:\ELEC Project\PboundaryIntrest\"+ fileNum +".bmp");
bmp.Dispose();
Close();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void pointOther_Click(object sender, EventArgs e)
{
//If the user classifies the point as not important then store it as a normal P boundary
var tFalg = new SortpBoundaryImages();
tFalg.tempFlag = 1;
Close();
}
}
class DataCollection
{
public static void main()
{
//add in temp image taker
var Psort = new SortpBoundaryImages();
Psort.Show();
var Tflag = Psort.tempFlag;
string gt = "\nboolvaluer is " + Tflag;
Application.ShowAlertDialog(gt);
}
}
}
Try at least these changes:
private void pointOther_Click(object sender, EventArgs e)
{
TmpFlag = 1;
Close();
}
. . .
Psort.ShowDialog();
var Tflag = Psort.TmpFlag;
这篇关于如何将参数从一个类传递到另一个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!