Example #1
0
        public void DrawMaze(GroupBox canvas)
        {
            Pen myPen = new System.Drawing.Pen(Color.Red);
            SolidBrush mBrush = new SolidBrush(Color.LawnGreen);
            Graphics fGraphics = canvas.CreateGraphics();
            fGraphics.Clear(Color.Gray);

            Random rand = new Random();

            startPosition = new Point(rand.Next(0, width), rand.Next(0, height));
            finalDestination = new Point(rand.Next(0, width), rand.Next(0, height));

            int size = 20;
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    MazeCell currCell = maze[i][j];

                    if (currCell.North == null)
                        fGraphics.DrawLine(myPen, i * size, j * size, (i + 1) * size, j * size);

                    if (currCell.South == null)
                        fGraphics.DrawLine(myPen, i * size, (j + 1) * size, (i + 1) * size, (j + 1) * size);

                    if (currCell.East == null)
                        fGraphics.DrawLine(myPen, (i + 1) * size, j * size, (i + 1) * size, (j + 1) * size);

                    if (currCell.West == null)
                        fGraphics.DrawLine(myPen, i * size, j * size, i * size, (j + 1) * size);
                }
            }

            //drawing startin and ending point
            fGraphics.FillRectangle(mBrush, startPosition.X * size + size / 2, startPosition.Y * size + size / 2, size / 2, size / 2);
            mBrush.Color = Color.SteelBlue;
            fGraphics.FillRectangle(mBrush, finalDestination.X * size + size / 2, finalDestination.Y * size + size / 2, size / 2, size / 2);

            myPen.Dispose();
            fGraphics.Dispose();
            mBrush.Dispose();
        }
Example #2
0
        /// <summary>
        /// Event Handler from Form Load Event
        /// Setup the real time stylus for collection.
        /// </summary>
        /// <param name="sender">The control that raised the event.</param>
        /// <param name="e">The event arguments.</param>
        private void RealTimeStylusPlugin_Load(object sender, System.EventArgs e)
        {
            // Create the real time stylus used to receive stylus notifications
            myRealTimeStylus = new RealTimeStylus(gbTestArea, true);

            // Store the Graphics object associated with the drawing area.
            customDynamicRendererGraphics = gbTestArea.CreateGraphics();

            // Create the plugins.  Note that since these are
            // synchronous plugins, notification will occur on the
            // pen thread.
            //
            // -PacketFilterPlugin: demonstrates packet modification by
            //  constraining all x,y packet data within a rectangular area.
            // -CustomDynamicRendererPlugin:  demonstrates custom dynamic
            //  rendering by drawing a small circle around each x,y.
            // -GestureRecognizer:  plugin provided by the Tablet PC Platform
            //  API, which recognizes application gestures.
            // -DynamicRenderer:  plugin provided by Tablet PC Platform API,
            // which renders packet data as it is collected.

            // Create the PacketFilterPlugin
            // Note that this custom plugin takes a rectangle in
            // ink space coordinates (.01mm = 1 ink space unit), which
            // specifies the filter region.  This sample uses a rectangle
            // that is centered over the drawing area.
            float     right      = ((float)gbTestArea.Width * 2540.0F) / (float)customDynamicRendererGraphics.DpiX;
            float     bottom     = ((float)gbTestArea.Height * 2540.0F) / (float)customDynamicRendererGraphics.DpiY;
            Rectangle filterRect = new Rectangle((int)Math.Round(.15F * right),
                                                 (int)Math.Round(.15F * bottom),
                                                 (int)Math.Round(.7F * right),
                                                 (int)Math.Round(.7F * bottom));
            IStylusSyncPlugin filterPlugin = new PacketFilterPlugin(filterRect);

            chklbPlugins.Items.Add(new PluginListItem(filterPlugin, "PacketFilter"));

            // Create the CustomDynamicRendererPlugin
            IStylusSyncPlugin rendererPlugin = new CustomDynamicRendererPlugin(customDynamicRendererGraphics);

            chklbPlugins.Items.Add(new PluginListItem(rendererPlugin, "CustomDynamicRenderer"));

            // Attempt to create the GestureRecognizer plugin.
            // An exception will occur if no recognizers are available.
            // In this case, the sample proceeds, but does not add the
            // gesture recognizer into the list of available plugins.
            GestureRecognizer gr = null;

            try
            {
                gr = new GestureRecognizer();
                ApplicationGesture [] gestures = { ApplicationGesture.AllGestures };
                gr.EnableGestures(gestures);
                chklbPlugins.Items.Add(new PluginListItem(gr, "GestureRecognizer"));
            }
            catch
            {
            }

            // Create the dynamic renderer used to render the stroke that is
            //  currently being collected
            DynamicRenderer dr = new DynamicRenderer(gbTestArea);

            chklbPlugins.Items.Add(new PluginListItem(dr, "DynamicRenderer"));

            // Enable all plugins
            for (int i = 0; i < chklbPlugins.Items.Count; i++)
            {
                chklbPlugins.SetItemChecked(i, true);
            }

            // Add this form to the collection of asynchronous plugins.
            // The CustomStylusDataAdded notification will be used to
            // update the form's UI when an application gesture occurs.
            // Since this is an asynchronous plugin, notification will
            // occur on the UI thread.
            myRealTimeStylus.AsyncPluginCollection.Add(this);

            // Enable the RealTimeStylus, GestureRecognizer, and DynamicRenderer
            myRealTimeStylus.Enabled = true;
            if (gr != null)
            {
                gr.Enabled = true;
            }
            dr.Enabled = true;
        }