Example #1
0
        // This is a constructor method for the DrawIt class.  Notice that it has the same name ("DrawIt") as the class,
        // and does not have a return type.  That's how we know it's a constructor method.
        public DrawIt()
        {
            // This may look familiar from last week's "create a Windows Forms application" assignment.
            // It is generated by Visual Studio to do the initial setup of the controls on your Windows Form.
            InitializeComponent();

            // This line creates a new DrawingModel which wraps around and encapsulates
            // the CanvasPanel, and then stores that DrawingModel into the instance variable
            // _canvasModel.
            //
            // Since _canvasModel is an "instance variable" (declared as part of the DrawIt
            // class, above), all of the "instance methods" here in DrawIt (also declared as
            // part of the DrawIt class) will be able to see it.  Anything that wants to draw
            // something on the canvas can say _canvasModel.DrawLine() or _canvasModel.DrawCircle() or...
            //
            // I have implemented versions of HandleMouseDown() and HandleMouseMoved() below
            // that draw simple circles on the canvas, and a circular cursor to show where
            // the next circle will be drawn, to illustrate how to use the DrawingModel.
            _canvasModel = new DrawingModel(CanvasPanel);

            // This creates the Pen intance that draws lines on the canvas.
            _pen = new Pen(_COLOR, _LINE_WIDTH);

            // This starts us out with a dark gray background on the canvas (so the user can see
            // where to draw).
            _canvasModel.Clear(_BACKGROUND_COLOR);

            // These three lines add "event handlers" to the canvas so that we get told when the user
            // does something with the mouse.  An "event handler" is just a method that knows how to
            // respond to an event (something that happened).  You can watch the extra session from
            // this Thursday if you want to see how to create a method like this.
            CanvasPanel.MouseDown += HandleMouseDown;
            CanvasPanel.MouseUp   += HandleMouseUp;
            CanvasPanel.MouseMove += HandleMouseMoved;
        }
Example #2
0
        // This is a constructor method for the DrawIt class.  Notice that it has the same name ("DrawIt") as the class,
        // and does not have a return type.  That's how we know it's a constructor method.
        public DrawIt()
        {
            // This may look familiar from last week's "create a Windows Forms application" assignment.
            // It is generated by Visual Studio to do the initial setup of the controls on your Windows Form.
            InitializeComponent();

            // This line creates a new DrawingModel which wraps around and encapsulates
            // the CanvasPanel, and then stores that DrawingModel into the instance variable
            // _canvasModel.
            //
            // Since _canvasModel is an "instance variable" (declared as part of the DrawIt
            // class, above), all of the "instance methods" here in DrawIt (also declared as
            // part of the DrawIt class) will be able to see it.  Anything that wants to draw
            // something on the canvas can say _canvasModel.DrawLine() or _canvasModel.DrawCircle() or...
            //
            // I have implemented versions of HandleMouseDown() and HandleMouseMoved() below
            // that draw simple circles on the canvas, and a circular cursor to show where
            // the next circle will be drawn, to illustrate how to use the DrawingModel.
            _canvasModel = new DrawingModel(CanvasPanel);

            // This line creates a PaintbrushControlModel to listen to the mouse events from the
            // CanvasPanel, and call our IPaintbrushEventHandler methods when appropriate.
            //
            // When we created the DrawingModel above, we put it into an instance variable called
            // "_canvasModel", because we needed to be able to call methods on it later.
            //
            // We don't need to call any methods on the PaintbrushControlModel later, so we
            // aren't going to put it into an instance variable.  Just creating it with the
            // CanvasPanel and ourself is enough.
            //
            // If we decided later to give the PaintbrushControlModel methods that we'd want
            // to call (for example, a "SuspendDrawing()" method that blocked all drawing
            // actions from being forwarded to us), we'd make an instance variable _paintbrushControlModel
            // and set its value to this new object.
            new PaintbrushControlModel(CanvasPanel, this);

            // This creates the Pen intance that draws lines on the canvas.
            _pen = new Pen(_COLOR, _LINE_WIDTH);

            // This starts us out with a dark gray background on the canvas (so the user can see
            // where to draw).
            _canvasModel.Clear(_BACKGROUND_COLOR);
        }
Example #3
0
 private void ClearButtonClicked(object sender, EventArgs e)
 {
     _canvasModel.Clear(_BACKGROUND_COLOR);
 }
Example #4
0
        // This is a constructor method for the DrawIt class.  Notice that it has the same name ("DrawIt") as the class,
        // and does not have a return type.  That's how we know it's a constructor method.
        public DrawIt()
        {
            // This may look familiar from last week's "create a Windows Forms application" assignment.
            // It is generated by Visual Studio to do the initial setup of the controls on your Windows Form.
            InitializeComponent();

            // This line creates a new DrawingModel which wraps around and encapsulates
            // the CanvasPanel, and then stores that DrawingModel into the instance variable
            // _canvasModel.
            //
            // Since _canvasModel is an "instance variable" (declared as part of the DrawIt
            // class, above), all of the "instance methods" here in DrawIt (also declared as
            // part of the DrawIt class) will be able to see it.  Anything that wants to draw
            // something on the canvas can say _canvasModel.DrawLine() or _canvasModel.DrawCircle() or...
            //
            // I have implemented versions of HandleMouseDown() and HandleMouseMoved() below
            // that draw simple circles on the canvas, and a circular cursor to show where
            // the next circle will be drawn, to illustrate how to use the DrawingModel.
            _canvasModel = new DrawingModel(CanvasPanel);

            // This line creates a PaintbrushControlModel to listen to the mouse events from the
            // CanvasPanel, and call our IPaintbrushEventHandler methods when appropriate.
            //
            // When we created the DrawingModel above, we put it into an instance variable called
            // "_canvasModel", because we needed to be able to call methods on it later.
            //
            // We don't need to call any methods on the PaintbrushControlModel later, so we
            // aren't going to put it into an instance variable.  Just creating it with the
            // CanvasPanel and ourself is enough.
            //
            // If we decided later to give the PaintbrushControlModel methods that we'd want
            // to call (for example, a "SuspendDrawing()" method that blocked all drawing
            // actions from being forwarded to us), we'd make an instance variable _paintbrushControlModel
            // and set its value to this new object.
            new PaintbrushControlModel(CanvasPanel, this);

            // This creates the Pen intance that draws lines on the canvas.
            _pen = new Pen(_COLOR, _LINE_WIDTH);

            // This starts us out with a dark gray background on the canvas (so the user can see
            // where to draw).
            _canvasModel.Clear(_BACKGROUND_COLOR);
        }
Example #5
0
        // This is a constructor method for the DrawIt class.  Notice that it has the same name ("DrawIt") as the class,
        // and does not have a return type.  That's how we know it's a constructor method.
        public DrawIt()
        {
            // This may look familiar from last week's "create a Windows Forms application" assignment.
            // It is generated by Visual Studio to do the initial setup of the controls on your Windows Form.
            InitializeComponent();

            // This line creates a new DrawingModel which wraps around and encapsulates
            // the CanvasPanel, and then stores that DrawingModel into the instance variable
            // _canvasModel.
            //
            // Since _canvasModel is an "instance variable" (declared as part of the DrawIt
            // class, above), all of the "instance methods" here in DrawIt (also declared as
            // part of the DrawIt class) will be able to see it.  Anything that wants to draw
            // something on the canvas can say _canvasModel.DrawLine() or _canvasModel.DrawCircle() or...
            //
            // I have implemented versions of HandleMouseDown() and HandleMouseMoved() below
            // that draw simple circles on the canvas, and a circular cursor to show where
            // the next circle will be drawn, to illustrate how to use the DrawingModel.
            _canvasModel = new DrawingModel(CanvasPanel);

            // This creates the Pen intance that draws lines on the canvas.
            _pen = new Pen(_COLOR, _LINE_WIDTH);

            // This starts us out with a dark gray background on the canvas (so the user can see
            // where to draw).
            _canvasModel.Clear(_BACKGROUND_COLOR);

            // These three lines add "event handlers" to the canvas so that we get told when the user
            // does something with the mouse.  An "event handler" is just a method that knows how to
            // respond to an event (something that happened).  You can watch the extra session from
            // this Thursday if you want to see how to create a method like this.
            CanvasPanel.MouseDown += HandleMouseDown;
            CanvasPanel.MouseUp += HandleMouseUp;
            CanvasPanel.MouseMove += HandleMouseMoved;
        }