Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Print if checkbox ticked?

Print if checkbox ticked?

Scheduled Pinned Locked Moved C#
graphicssalestutorialquestion
4 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 10627757
    wrote on last edited by
    #1

    I am trying to print a questionnaire which has 6 check-boxes. I am following a tutorial but this tutorial does not have check-boxes. Below prints except for the check-box. The text in the checkbox prints but prints if checked or not. I need some kind of statement to print if checked but cant find any examples of doing so.

    private void metroButton3_Click(object sender, EventArgs e)
    {
    DSprintPreviewDialog.Document = DSprintDocument;
    DSprintPreviewDialog.ShowDialog();
    }

    private void DSprintDocument\_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
        Bitmap bmp = Properties.Resources.dslogo;
        Image newImage = bmp;
       // e.Graphics.DrawImage(newImage, 25,25, newImage.Width, newImage,Height);
        e.Graphics.DrawString("Customer Name: " + metroTextBox2.Text, new Font("Arial", 16, FontStyle.Regular), Brushes.Black, new Point(25, 180));
        e.Graphics.DrawString("Date: " + DateTime.Now, new Font("Arial", 12), Brushes.Black, new Point(25, 100));
        e.Graphics.DrawString("Computer Make: " + metroMakeBox28.Text, new Font("Arial", 14, FontStyle.Regular), Brushes.Black, new Point(25, 250));
        e.Graphics.DrawString("Customer Items: " + metroCheckBox1.Text, new Font("Arial", 14, FontStyle.Regular), Brushes.Black, new Point(25, 320));
    

    I've changed the following but it prints with a True or False

    e.Graphics.DrawString("Customer Items: " + metroCheckBox1.Checked + metroCheckBox1.Text, new Font("Arial", 14, FontStyle.Regular), Brushes.Black, new Point(25, 320));

    L M O 3 Replies Last reply
    0
    • M Member 10627757

      I am trying to print a questionnaire which has 6 check-boxes. I am following a tutorial but this tutorial does not have check-boxes. Below prints except for the check-box. The text in the checkbox prints but prints if checked or not. I need some kind of statement to print if checked but cant find any examples of doing so.

      private void metroButton3_Click(object sender, EventArgs e)
      {
      DSprintPreviewDialog.Document = DSprintDocument;
      DSprintPreviewDialog.ShowDialog();
      }

      private void DSprintDocument\_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
      {
          Bitmap bmp = Properties.Resources.dslogo;
          Image newImage = bmp;
         // e.Graphics.DrawImage(newImage, 25,25, newImage.Width, newImage,Height);
          e.Graphics.DrawString("Customer Name: " + metroTextBox2.Text, new Font("Arial", 16, FontStyle.Regular), Brushes.Black, new Point(25, 180));
          e.Graphics.DrawString("Date: " + DateTime.Now, new Font("Arial", 12), Brushes.Black, new Point(25, 100));
          e.Graphics.DrawString("Computer Make: " + metroMakeBox28.Text, new Font("Arial", 14, FontStyle.Regular), Brushes.Black, new Point(25, 250));
          e.Graphics.DrawString("Customer Items: " + metroCheckBox1.Text, new Font("Arial", 14, FontStyle.Regular), Brushes.Black, new Point(25, 320));
      

      I've changed the following but it prints with a True or False

      e.Graphics.DrawString("Customer Items: " + metroCheckBox1.Checked + metroCheckBox1.Text, new Font("Arial", 14, FontStyle.Regular), Brushes.Black, new Point(25, 320));

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      If you are asking what I think you are asking, this[^] is how you write an if statement in C#.

      1 Reply Last reply
      0
      • M Member 10627757

        I am trying to print a questionnaire which has 6 check-boxes. I am following a tutorial but this tutorial does not have check-boxes. Below prints except for the check-box. The text in the checkbox prints but prints if checked or not. I need some kind of statement to print if checked but cant find any examples of doing so.

        private void metroButton3_Click(object sender, EventArgs e)
        {
        DSprintPreviewDialog.Document = DSprintDocument;
        DSprintPreviewDialog.ShowDialog();
        }

        private void DSprintDocument\_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Bitmap bmp = Properties.Resources.dslogo;
            Image newImage = bmp;
           // e.Graphics.DrawImage(newImage, 25,25, newImage.Width, newImage,Height);
            e.Graphics.DrawString("Customer Name: " + metroTextBox2.Text, new Font("Arial", 16, FontStyle.Regular), Brushes.Black, new Point(25, 180));
            e.Graphics.DrawString("Date: " + DateTime.Now, new Font("Arial", 12), Brushes.Black, new Point(25, 100));
            e.Graphics.DrawString("Computer Make: " + metroMakeBox28.Text, new Font("Arial", 14, FontStyle.Regular), Brushes.Black, new Point(25, 250));
            e.Graphics.DrawString("Customer Items: " + metroCheckBox1.Text, new Font("Arial", 14, FontStyle.Regular), Brushes.Black, new Point(25, 320));
        

        I've changed the following but it prints with a True or False

        e.Graphics.DrawString("Customer Items: " + metroCheckBox1.Checked + metroCheckBox1.Text, new Font("Arial", 14, FontStyle.Regular), Brushes.Black, new Point(25, 320));

        M Offline
        M Offline
        Midi_Mick
        wrote on last edited by
        #3

        The framework has a nice tool to help here[^]. Check out the DrawCheckBox Method[^] overloads.

        Cheers, Mick ------------------------------------------------ It doesn't matter how often or hard you fall on your arse, eventually you'll roll over and land on your feet.

        1 Reply Last reply
        0
        • M Member 10627757

          I am trying to print a questionnaire which has 6 check-boxes. I am following a tutorial but this tutorial does not have check-boxes. Below prints except for the check-box. The text in the checkbox prints but prints if checked or not. I need some kind of statement to print if checked but cant find any examples of doing so.

          private void metroButton3_Click(object sender, EventArgs e)
          {
          DSprintPreviewDialog.Document = DSprintDocument;
          DSprintPreviewDialog.ShowDialog();
          }

          private void DSprintDocument\_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
          {
              Bitmap bmp = Properties.Resources.dslogo;
              Image newImage = bmp;
             // e.Graphics.DrawImage(newImage, 25,25, newImage.Width, newImage,Height);
              e.Graphics.DrawString("Customer Name: " + metroTextBox2.Text, new Font("Arial", 16, FontStyle.Regular), Brushes.Black, new Point(25, 180));
              e.Graphics.DrawString("Date: " + DateTime.Now, new Font("Arial", 12), Brushes.Black, new Point(25, 100));
              e.Graphics.DrawString("Computer Make: " + metroMakeBox28.Text, new Font("Arial", 14, FontStyle.Regular), Brushes.Black, new Point(25, 250));
              e.Graphics.DrawString("Customer Items: " + metroCheckBox1.Text, new Font("Arial", 14, FontStyle.Regular), Brushes.Black, new Point(25, 320));
          

          I've changed the following but it prints with a True or False

          e.Graphics.DrawString("Customer Items: " + metroCheckBox1.Checked + metroCheckBox1.Text, new Font("Arial", 14, FontStyle.Regular), Brushes.Black, new Point(25, 320));

          O Offline
          O Offline
          omeecode
          wrote on last edited by
          #4

          checkbox control checked property will only return either true or false. Also the text property only returned the text associated with the control. One way around that I come up is that: You will have to write an if statement before the e.Graphics.Drawstring.

          if(metroCheckBox.checked)
          {

          e.Graphics.DrawString("Customer Items: " + metroCheckBox1.Text, new Font("Arial", 14, FontStyle.Regular), Brushes.Black, new Point(25, 320));

          }
          else
          {
          // do nothing or Whatever you wanted to do such as print..
          }

          Umair (Software Engineer) (Interested in C#, .Net, Interfacing, Device Drivers, GIS, WCF, Asp.net, Ajax, Architecture and Design Patterns)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups