我是新的这种类型的c ++ / cli语言,我寻求一些帮助。我开发了一个关于ListBoxes的项目,我得到了一些代码并学习了它的基本步骤。但我实际上是在这个项目中最困难的部分。
项目计算framenumbers并保留它。它只是一个整数,我的代码中有下一个和前一个按钮。当人们点击图像中的某个位置时,gui会获得x和y坐标并将其正确地写入列表框。我想要做的是,当人们按下下一个按钮时,framenumber增加1并清除列表框界面并准备好获取其他x和y坐标。当人们按下前一个按钮时,ListBox应该显示前面的framenumbers x和y坐标。
我的问题是,我可以将此x和y数据保存在某个地方并随意覆盖吗?我应该怎么做才能保留这些数据?任何帮助或想法将不胜感激。
感谢您的帮助。
答案 0 :(得分:0)
我要做的是创建一个类来保存每个帧要保存的数据,并在用户浏览帧时将其粘贴到某种类型的集合中。您可以保留列表或堆栈,以实现检索“之前的”#39;项目,但我可能使用Dictionary。使字典的键为帧编号,并使值为您为每个帧保存的数据类。
也许是这样的:
public ref class FrameData
{
public:
int x;
int y;
public:
FrameData(int x, int y)
{
this->x = x;
this->y = y;
}
};
Dictionary<int, FrameData^>^ savedFrameData = gcnew Dictionary<int, FrameData^>();
// When they click the next or previous button:
// Save the data for the old frame.
savedFrameData->[oldFrameNumber] = gcnew FrameData(currentX, currentY);
// Retrieve the previous data for the new frame, if found.
FrameData^ dataForNewFrame;
if (savedFrameData->TryGetValue(newFrameNumber, dataForNewFrame))
{
currentX = dataForNewFrame->x;
currentY = dataForNewFrame->y;
}
else
{
currentX = 0;
currentY = 0;
}