1
Answer

I cant see where I am going wrong ?

Haider Kubba

Haider Kubba

16y
2k
1
Hi guys this is my first post on here now I dont want the answer I just want a hint as to where I am going wrong

my code is:

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;

namespace PrintMyName
{
    class GetName
    {
        private string Surname;                                                    

        public void whatsthename()
        {
            Console.Write("Please Enter your name: ");
            surname = (Console.ReadLine());
        }
                                                                                   
        public string surname       
        {
            set
            {
                Surname = value;
            }
            get
            {
                return Surname;
            }
        }
    }

        public delegate void Printingname();

        public class nameprinting
        {
            public void FireMyFire() //the firing method
            {
                GetName gn = new GetName();
                gn.whatsthename();
            }

            public void MyPrintMethod(object sender, PrintPageEventArgs args)
            {
                GetName gn = new GetName();
                nameprinting np = new nameprinting();
                Graphics gr = args.Graphics;
                String drawString = gn.surname;
                Font drawFont = new Font("Arial", 16);
                SolidBrush drawBrush = new SolidBrush(Color.Black);
                PointF drawPoint = new PointF(500.0F, 500.0F);
                gr.DrawString(drawString, drawFont, drawBrush, drawPoint);
            }


        }

        class MainClass
        {
            public static void Main(string[] args)
            {
                //GetName gn = new GetName();
                nameprinting np = new nameprinting();
                MainClass mc = new MainClass();
                PrintDocument pd = new PrintDocument();
                np.FireMyFire();
                pd.PrintPage += new PrintPageEventHandler(np.MyPrintMethod);
                pd.Print();
                Console.ReadLine();
            }
        }
    }

I take a name and then print it on a page but I am getting a null value when I go to the MyPrintMethod method I just dont know why?????

ps. I have only been using C# for like 3 months so take it easy on me.

thanks.
Answers (1)