如何正确声明Font变量?

时间:2014-04-23 02:59:28

标签: fonts c++-cli

我会有一个简单的问题: 谁能告诉我这一行有什么问题:

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;

PS。很抱歉没有专业编码,但我没有参加C ++ / CLR中的任何大学水平编程。

编辑:

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();
}
}

1 个答案:

答案 0 :(得分:1)

你有指令

using namespace System::Drawing;

然后你可以写简单

Font ^printFont = gcnew Font("Arial", 10);

我认为问题在于您没有将System.Drawing的引用添加到项目