我有一个简单的问题:
谁能告诉我这行有什么问题:
Font ^printFont = gcnew System::Drawing::Font("Arial", 10);
我的编译器说“标识符‘printFont’无法识别”。
我还包含命名空间和 dll 文件:
#using <System.Drawing.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Drawing::Text;
using namespace System::Drawing::Printing;
附言。抱歉,我不是专业编码,但我没有学过任何大学水平的 C++/CLR 编程。
Edited :
private: System::Void testCorrection_PrintPage_1(System::Object^ sender, System::Drawing::Printing::PrintPageEventArgs^ e) {
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = (float)e->MarginBounds.Left;
float topMargin = (float)e->MarginBounds.Top;
String^ line = nullptr;
Font ^printFont = gcnew System::Drawing::Font("Arial", 10); // error is :" IntelliSense:identifier 'PrintFont' is undefined "
SolidBrush ^myBrush = gcnew SolidBrush(Color::Black);
StreamReader^ streamToPrint;
// Calculate the number of lines per page.
linesPerPage = e->MarginBounds.Height / printFont->GetHeight(e->Graphics);
line = streamToPrint->ReadLine();
// Iterate over the file, printing each line.
while (count < linesPerPage && ((line = streamToPrint->ReadLine()) != nullptr)) {
yPos = topMargin + (count * printFont->GetHeight(e->Graphics));
e->Graphics->DrawString(line, printFont, myBrush, leftMargin, yPos, gcnew StringFormat);
count++;
line = streamToPrint->ReadLine();
}
}
既然你有指令
using namespace System::Drawing;
那么你可以简单地写
Font ^printFont = gcnew Font("Arial", 10);
我认为问题是你没有添加对System.Drawing
到项目
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)