How to use Font as a variable?

2019-01-29 14:08发布

问题:

I would have a quick question : What do I have to include into a visual C++/CLR project to be able to use Font^ ? I have tried to create a ref class, something like this :

[SerializableAttribute]
[ComVisibleAttribute(true)]
[TypeConverterAttribute(typeof(FontConverter))]
public ref class Font sealed : public MarshalByRefObject, 
    ICloneable, ISerializable, IDisposable

(got it from here : http://msdn.microsoft.com/en-us/library/system.drawing.font.aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1 )

I am working on a project were I have to be able to print something, so my coding is really similiar to something like this : http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.print(v=vs.110).aspx?cs-save-lang=1&cs-lang=cpp

I tried to use a namespace for the Font^, something like this :

using namespace System;
using namespace System::IO;
using namespace System::Drawing;
using namespace System::Drawing::Printing;
using namespace System::Windows::Forms;

OR I tried to use a dll. file in order to be able to use a Font^ as a variable (specifically #using <System.Drawing.dll>

But none seemed to work out ... So what I would need is to use Font^ as a variable, something like this :

Font^ printFont = new System.Drawing.Font("Arial", 10);
SolidBrush myBrush = new SolidBrush(Color.Black);

Could anyone suggest a way to allow Font^ to be used, because in my error list it says that Font^ printFont is unidentified.

P.S. I am a beginner in c++, I really do not know how to use the Font^ as a variable

回答1:

I had to have:

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

instead of :

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


标签: c++ fonts clr