dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/samples CustomControl.cs,NONE,1.1 sa


From: Gopal.V <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/samples CustomControl.cs,NONE,1.1 samples.build,1.6,1.7
Date: Thu, 12 Jun 2003 07:22:25 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/samples
In directory subversions:/tmp/cvs-serv1990/samples

Modified Files:
        samples.build 
Added Files:
        CustomControl.cs 
Log Message:
A simple custom control demo


--- NEW FILE ---
/*
 * CustomControl.cs - Sample program for Custom control creation.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software, you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY, without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program, if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

using System;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;

public class MainForm : Form
{
        
        private MainForm()
        {
                SetStyle(ControlStyles.ResizeRedraw, true);
        }
        public static void Main(String[] args)
        {
                Form form = new MainForm();
                form.Width = 400;
                form.Height = 320;
                form.Text = "Graphs app";
                GraphItem[] data=new GraphItem[] 
                                                        {
                                                                new 
GraphItem(0,0),
                                                                new 
GraphItem(10,10),
                                                                new 
GraphItem(20,35),
                                                                new 
GraphItem(30,40),
                                                                new 
GraphItem(60,80),
                                                                new 
GraphItem(70,30),
                                                                new 
GraphItem(75,50),
                                                                new 
GraphItem(100,90)
                                                        };
                Control ctrl = new GraphControl(data,0,0,320,320);
                ctrl.Show();
                ctrl.Location = new Point(10,10);
                form.Controls.Add(ctrl);
                Application.Run(form);
        }
}

/// <summary>
/// The visual points on the graph 
/// </summary>
public class GraphPoint: Control
{
        private bool active=false;
        private Color ActiveColor=Color.Red;
        private Color InactiveColor=Color.FromArgb(0x91,0x91,0x91);
        const int radius=5;
        private static Size offset=new Size(radius, radius);

        internal void Draw(Graphics graphics)
        {
                if(!Visible) return;
                using(Brush brush=new SolidBrush(active ? ActiveColor : 
InactiveColor))
                {
                        graphics.FillEllipse(brush, 0,0, 2*radius, 2*radius);
                }
        }

        protected override void OnPaint(PaintEventArgs args)
        {
                Draw(args.Graphics);
        }

        protected override void OnMouseEnter(EventArgs args)
        {
                active=true;
                using(Graphics graphics=CreateGraphics())
                {
                        Draw(graphics);
                }
        }

        protected override void OnMouseLeave(EventArgs args)
        {
                active=false;
                using(Graphics graphics=CreateGraphics())
                {
                        Draw(graphics);
                }
        }

        protected override Size DefaultSize
        {
                get
                {
                        return new Size(2*radius,2*radius);
                }
        }

        public GraphPoint(Point pt)
        {
                Visible=true;
                this.Location=pt-offset;
        }

        public Point Point
        {
                get
                {
                        return (Location + offset);
                }
        }
}

///<summary>
/// The actual graph control class which handles the grid control
///</summary>
public class GraphControl: Control
{
        private GraphPoint [] points =null;
        const int edge=300;
        Size offset;
        
        internal void Draw(Graphics graphics)
        {
                int x=offset.Width;
                int y=offset.Height;
                using(Pen pen=new Pen(Color.FromArgb(0xC0,0xC0,0xC0), 0.5f))
                {
                        for(int i=0;i<edge;i+=(edge/10))
                        {
                                graphics.DrawLine(pen, x+0, y+i, x+edge, y+i);
                                graphics.DrawLine(pen, x+i, y+0, x+i, y+edge);
                        }
                }

                using(Pen pen=new Pen(Color.Black, 1.0f))
                {
                        graphics.DrawLine(pen,x+0,y+edge,x+edge,y+edge);
                        graphics.DrawLine(pen,x+edge,y+edge,x+edge,y+0);
                        graphics.DrawLine(pen,x,y,x,y+edge);
                        graphics.DrawLine(pen,x,y,x+edge,y);
                        for(int i=0;i<=edge;i+=(edge/10))
                        {
                                graphics.DrawLine(pen, x+0,y+i,x-4,y+i);
                                graphics.DrawLine(pen, x+edge,y+i,x+edge+4,y+i);
                                graphics.DrawLine(pen, x+i,y+edge,x+i,y+edge+4);
                                graphics.DrawLine(pen, x+i,y,x+i,y-4);
                        }
                }
                
                using(Pen pen=new Pen(Color.Red, 0.2f))
                {
                        for(int i=1;i<points.Length;i++)
                        {
                                graphics.DrawLine(pen,points[i-1].Point,
                                                                        
points[i].Point);
                        }
                }

                using(Font font = new Font("Arial", 12))
                {
                        using(Brush brush = new SolidBrush(Color.Black))
                        {
                                graphics.DrawString("Mouse Over Demo", font, 
brush, x+10,y+10);
                        }
                }
        }

        protected override Size DefaultSize
        {
                get
                {
                        return new Size(edge+20,edge+20);
                }
        }

        protected override void OnPaint(PaintEventArgs args)
        {
                Draw(args.Graphics);
                foreach(Control ctrl in Controls)
                {
                }
        }

        public GraphControl(GraphItem[] dataset,int left,int top,int right, int 
bottom) : base("GraphControl",left,top,right,bottom)
        {
                CreateHandle();
                this.points=new GraphPoint[dataset.Length];
                offset=new Size(5,2);
                for(int i=0;i<dataset.Length;i++)
                {
                        Point point=new Point();
                        point.X=(dataset[i].X * (edge/100));
                        point.Y=edge-(dataset[i].Y * (edge/100));
                        point=point+offset;
                        points[i]=new GraphPoint(point);
                        this.Controls.Add(points[i]);
                }
        }
}

public struct GraphItem
{
        int x;
        int y;
        public GraphItem(int x, int y)
        {
                this.x=x;
                this.y=y;
        }
        public int X
        {
                get { return this.x; }
        }
        public int Y
        {
                get { return this.y; }
        }
        public override String ToString()
        {
                return  "("+x+","+y+")";
        }
}



Index: samples.build
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/samples/samples.build,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** samples.build       11 Jun 2003 07:07:19 -0000      1.6
--- samples.build       12 Jun 2003 11:22:22 -0000      1.7
***************
*** 229,232 ****
--- 229,260 ----
                        <arg compiler="csc" value="/nowarn:169"/>
                </compile>
+               <!-- Build the CustomControl.exe program -->
+               <compile output="CustomControl.exe"
+                                target="exe"
+                                unsafe="true"
+                                nostdlib="true"
+                                optimize="true"
+                                debug="true">
+ 
+                       <sources>
+                               <includes if="${CONFIG_REFLECTION}" 
name="CustomControl.cs"/>
+                               <file name="dummy.cs"/>
+                       </sources>
+ 
+                       <references>
+                               <includes if="${CONFIG_REFLECTION}" 
name="../System.Windows.Forms/System.Windows.Forms.dll"/>
+                               <includes if="${CONFIG_REFLECTION}" 
name="../System.Drawing/System.Drawing.dll"/>
+                               <includes if="${CONFIG_REFLECTION}" 
name="../System/System.dll"/>
+                               <includes if="${CONFIG_REFLECTION}" 
name="../DotGNU.SSL/DotGNU.SSL.dll"/>
+                               <file name="../runtime/mscorlib.dll"/>
+                       </references>
+ 
+                       <arg compiler="cscc" value="-Wno-empty-input"/>
+                       <arg compiler="csc" value="/nowarn:626"/>
+                       <arg compiler="csc" value="/nowarn:649"/>
+                       <arg compiler="csc" value="/nowarn:168"/>
+                       <arg compiler="csc" value="/nowarn:67"/>
+                       <arg compiler="csc" value="/nowarn:169"/>
+               </compile>
        </target>
  </project>





reply via email to

[Prev in Thread] Current Thread [Next in Thread]