您能否获得指向 System::Object^ 内的 {System.Array} 的指针?
好的,我有这个程序,它接受用户拖放到标签框中的文件。该程序当前能够接受删除的文件。然后我将文件保存到 System::Object^ 中。 System::Object^ 内部是一个 {System.Array},它保存拖放到标签框中的文件的路径。
我需要能够访问 System::Object^ 内的 {System.Array} 中的文件路径。我正在将用 Visual Basic 编写的另一个程序转换为 C++;所以我试图让两个程序的代码彼此非常接近。我稍微研究了一下 OLE 的拖放功能,我认为我应该能够按照我在这段代码中开始的方式执行拖放操作。我觉得 OLE 对于我的需要来说太多了,我只需要文件的文件路径。关于如何获取文件路径有什么想法吗?
private: System::Void lblDragHere_DragEnter(System::Object^ sender, System::Windows::Forms::DragEventArgs^ e)
{
if (e->Data->GetDataPresent(System::Windows::Forms::DataFormats::FileDrop))
e->Effect = System::Windows::Forms::DragDropEffects::All;
else
e->Effect = System::Windows::Forms::DragDropEffects::None;
lblError->Visible = false;
blnSaveSuccessful = false;
}
private: System::Void lblDragHere_DragDrop(System::Object^ sender, System::Windows::Forms::DragEventArgs^ e)
{
bool blnContinue = false;
// Checks if the user has not set a save location for the files.
if (lblSaveLocation->Text == "Current Save Location")
{
lblError->ForeColor = Color::Red;
lblError->Text = "Please select a save location first.";
lblError->Visible = true;
}
else
{
lblError->Visible = false;
// Checks to see if the user actually dropped anything onto lblDragHere
if (e->Data->GetDataPresent(DataFormats::FileDrop))
{
System::Object ^ MyFiles;
// Assign the files to the array.
MyFiles = e->Data->GetData(DataFormats::FileDrop);
}
}
}
Ok so I have this program that accepts files the user drags and drops onto a label box. The program is currently able to accept files that are dropped. I then save the files into a System::Object^. Inside the System::Object^ is a {System.Array} that holds the path of the files dropped onto the label box.
I need to be able to access the file paths in the {System.Array} inside of the System::Object^. I am converting another program that I wrote in Visual Basic to C++; so I'm trying to keep the code of both programs pretty close to each other. I have looked at OLE for drag and drop a little bit and I'm thinking that I should be able to perform drag and drop the way I started in this code. I feel OLE is too much for what I need, I just need the file paths for the files. Any ideas on how I can get the file paths?
private: System::Void lblDragHere_DragEnter(System::Object^ sender, System::Windows::Forms::DragEventArgs^ e)
{
if (e->Data->GetDataPresent(System::Windows::Forms::DataFormats::FileDrop))
e->Effect = System::Windows::Forms::DragDropEffects::All;
else
e->Effect = System::Windows::Forms::DragDropEffects::None;
lblError->Visible = false;
blnSaveSuccessful = false;
}
private: System::Void lblDragHere_DragDrop(System::Object^ sender, System::Windows::Forms::DragEventArgs^ e)
{
bool blnContinue = false;
// Checks if the user has not set a save location for the files.
if (lblSaveLocation->Text == "Current Save Location")
{
lblError->ForeColor = Color::Red;
lblError->Text = "Please select a save location first.";
lblError->Visible = true;
}
else
{
lblError->Visible = false;
// Checks to see if the user actually dropped anything onto lblDragHere
if (e->Data->GetDataPresent(DataFormats::FileDrop))
{
System::Object ^ MyFiles;
// Assign the files to the array.
MyFiles = e->Data->GetData(DataFormats::FileDrop);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够通过强制转换直接以 cli 文件名数组形式获取数据:(
您应该使用
void
而不是 System::Void,它更具可读性)You should be able to directly get the data as a cli array of file names with a cast:
(You should use
void
instead of System::Void, it's more readable)