c ++如何动态添加标签到组框并设置其位置
c++ How to add dinamically a label to a groupbox and set its postion
大家好,我希望用户选择一个文件列表(txt 文件),我想在组框中显示这些文件的路径,我可以在 c# 中完美地做到这一点,但我在使用 c++ 时遇到了一些问题\客户端
p.s 我在 visual studio 2017 社区工作
这是我的代码:
openFileDialog1 = gcnew System::Windows::Forms::OpenFileDialog();
openFileDialog1->InitialDirectory = DefaultProgramPath;
openFileDialog1->FileName = "";
openFileDialog1->Filter = "ESA Files (*.esa)|*.esa|txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1->FilterIndex = 1;
openFileDialog1->RestoreDirectory = true;
if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
String^ toBeAdded= openFileDialog1->FileName;
Label^job = gcnew Label();
job->Text = toBeAdded;
job->Location.X = 150;
job->Location.Y = 250;
groupBox1->Controls->Add(job);
}
使用此代码,标签被添加到组框中但我无法在其中正确设置其位置
感谢您的帮助
System.Drawing.Point
is a value type (struct
in C#, value class
/value struct
in C++/CLI), therefore the property Location
正在返回其当前位置的 copy。为了更新它,您需要一次设置整个值类型。
Point newLocation;
newLocation.X = 150;
newLocation.Y = 250;
job->Location = newLocation;
大家好,我希望用户选择一个文件列表(txt 文件),我想在组框中显示这些文件的路径,我可以在 c# 中完美地做到这一点,但我在使用 c++ 时遇到了一些问题\客户端 p.s 我在 visual studio 2017 社区工作
这是我的代码:
openFileDialog1 = gcnew System::Windows::Forms::OpenFileDialog();
openFileDialog1->InitialDirectory = DefaultProgramPath;
openFileDialog1->FileName = "";
openFileDialog1->Filter = "ESA Files (*.esa)|*.esa|txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1->FilterIndex = 1;
openFileDialog1->RestoreDirectory = true;
if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
String^ toBeAdded= openFileDialog1->FileName;
Label^job = gcnew Label();
job->Text = toBeAdded;
job->Location.X = 150;
job->Location.Y = 250;
groupBox1->Controls->Add(job);
}
使用此代码,标签被添加到组框中但我无法在其中正确设置其位置
感谢您的帮助
System.Drawing.Point
is a value type (struct
in C#, value class
/value struct
in C++/CLI), therefore the property Location
正在返回其当前位置的 copy。为了更新它,您需要一次设置整个值类型。
Point newLocation;
newLocation.X = 150;
newLocation.Y = 250;
job->Location = newLocation;