Click here to Skip to main content
13,664,632 members
Click here to Skip to main content
Articles » Multimedia » GDI+ » General » Downloads

Stats

28.4K views
1.3K downloads
39 bookmarked
Posted 29 Dec 2012
Licenced CPOL

WPF-Less GDI+.NET Report Component: Star Report

, 25 Jan 2013
StarReport: WPF-less GDI+.NET report component.
UniverseReportDemo
UniverseReport_WithoutPrinter_Project
UniverseReport
mac_button.png
mac_checkbox.png
mac_radiobutton.png
Plex_button.png
Plex_checkbox.png
Plex_radiobutton.png
Properties
Resources
Report1.bmp
StarReport.png
Thumbs.db
UniverseReport.csproj.user
UniverseReport.suo
UpgradeLog.XML
xp1_button.png
xp1_checkbox.png
xp1_radiobutton.png
UniverseReportDemo.suo
UniverseReportDemo
bin
Debug
Properties
mac_button.png
mac_checkbox.png
mac_radiobutton.png
Plex_button.png
Plex_checkbox.png
Plex_radiobutton.png
Report1.bmp
StarReport.png
Thumbs.db
UniverseReport.csproj.user
UniverseReport.suo
UpgradeLog.XML
xp1_button.png
xp1_checkbox.png
xp1_radiobutton.png
UniverseReportDemo.suo
UniverseReport.dll
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace UniverseReport
{
    /// <summary>
    /// A FrontPage style table dimensions picker.
    /// </summary>
    public partial class TablePicker : System.Windows.Forms.Form
    {
     

        public TablePicker()
        {
            // Activates double buffering
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.DoubleBuffer, true);

            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
        }

        ///// <summary>
        ///// Clean up any resources being used.
        ///// </summary>
        //protected override void Dispose(bool disposing)
        //{
        //    if (disposing)
        //    {
        //        if (components != null)
        //        {
        //            components.Dispose();
        //        }
        //    }
        //    base.Dispose(disposing);
        //}

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
      
        #endregion

        private Pen BeigePen = new Pen(Color.Beige, 1);
        private Brush BeigeBrush = System.Drawing.Brushes.Beige;
        private Brush GrayBrush = System.Drawing.Brushes.Gray;
        private Brush BlackBrush = System.Drawing.Brushes.Black;
        private Brush WhiteBrush = System.Drawing.Brushes.White;
        private Pen BorderPen = new Pen(SystemColors.ControlDark);
        private Pen BluePen = new Pen(Color.SlateGray, 1);

        private string DispText = "Cancel";	// Display text
        private int DispHeight = 20;		// Display ("Table 1x1", "Cancel")
        private Font DispFont = new Font("Tahoma", 8.25F);
        private int SquareX = 20;			// Width of squares 
        private int SquareY = 20;			// Height of squares
        private int SquareQX = 3;			// Number of visible squares (X)
        private int SquareQY = 3;			// Number of visible squares (Y)
        private int SelQX = 1;				// Number of selected squares (x)
        private int SelQY = 1;				// Number of selected squares (y)

        private bool bHiding = false;
        private bool bCancel = true;	// Determines whether to Cancel

        /// <summary>
        /// Similar to <code><see cref="DialogResult"/> 
        /// == <see cref="DialogResult.Cancel"/></code>,
        /// but is used as a state value before the form
        /// is hidden and cancellation is finalized.
        /// </summary>
        public bool Cancel
        {
            get
            {
                return bCancel;
            }
        }

        /// <summary>
        /// Returns the number of columns, or the horizontal / X count,
        /// of the selection.
        /// </summary>
        public int SelectedColumns
        {
            get
            {
                return SelQX;
            }
        }

        /// <summary>
        /// Returns the number of rows, or the vertical / Y count, 
        /// of the selection.
        /// </summary>
        public int SelectedRows
        {
            get
            {
                return SelQY;
            }
        }

        private void TablePicker_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            // First, increment the number of visible squares if the 
            // number of selected squares is equal to or greater than the
            // number of visible squares.
            if (SelQX > SquareQX - 1) SquareQX = SelQX + 1;
            if (SelQY > SquareQY - 1) SquareQY = SelQY + 1;

            // Second, expand the dimensions of this form according to the 
            // number of visible squares.
            this.Width = (SquareX * (SquareQX)) + 5;
            this.Height = (SquareY * (SquareQY)) + 6 + DispHeight;

            // Draw an outer rectangle for the border.
            g.DrawRectangle(BorderPen, 0, 0, this.Width - 1, this.Height - 1);

            // Draw the text to describe the selection. Note that since
            // the text is left-justified, only the Y (vertical) position
            // is calculated.
            int dispY = ((SquareY - 1) * SquareQY) + SquareQY + 4;
            if (this.Cancel)
            {
                DispText = "Cancel";
            }
            else
            {
                DispText = SelQX.ToString() + " by " + SelQY.ToString() + " Table";
            }
            g.DrawString(DispText, DispFont, BlackBrush, 3, dispY + 2);

            // Draw each of the squares and fill with the default color.
            for (int x = 0; x < SquareQX; x++)
            {
                for (int y = 0; y < SquareQY; y++)
                {
                    g.FillRectangle(WhiteBrush, (x * SquareX) + 3, (y * SquareY) + 3, SquareX - 2, SquareY - 2);
                    g.DrawRectangle(BorderPen, (x * SquareX) + 3, (y * SquareY) + 3, SquareX - 2, SquareY - 2);
                }
            }

            // Go back and paint the squares with selection colors.
            for (int x = 0; x < SelQX; x++)
            {
                for (int y = 0; y < SelQY; y++)
                {
                    g.FillRectangle(BeigeBrush, (x * SquareX) + 3, (y * SquareY) + 3, SquareX - 2, SquareY - 2);
                    g.DrawRectangle(BluePen, (x * SquareX) + 3, (y * SquareY) + 3, SquareX - 2, SquareY - 2);
                }
            }
        }

        /// <summary>
        /// Detect termination. Hides form.
        /// </summary>
        private void TablePicker_Deactivate(object sender, System.EventArgs e)
        {

            // bCancel = true 
            // and DialogResult = DialogResult.Cancel 
            // were previously already set in MouseLeave.

            this.Hide();
        }

        /// <summary>
        /// Detects mouse movement. Tracks table dimensions selection.
        /// </summary>
        private void TablePicker_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            int sqx = (e.X / SquareX) + 1;
            int sqy = (e.Y / SquareY) + 1;
            bool changed = false;
            if (sqx != SelQX)
            {
                changed = true;
                SelQX = sqx;
            }
            if (sqy != SelQY)
            {
                changed = true;
                SelQY = sqy;
            }

            // Ask Windows to call the Paint event again.
            if (changed) Invalidate();
        }

        /// <summary>
        /// Detects mouse sudden exit from the form to indicate 
        /// escaped (canceling) state.
        /// </summary>
        private void TablePicker_MouseLeave(object sender, System.EventArgs e)
        {
            if (!bHiding) bCancel = true;
            this.DialogResult = DialogResult.Cancel;
            this.Invalidate();
        }

        /// <summary>
        /// Cancels the prior cancellation caused by MouseLeave.
        /// </summary>
        private void TablePicker_MouseEnter(object sender, System.EventArgs e)
        {
            bHiding = false;
            bCancel = false;
            this.DialogResult = DialogResult.OK;
            this.Invalidate();
        }

        /// <summary>
        /// Detects that the user made a selection by clicking.
        /// </summary>
        private void TablePicker_Click(object sender, System.EventArgs e)
        {
            bHiding = true; // Not the same as Visible == false
            // because bHiding suggests that the control
            // is still "active" (not canceled).
            this.Hide();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

FatCatProgrammer
Software Developer (Senior) Finance Industry
United States United States
Currently pursuing 'Programming Nirvana' (The ineffable ultimate in which one has attained disinterested wisdom and compassion as it relates to programming)

Respected Technologies
1. Confusor (https://confuser.codeplex.com/)
2. Power Threading (http://www.wintellect.com/Resources/visit-the-power-threading-library)
3. EDI Parsers (http://www.rdpcrystal.com)


Acknowledgements:

Microsoft Certified Technologist for WPF and .Net 3.5 (MCTS)
Microsoft Certified Technologist for WCF and .Net 3.5 (MCTS)
Microsoft Certified Application Developer for .Net (MCAD)
Microsoft Certified Systems Engineer (MCSE)
Microsoft Certified Professional (MCP)

Sun Certified Developer for Java 2 Platform (SCD)
Sun Certified Programmer for Java 2 Platform (SCP)
Sun Certified Web Component Developer (SCWCD)

CompTIA A+ Certified Professional

Registered Business School Teacher for Computer Programming and Computer Applications (2004)
(University of the State of New York Education Department)

Graduated from University At Stony Brook

You may also be interested in...

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180810.1 | Last Updated 25 Jan 2013
Article Copyright 2012 by FatCatProgrammer
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid