如何正确声明一个字体变量? [英] How to declare a Font variable properly?
本文介绍了如何正确声明一个字体变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我会有一个快速问题:
任何人都可以告诉我这行是什么问题:
I would have a quick question : Could anyone tell me what is wrong with this line :
Font ^printFont = gcnew System::Drawing::Font("Arial", 10);
我的编译器说标识符'printFont'不明。
我也有命名空间和dll文件包括:
My compiler says "Identifier 'printFont' is unidentified". I also have the namespaces and the dll file included :
#using <System.Drawing.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Drawing::Text;
using namespace System::Drawing::Printing;
PS。对不起不是亲编码,但我没有采取任何大学水平的编程在C ++ / CLR。
PS. Sorry for not pro coding, but I did not take any University level programming in 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();
}
}
推荐答案
你有指令
using namespace System::Drawing;
那么你可以写
Font ^printFont = gcnew Font("Arial", 10);
我想问题是你没有添加引用 System.Drawing
到项目
I think the problem is that you did not add reference to System.Drawing
to the project
这篇关于如何正确声明一个字体变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文