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 :
1 2 3 4 5
[SerializableAttribute]
[ComVisibleAttribute(true)]
[TypeConverterAttribute(typeof(FontConverter))]
public ref class Font sealed : public MarshalByRefObject,
ICloneable, ISerializable, IDisposable
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 :
1 2
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. Sorry for not pro coding, I am a beginner in c++ ,I did not take any University or College level of courses, I just self-teach myself from tutorials and internet.
As I mentioned, C++/CLR is a different language than C++. What's on topic here is C++ used for Windows Programming. I meant an altogether different forum where Microsoft's proprietary language is on topic.
There are a few people who frequent this forum that are familiar with C++/CLR, but not nearly as many as are familiar with C++, which is why I suggested a forum where it is on topic. Presumably, then, you'd get a better chance of a cogent response.
I don't think you're including the relevant .DLL correctly. In your solution explorer, right-click on your project and select 'References...'. You should see a page for Framework and References that may be populated with things like System, System.Data, or nothing at all. You should also see a button that says 'Add New Reference...'. Click this button, and on the dialog that emerges, select the .NET tab. Scroll down until you see System.Drawing and add this reference. Now using delcarations like
Thank you booradley60 for the suggestions. The only problem is that when I wanted to add the new reference, it was already added and my namespaces were as you wrote.
I know what the problem is, although I have no idea how to solve it :
When I use a ref class, Font works, like this :
1 2 3 4
public ref class PrintingExample
{
private:
Font^ printFont;
But when I want to use it in my Document_PrintPage, it does not work anymore, example :
1 2 3 4 5 6 7 8 9 10
Font^ printFont; // error, it does not accept it, it says printFont is unidentified
// Calculate the number of lines per page.
linesPerPage = e->MarginBounds.Height / printFont->GetHeight(e->Graphics);
// Iterate over the fil, printing each line.
while (count < linesPerPage && ((line = streamToPrint->ReadLine()) != nullptr)) {
yPos = TopMargin + (count * printFont->GetHeight(e->Graphics));
e->Graphics->DrawString(line, printFont, Brushes::Black, leftMargin, yPos, gcnew StringFormat);
count++;
}