Click here to Skip to main content
15,887,485 members
Home / Discussions / C#
   

C#

 
AnswerRe: error : The left-hand side of an assignment must be a variable, property or indexer Pin
Guffa29-Sep-07 10:42
Guffa29-Sep-07 10:42 
GeneralRe: error : The left-hand side of an assignment must be a variable, property or indexer Pin
Colin Angus Mackay29-Sep-07 10:49
Colin Angus Mackay29-Sep-07 10:49 
GeneralRe: error : The left-hand side of an assignment must be a variable, property or indexer Pin
Christian Graus29-Sep-07 13:21
protectorChristian Graus29-Sep-07 13:21 
GeneralRe: error : The left-hand side of an assignment must be a variable, property or indexer Pin
Colin Angus Mackay29-Sep-07 13:26
Colin Angus Mackay29-Sep-07 13:26 
GeneralRe: error : The left-hand side of an assignment must be a variable, property or indexer Pin
Christian Graus29-Sep-07 13:54
protectorChristian Graus29-Sep-07 13:54 
GeneralRe: error : The left-hand side of an assignment must be a variable, property or indexer Pin
Colin Angus Mackay29-Sep-07 10:47
Colin Angus Mackay29-Sep-07 10:47 
GeneralRe: error : The left-hand side of an assignment must be a variable, property or indexer Pin
Landie1101-Oct-07 2:18
Landie1101-Oct-07 2:18 
QuestionHelp with Prining Pin
MumbleB29-Sep-07 9:39
MumbleB29-Sep-07 9:39 
HI All,

I am trying to put together a print function but I am having some trouble with it. I have looked at numerous code and have tried to put my own together but I getthe following error message, "Object not reference not set to an instance of an object". I think I know where the problem is but do't know how to fix it.

<br />
    public partial class Orders : Form<br />
    {<br />
        <br />
        private PrintDocument printDoc = new PrintDocument();<br />
        private PageSettings pgSettings = new PageSettings();<br />
        private PrinterSettings prtSettings = new PrinterSettings();<br />
        <br />
        <br />
        <br />
        <br />
        <br />
<br />
        public Orders()<br />
        {<br />
            MenuItem fileMenuItem = new MenuItem("&File");<br />
            MenuItem filePageSetupMenuItem = new MenuItem("Page Set&up...", new EventHandler(filePageSetupMenuItem_Click));<br />
            MenuItem filePrintPreviewMenuItem = new MenuItem("Print Pre&view", new EventHandler(filePrintPreviewMenuItem_Click));<br />
            MenuItem filePrintMenuItem = new MenuItem("&Print...", new EventHandler(filePrintMenuItem_Click), Shortcut.CtrlP);<br />
<br />
            fileMenuItem.MenuItems.Add(filePageSetupMenuItem);<br />
            fileMenuItem.MenuItems.Add(filePrintPreviewMenuItem);<br />
            fileMenuItem.MenuItems.Add(filePrintMenuItem);<br />
            this.Menu = new MainMenu();<br />
            this.Menu.MenuItems.Add(fileMenuItem);<br />
            printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage);<br />
            <br />
            InitializeComponent();<br />
        }<br />
<br />
        #region Printing Code<br />
<br />
        private void filePrintMenuItem_Click(Object sender, EventArgs e)<br />
        {<br />
            printDoc.DefaultPageSettings = pgSettings;<br />
            PrintDialog dlg = new PrintDialog();<br />
            dlg.Document = printDoc;<br />
            if (dlg.ShowDialog() == DialogResult.OK)<br />
            {<br />
                printDoc.Print();<br />
            }<br />
        }<br />
        private void filePrintPreviewMenuItem_Click(Object sender, EventArgs e)<br />
        {<br />
            try<br />
            {<br />
                <br />
                PrintPreviewDialog dlg = new PrintPreviewDialog();<br />
                dlg.Document = printDoc;<br />
                dlg.FormBorderStyle = FormBorderStyle.Fixed3D;<br />
                dlg.SetBounds(20, 20, this.Width, this.Height);<br />
                dlg.ShowDialog();<br />
            }<br />
            catch (Exception ex)<br />
            {<br />
                MessageBox.Show(ex.Message.ToString());<br />
            }<br />
             <br />
            <br />
            <br />
        }<br />
        private void filePageSetupMenuItem_Click(Object sender, EventArgs e)<br />
        {<br />
            PageSetupDialog pageSetupDialog = new PageSetupDialog();<br />
            pageSetupDialog.PageSettings = pgSettings;<br />
            pageSetupDialog.PrinterSettings = prtSettings;<br />
            pageSetupDialog.AllowOrientation = true;<br />
            pageSetupDialog.AllowMargins = true;<br />
            pageSetupDialog.ShowDialog();<br />
        }<br />
<br />
        private void printDoc_PrintPage(Object sender, PrintPageEventArgs e)<br />
        {<br />
            /*e.Graphics.Clip = new Region(e.MarginBounds);<br />
            String textToPrint = ".NET Printing is easy";<br />
            Font printFont = new Font("Courier New", 12);<br />
            int leftMargin = e.MarginBounds.Left;<br />
            int topMargin = e.MarginBounds.Top;<br />
            e.Graphics.DrawString(textToPrint, printFont, Brushes.Black, leftMargin, topMargin);<br />
            */<br />
            DrawAll(e.Graphics);<br />
            <br />
        }<br />

Problem is in here.

private void DrawAll(Graphics g)<br />
        {<br />
            RectangleF srcRect = new Rectangle(0, 0, this.BackgroundImage.Width, BackgroundImage.Height);<br />
<br />

Then the rest of the code

<br />
            int nWidth = printDoc.PrinterSettings.DefaultPageSettings.PaperSize.Width;<br />
            int nHeight = printDoc.PrinterSettings.DefaultPageSettings.PaperSize.Height;<br />
            RectangleF desct = new Rectangle(0, 0, nWidth, nHeight / 2);<br />
<br />
            g.DrawImage(this.BackgroundImage, desct, srcRect, GraphicsUnit.Pixel);<br />
<br />
            float scalex = desct.Width / srcRect.Width;<br />
            float scaley = desct.Height / srcRect.Height;<br />
<br />
            Pen aPen = new Pen(Brushes.Black, 1);<br />
<br />
            for (int i = 0; i < this.Controls.Count; i++)<br />
            {<br />
                if (Controls[i].GetType() == this.t1TextBox.GetType())<br />
                {<br />
                    TextBox theText = (TextBox)Controls[i];<br />
                    g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left * scalex, theText.Bounds.Top * scaley, new StringFormat());<br />
                }<br />
                if (Controls[i].GetType() == this.groupBox1.GetType())<br />
                {<br />
                    GroupBox theGroup = (GroupBox)Controls[i];<br />
                    Rectangle aRect = theGroup.Bounds;<br />
                    g.DrawRectangle(aPen, aRect.Left * scalex, aRect.Top * scaley, aRect.Width * scalex, aRect.Height * scaley);<br />
                }<br />
                if (Controls[i].GetType() == this.orderDateDateTimePicker.GetType())<br />
                {<br />
                    DateTimePicker aPicker = (DateTimePicker)Controls[i];<br />
                    g.DrawString(aPicker.Text, aPicker.Font, Brushes.Black, aPicker.Bounds.Left * scalex, aPicker.Bounds.Top * scaley, new StringFormat());<br />
                }<br />
                if (Controls[i].GetType() == this.comboBox1.GetType())<br />
                {<br />
                    ComboBox theCombo = (ComboBox)Controls[i];<br />
                    Rectangle cRect = theCombo.Bounds;<br />
                    g.DrawRectangle(aPen, cRect.Left * scalex, cRect.Top * scaley, cRect.Width * scalex, cRect.Height * scaley);<br />
                }<br />
                <br />
            }<br />
        }<br />

AnswerRe: Help with Prining Pin
Lutosław29-Sep-07 10:51
Lutosław29-Sep-07 10:51 
GeneralRe: Help with Prining Pin
MumbleB29-Sep-07 11:44
MumbleB29-Sep-07 11:44 
GeneralRe: Help with Prining Pin
Lutosław29-Sep-07 12:21
Lutosław29-Sep-07 12:21 
GeneralRe: Help with Prining Pin
Paul Conrad29-Sep-07 13:09
professionalPaul Conrad29-Sep-07 13:09 
GeneralRe: Help with Prining Pin
MumbleB30-Sep-07 3:41
MumbleB30-Sep-07 3:41 
GeneralRe: Help with Prining Pin
Lutosław30-Sep-07 5:33
Lutosław30-Sep-07 5:33 
GeneralRe: Help with Prining Pin
MumbleB30-Sep-07 10:57
MumbleB30-Sep-07 10:57 
Questionbarcode Pin
k36madman29-Sep-07 8:12
k36madman29-Sep-07 8:12 
AnswerRe: barcode Pin
martin_hughes29-Sep-07 10:15
martin_hughes29-Sep-07 10:15 
GeneralRe: barcode Pin
k36madman29-Sep-07 12:02
k36madman29-Sep-07 12:02 
GeneralRe: barcode Pin
martin_hughes29-Sep-07 12:31
martin_hughes29-Sep-07 12:31 
GeneralRe: barcode Pin
k36madman29-Sep-07 14:39
k36madman29-Sep-07 14:39 
GeneralRe: barcode Pin
GuyThiebaut30-Sep-07 8:25
professionalGuyThiebaut30-Sep-07 8:25 
GeneralRe: barcode Pin
k36madman30-Sep-07 10:43
k36madman30-Sep-07 10:43 
QuestionRadio Buttons Pin
picasso229-Sep-07 7:52
picasso229-Sep-07 7:52 
AnswerRe: Radio Buttons Pin
Lutosław29-Sep-07 8:59
Lutosław29-Sep-07 8:59 
QuestionObject reference not set to an instance of an object. Pin
anydie29-Sep-07 7:20
anydie29-Sep-07 7:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.