static void Main()
        {
            Microsoft.Glee.Drawing.Graph graph = new
                                                 Microsoft.Glee.Drawing.Graph("");
            graph.AddEdge("A", "B");
            graph.AddEdge("A", "B");
            graph.FindNode("A").Attr.Fillcolor =
                Microsoft.Glee.Drawing.Color.Red;
            graph.FindNode("B").Attr.Fillcolor =
                Microsoft.Glee.Drawing.Color.Blue;
            Microsoft.Glee.GraphViewerGdi.GraphRenderer renderer
                = new Microsoft.Glee.GraphViewerGdi.GraphRenderer
                      (graph);
            renderer.CalculateLayout();
            int    width  = 500;
            Bitmap bitmap = new Bitmap(width, (int)(graph.Height *
                                                    (width / graph.Width)), PixelFormat.Format32bppPArgb);

            renderer.Render(bitmap);
            bitmap.Save("test1.png");

            //        //create a form
            //        System.Windows.Forms.Form form = new
            //System.Windows.Forms.Form();
            //        //create a viewer object
            //        Microsoft.Glee.GraphViewerGdi.GViewer viewer
            //= new Microsoft.Glee.GraphViewerGdi.GViewer();
            //        //create a graph object
            //        Microsoft.Glee.Drawing.Graph graph = new
            //Microsoft.Glee.Drawing.Graph("graph");
            //        //create the graph content
            //        graph.AddEdge("A", "B");
            //        graph.AddEdge("B", "C");
            //        graph.AddEdge("A", "C").EdgeAttr.Color =
            //Microsoft.Glee.Drawing.Color.Green;
            //        graph.FindNode("A").Attr.Fillcolor =
            //Microsoft.Glee.Drawing.Color.Magenta;
            //        graph.FindNode("B").Attr.Fillcolor =
            //Microsoft.Glee.Drawing.Color.MistyRose;
            //        Microsoft.Glee.Drawing.Node c =
            //graph.FindNode("C");
            //        c.Attr.Fillcolor =
            //Microsoft.Glee.Drawing.Color.PaleGreen;
            //        c.Attr.Shape =
            //Microsoft.Glee.Drawing.Shape.Diamond;
            //        //bind the graph to the viewer viewer.Graph = graph;
            //        //associate the viewer with the form
            //        form.SuspendLayout();
            //        viewer.Dock =
            //System.Windows.Forms.DockStyle.Fill;
            //        form.Controls.Add(viewer);
            //        form.ResumeLayout();
            //        ///show the form
            //        ///
            //form.ShowDialog();

            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());
        }
Exemple #2
0
        private bool find_critical_path(int index)
        {
            int i;

            if (index != 0 && net_work[index].flag == 1)
            {
                return(true);
            }
            node cur_node = net_work[index];

            if (cur_node.early_start != cur_node.last_start)
            {
                return(false);
            }
            for (i = 0; i < cur_node.len_after; i++)
            {
                if (find_critical_path(cur_node.after_num[i]))
                {
                    Console.WriteLine("->({0},{1})", cur_node.value, index);
                    richTextBox1.AppendText(cur_node.value.ToString() + "    " + index.ToString() + "  ///   ");
                    /////////////////////////////////////////////////////////////////////
                    /////////////////////////////////////////////////////////////////////
                    //richTextBox1.Text += "("+cur_node.value.ToString() +"   "+ index.ToString()+")";
                    //richTextBox1.Text += index.ToString() + "     ";
                    if (index == 0)
                    {
                        graph.FindNode("start").Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Red;
                    }
                    if (index == 0)
                    {
                        graph.FindNode("start").Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Red;
                        graph.FindNode("end").Attr.Fillcolor   = Microsoft.Glee.Drawing.Color.Red;
                        break;
                    }

                    graph.FindNode(ods.Tables[0].Rows[index - 1][0].ToString()).Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Red;



                    /////////////////////////////////////////////////////////////////////
                    /////////////////////////////////////////////////////////////////////

                    return(true);
                }
            }
            return(false);
        }
Exemple #3
0
    public void GambarPeta()
    //Method menggabarkan peta penyebaran atribut graf pada form baru
    {
        System.Windows.Forms.Form             peta = new System.Windows.Forms.Form();
        Microsoft.Glee.GraphViewerGdi.GViewer view = new Microsoft.Glee.GraphViewerGdi.GViewer();
        Microsoft.Glee.Drawing.Graph          map  = new Microsoft.Glee.Drawing.Graph("Peta Penyebaran Virus");

        Dictionary <string, Graph> .KeyCollection keys = this.graf.Keys;
        foreach (string node1 in keys)
        {
            if (graf[node1].GetNEdge() == 0)
            {
                map.AddNode(node1);
            }
            else
            {
                foreach (string node2 in graf[node1].GetEdge())
                {
                    map.AddEdge(node1, node2);
                }
                if (graf[node1].GetDayInf() != -1)
                {
                    Microsoft.Glee.Drawing.Node temp = map.FindNode(node1);
                    temp.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Red;
                }
            }
        }

        //bind the graph to the viewer
        view.Graph = map;

        //associate the viewer with the form
        peta.SuspendLayout();
        view.Dock = System.Windows.Forms.DockStyle.Fill;
        peta.Controls.Add(view);
        peta.ResumeLayout();
        peta.Text          = "Peta Penyebaran Virus";
        peta.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

        //show the form
        peta.ShowDialog();
    }
Exemple #4
0
        public FormGanttChart()
        {
            InitializeComponent();

            /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
            *                          GANTT CHART                                      *
            * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
            chart.ChartAreas[0].AxisY.IntervalType = DateTimeIntervalType.Days;
            //chart.ChartAreas[0].AxisY.Interval = 1;

            // Get each task start date and finish date
            HashSet <Node> Nodes        = Program.formMain.GetNodes();
            int            maxEmployees = 0;
            // While there are uncomlited tasks
            DateTime currentDate = Program.formMain.dateTimePicker.Value;

            for (; Nodes.Any(new Func <Node, bool>(delegate(Node node) { return(node.Days > 0); })); currentDate = currentDate.AddDays(1))
            {
                // Start unstarted tasks that have all dependencies complited
                foreach (Node node in Nodes)
                {
                    if (!node.HasStarted && node.Dependencies.All(new Func <Node, bool>(delegate(Node dependency) { return(dependency.Days == 0); })))
                    {
                        node.HasStarted = true;
                        node.StartDate  = currentDate;
                    }
                }

                // Decrese days of uncomplited started tasks and finish them if current day was last
                if (Program.formMain.checkboxes[(int)currentDate.DayOfWeek].Checked)
                {
                    // Count of employees required at current day
                    int employ = 0;
                    foreach (Node node in Nodes)
                    {
                        if (node.HasStarted && node.Days > 0)
                        {
                            employ++;
                            if (--node.Days == 0)
                            {
                                node.FinishDate = currentDate;
                            }
                        }
                    }
                    // Check for loops
                    if (employ == 0)
                    {
                        throw new Exception("Loop detected");
                    }
                    // Check if max emloyees required at current day
                    if (employ > maxEmployees)
                    {
                        maxEmployees = employ;
                    }
                }
            }
            employees.Text = maxEmployees.ToString();
            deadline.Text  = currentDate.ToLongDateString();
            period.Text    = (currentDate - Program.formMain.dateTimePicker.Value).Days.ToString() + " days";

            // Set Y axis maximum an minimum dates
            chart.ChartAreas[0].AxisY.Minimum = Program.formMain.dateTimePicker.Value.AddDays(-1).ToOADate();
            chart.ChartAreas[0].AxisY.Maximum = currentDate.ToOADate();

            // Add DataPoints to chart
            for (int i = 0; i < Nodes.Count(); i++)
            {
                Node node = Nodes.ElementAt(i);
                chart.Series[0].Points.AddXY(i, node.StartDate, node.FinishDate.AddDays(1));
                chart.Series[0].Points[i].Label   = chart.Series[0].Points[i].AxisLabel = node.ID;
                chart.Series[0].Points[i].ToolTip = node.StartDate.ToShortDateString() + " - " + node.FinishDate.ToShortDateString();
            }


            /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
            * Program Evaluation and Review Technique                                   *
            * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
            // Get union of all nodes dependencies
            List <Node> allDependencies = new List <Node>();
            // List of checkpoints
            List <Checkpoint> checkpoints = new List <Checkpoint>();

            for (int i = 0, m = 0; i < Nodes.Count; i++)
            {
                Node node = Nodes.ElementAt(i);
                allDependencies.AddRange(node.Dependencies);
                if (node.checkpoint == null)
                {
                    // Set checkpoint to node
                    Checkpoint checkpoint = new Checkpoint();
                    checkpoint.ID   = (checkpoint.Dependencies = node.Dependencies).Count == 0 ? "Start" : Checkpoint.template + m++.ToString();
                    node.checkpoint = checkpoint;
                    // Check other nodes for same dependencies
                    for (int j = i + 1; j < Nodes.Count; j++)
                    {
                        Node otherNode = Nodes.ElementAt(j);
                        if (otherNode.Dependencies.SetEquals(node.Dependencies))
                        {
                            otherNode.checkpoint = checkpoint;
                        }
                    }
                    checkpoints.Add(checkpoint);
                }
            }

            // Create finish checkpoint
            Checkpoint finish = new Checkpoint();

            finish.ID           = "Finish";
            finish.Dependencies = new HashSet <Node>(Nodes.Except(allDependencies));
            checkpoints.Add(finish);

            // Get critical way
            List <object> critical = new List <object>();

            critical.Add(finish);
            for (Checkpoint checkpoint = finish; checkpoint.Dependencies.Count > 0;)
            {
                DateTime latestDate = checkpoint.Dependencies.Max(new Func <Node, DateTime>(delegate(Node node) { return(node.FinishDate); }));
                Node     latestNode = checkpoint.Dependencies.First(new Func <Node, bool>(delegate(Node next) { return(next.FinishDate == latestDate); }));
                critical.Add(checkpoint = latestNode.checkpoint);
                critical.Add(latestNode);
            }

            // Create graph
            Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("PERT");
            // Add nodes
            foreach (Node node in Nodes)
            {
                graph.AddNode(node.ID);
                graph.FindNode(node.ID).Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Azure;
            }
            // Add checkpoints
            foreach (Checkpoint checkpoint in checkpoints)
            {
                graph.AddNode(checkpoint.ID);
                Microsoft.Glee.Drawing.Node graphNode = graph.FindNode(checkpoint.ID);
                graphNode.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.MistyRose;
                graphNode.Attr.Shape     = Microsoft.Glee.Drawing.Shape.Diamond;
            }
            // Connect each node to its dependency checkpoint
            foreach (Node node in Nodes)
            {
                Microsoft.Glee.Drawing.Edge edge = new Microsoft.Glee.Drawing.Edge(node.checkpoint.ID, null, node.ID);
                if (critical.Contains(node))
                {
                    edge.Attr.Color = Microsoft.Glee.Drawing.Color.Red;
                }
                graph.Edges.Add(edge);
            }
            // Connect each checkpoint to all dependency nodes
            foreach (Checkpoint checkpoint in checkpoints)
            {
                foreach (Node node in checkpoint.Dependencies)
                {
                    Microsoft.Glee.Drawing.Edge edge = new Microsoft.Glee.Drawing.Edge(node.ID, null, checkpoint.ID);
                    if (critical.Contains(node) && critical.Contains(checkpoint))
                    {
                        edge.Attr.Color = Microsoft.Glee.Drawing.Color.Red;
                    }
                    graph.Edges.Add(edge);
                }
            }

            // Bind the graph to the viewer
            gViewer.Graph            = graph;
            gViewer.OutsideAreaBrush = Brushes.OldLace;
        }
        public FormGanttChart()
        {
            InitializeComponent();

            /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
             *                          GANTT CHART                                      *
             * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
            chart.ChartAreas[0].AxisY.IntervalType = DateTimeIntervalType.Days;
            //chart.ChartAreas[0].AxisY.Interval = 1;

            // Get each task start date and finish date
            HashSet<Node> Nodes = Program.formMain.GetNodes();
            int maxEmployees = 0;
            // While there are uncomlited tasks
            DateTime currentDate = Program.formMain.dateTimePicker.Value;
            for (; Nodes.Any(new Func<Node, bool>(delegate(Node node) { return node.Days > 0; })); currentDate = currentDate.AddDays(1))
            {
                // Start unstarted tasks that have all dependencies complited
                foreach (Node node in Nodes)
                    if (!node.HasStarted && node.Dependencies.All(new Func<Node, bool>(delegate(Node dependency) { return dependency.Days == 0; })))
                    {
                        node.HasStarted = true;
                        node.StartDate = currentDate;
                    }

                // Decrese days of uncomplited started tasks and finish them if current day was last
                if (Program.formMain.checkboxes[(int)currentDate.DayOfWeek].Checked)
                {
                    // Count of employees required at current day
                    int employ = 0;
                    foreach (Node node in Nodes)
                        if (node.HasStarted && node.Days > 0)
                        {
                            employ++;
                            if (--node.Days == 0)
                                node.FinishDate = currentDate;
                        }
                    // Check for loops
                    if (employ == 0) throw new Exception("Loop detected");
                    // Check if max emloyees required at current day
                    if (employ > maxEmployees) maxEmployees = employ;
                }
            }
            employees.Text = maxEmployees.ToString();
            deadline.Text = currentDate.ToLongDateString();
            period.Text = (currentDate - Program.formMain.dateTimePicker.Value).Days.ToString() + " days";

            // Set Y axis maximum an minimum dates
            chart.ChartAreas[0].AxisY.Minimum = Program.formMain.dateTimePicker.Value.AddDays(-1).ToOADate();
            chart.ChartAreas[0].AxisY.Maximum = currentDate.ToOADate();

            // Add DataPoints to chart
            for (int i = 0; i < Nodes.Count(); i++)
            {
                Node node = Nodes.ElementAt(i);
                chart.Series[0].Points.AddXY(i, node.StartDate, node.FinishDate.AddDays(1));
                chart.Series[0].Points[i].Label = chart.Series[0].Points[i].AxisLabel = node.ID;
                chart.Series[0].Points[i].ToolTip = node.StartDate.ToShortDateString() + " - " + node.FinishDate.ToShortDateString();
            }

            /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
             * Program Evaluation and Review Technique                                   *
             * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
            // Get union of all nodes dependencies
            List<Node> allDependencies = new List<Node>();
            // List of checkpoints
            List<Checkpoint> checkpoints = new List<Checkpoint>();
            for (int i = 0, m = 0; i < Nodes.Count; i++)
            {
                Node node = Nodes.ElementAt(i);
                allDependencies.AddRange(node.Dependencies);
                if (node.checkpoint == null)
                {
                    // Set checkpoint to node
                    Checkpoint checkpoint = new Checkpoint();
                    checkpoint.ID = (checkpoint.Dependencies = node.Dependencies).Count == 0 ? "Start" : Checkpoint.template + m++.ToString();
                    node.checkpoint = checkpoint;
                    // Check other nodes for same dependencies
                    for (int j = i + 1; j < Nodes.Count; j++)
                    {
                        Node otherNode = Nodes.ElementAt(j);
                        if (otherNode.Dependencies.SetEquals(node.Dependencies))
                            otherNode.checkpoint = checkpoint;
                    }
                    checkpoints.Add(checkpoint);
                }
            }

            // Create finish checkpoint
            Checkpoint finish = new Checkpoint();
            finish.ID = "Finish";
            finish.Dependencies = new HashSet<Node>(Nodes.Except(allDependencies));
            checkpoints.Add(finish);

            // Get critical way
            List<object> critical = new List<object>();
            critical.Add(finish);
            for (Checkpoint checkpoint = finish; checkpoint.Dependencies.Count > 0; )
            {
                DateTime latestDate = checkpoint.Dependencies.Max(new Func<Node, DateTime>(delegate(Node node) { return node.FinishDate; }));
                Node latestNode = checkpoint.Dependencies.First(new Func<Node, bool>(delegate(Node next) { return next.FinishDate == latestDate; }));
                critical.Add(checkpoint = latestNode.checkpoint);
                critical.Add(latestNode);
            }

            // Create graph
            Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("PERT");
            // Add nodes
            foreach (Node node in Nodes)
            {
                graph.AddNode(node.ID);
                graph.FindNode(node.ID).Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Azure;
            }
            // Add checkpoints
            foreach (Checkpoint checkpoint in checkpoints)
            {
                graph.AddNode(checkpoint.ID);
                Microsoft.Glee.Drawing.Node graphNode = graph.FindNode(checkpoint.ID);
                graphNode.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.MistyRose;
                graphNode.Attr.Shape = Microsoft.Glee.Drawing.Shape.Diamond;
            }
            // Connect each node to its dependency checkpoint
            foreach (Node node in Nodes)
            {
                Microsoft.Glee.Drawing.Edge edge = new Microsoft.Glee.Drawing.Edge(node.checkpoint.ID, null, node.ID);
                if (critical.Contains(node))
                    edge.Attr.Color = Microsoft.Glee.Drawing.Color.Red;
                graph.Edges.Add(edge);
            }
            // Connect each checkpoint to all dependency nodes
            foreach (Checkpoint checkpoint in checkpoints)
                foreach (Node node in checkpoint.Dependencies)
                {
                    Microsoft.Glee.Drawing.Edge edge = new Microsoft.Glee.Drawing.Edge(node.ID, null, checkpoint.ID);
                    if (critical.Contains(node) && critical.Contains(checkpoint))
                        edge.Attr.Color = Microsoft.Glee.Drawing.Color.Red;
                    graph.Edges.Add(edge);
                }

            // Bind the graph to the viewer
            gViewer.Graph = graph;
            gViewer.OutsideAreaBrush = Brushes.OldLace;
        }
Exemple #6
0
        private void draw_button_Click(object sender, EventArgs e)
        {
            ////////////////////////////////////////
            ///////////////////////////////////////
            for (int z = 0; z < gridorg.RowCount - 1; z++)
            {
                if (gridorg.Rows[z].Cells[2].Value == null)
                {
                    gridorg.Rows[z].Cells[2].Value = "";
                }
            }
            ///////////////////////////////////////
            for (int z = 0; z < gridorg.RowCount - 1; z++)
            {
                if (gridorg.Rows[z].Cells[1].Value == null)
                {
                    gridorg.Rows[z].Cells[1].Value = "";
                }
            }
            ///////////////////////////////////////
            for (int z = 0; z < gridorg.RowCount - 1; z++)
            {
                if (gridorg.Rows[z].Cells[0].Value == null)
                {
                    gridorg.Rows[z].Cells[0].Value = "";
                }
            }
            ///////////////////////////////////////
            int x = 0;

            Microsoft.Glee.Drawing.Graph graph = new Microsoft.Glee.Drawing.Graph("graph");
            ////////////////////////////////////////
            ///////////////////////////////////////
            for (int i = 0; i < gridorg.Rows.Count - 1; i++)
            {
                /* x = gridorg.Rows[i].Cells[0].Value.ToString();
                 * Console.WriteLine("{0}", x);
                 * graph.AddEdge("hellow","hello");*/
                if (gridorg.Rows[i].Cells[2].Value.ToString() == "")
                {
                    graph.AddNode(gridorg.Rows[i].Cells[0].Value.ToString() + "\n" + gridorg.Rows[i].Cells[1].Value.ToString());
                    graph.FindNode(gridorg.Rows[i].Cells[0].Value.ToString() + "\n" + gridorg.Rows[i].Cells[1].Value.ToString()).Attr.Shape     = Microsoft.Glee.Drawing.Shape.Ellipse;
                    graph.FindNode(gridorg.Rows[i].Cells[0].Value.ToString() + "\n" + gridorg.Rows[i].Cells[1].Value.ToString()).Attr.Fillcolor = Microsoft.Glee.Drawing.Color.AliceBlue;
                    graph.FindNode(gridorg.Rows[i].Cells[0].Value.ToString() + "\n" + gridorg.Rows[i].Cells[1].Value.ToString()).Attr.FontName  = "Tahoma";
                    continue;
                }
                for (int j = 0; j < gridorg.RowCount - 1; j++)//looks for the description of the rankabove
                {
                    if (gridorg.Rows[i].Cells[2].Value.ToString() == gridorg.Rows[j].Cells[0].Value.ToString())
                    {
                        x = j;
                    }
                }
                graph.AddEdge(gridorg.Rows[i].Cells[2].Value.ToString() + "\n" + gridorg.Rows[x].Cells[1].Value.ToString(), gridorg.Rows[i].Cells[0].Value.ToString() + "\n" + gridorg.Rows[i].Cells[1].Value.ToString()).Attr.Color = Microsoft.Glee.Drawing.Color.Black;
                graph.FindNode(gridorg.Rows[i].Cells[2].Value.ToString() + "\n" + gridorg.Rows[x].Cells[1].Value.ToString()).Attr.Shape     = Microsoft.Glee.Drawing.Shape.Box;
                graph.FindNode(gridorg.Rows[i].Cells[2].Value.ToString() + "\n" + gridorg.Rows[x].Cells[1].Value.ToString()).Attr.Color     = Microsoft.Glee.Drawing.Color.Black;
                graph.FindNode(gridorg.Rows[i].Cells[2].Value.ToString() + "\n" + gridorg.Rows[x].Cells[1].Value.ToString()).Attr.Fillcolor = Microsoft.Glee.Drawing.Color.AliceBlue;
                graph.FindNode(gridorg.Rows[i].Cells[0].Value.ToString() + "\n" + gridorg.Rows[i].Cells[1].Value.ToString()).Attr.Shape     = Microsoft.Glee.Drawing.Shape.Box;
                graph.FindNode(gridorg.Rows[i].Cells[0].Value.ToString() + "\n" + gridorg.Rows[i].Cells[1].Value.ToString()).Attr.Color     = Microsoft.Glee.Drawing.Color.Black;
                graph.FindNode(gridorg.Rows[i].Cells[0].Value.ToString() + "\n" + gridorg.Rows[i].Cells[1].Value.ToString()).Attr.Fillcolor = Microsoft.Glee.Drawing.Color.AliceBlue;
            }
            //graph.FindNode("Mohamed Bahaa" + "hello world");
            ////////////////////////////////////////
            ///////////////////////////////////////bind the graph to the viewer
            graph.GraphAttr.Orientation = Microsoft.Glee.Drawing.Orientation.Portrait;
            graph.GraphAttr.Border      = 2;

            graph.GraphAttr.AspectRatio = 1;

            graph.GraphAttr.NodeAttr.FontName = "Tahoma";
            graph.GraphAttr.NodeAttr.Fontsize = 5;
            graph.GraphAttr.NodeAttr.Shape    = Microsoft.Glee.Drawing.Shape.Box;

            graph.GraphAttr.EdgeAttr.FontName          = "Tahoma";
            graph.GraphAttr.EdgeAttr.Fontsize          = 50;
            graph.GraphAttr.EdgeAttr.Separation        = 1000;
            graph.GraphAttr.EdgeAttr.ArrowHeadAtTarget = Microsoft.Glee.Drawing.ArrowStyle.Tee;

            viewer.Graph = graph;

            //associate the viewer with the form
            form.SuspendLayout();
            viewer.Dock = System.Windows.Forms.DockStyle.Fill;
            //viewer.Size = new Size(1000, 1000);
            //viewer.MinimumSize = new Size(Screen.PrimaryScreen.Bounds.Height, Screen.PrimaryScreen.Bounds.Width);
            //viewer.AutoScroll = true;
            form.Controls.Add(viewer);

            form.ResumeLayout();
            //show the form
            form.ShowDialog();
        }