As you have directive
using namespace System::Drawing;
then you can write simply
Font ^printFont = gcnew Font("Arial", 10);
I think the problem is that you did not add reference to System.Drawing
to the project
Frage
I would have a quick question : Could anyone tell me what is wrong with this line :
Font ^printFont = gcnew System::Drawing::Font("Arial", 10);
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. Sorry for not pro coding, but I did not take any University level programming in 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();
}
}
Lösung
As you have directive
using namespace System::Drawing;
then you can write simply
Font ^printFont = gcnew Font("Arial", 10);
I think the problem is that you did not add reference to System.Drawing
to the project