/////////////////////////////////////////////////////////////////////// // demoControl.cpp - Demonstration control example that illustrates: // // - how to expose events (with delegates) // // - how to expose properties (by defining them) // // // // Language: Visual C++/CLI, VS8 // // Platform: Dell Dimension 9250, Windows XP Pro, SP2 // // Application: CSE775 - Distributed Objects Demo // // Author: Jim Fawcett, CST 2-187, Syracuse University // // (315) 443-3948, jfawcett@twcny.rr.com // /////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "demoControl.h" using namespace control; //----< initialize control >----------------------------------------- controlControl::controlControl(void) { bkgrBrush = gcnew SolidBrush(Color::WhiteSmoke); this->controlText = "demoControl"; InitializeComponent(); } //----< define painted view of control surface >--------------------- void controlControl::OnPaint(PaintEventArgs^ e) { Control::OnPaint(e); Graphics^ g = e->Graphics; SolidBrush^ blackbrush = gcnew SolidBrush(Color::Black); SolidBrush^ whitebrush = gcnew SolidBrush(Color::White); int ht = this->Height; int wd = this->Width; g->FillRectangle(bkgrBrush,0,0,wd,ht); String^ msg("CSE775 - Distributed Objects"); g->DrawString( msg, gcnew System::Drawing::Font("tahoma",18),blackbrush,50,50 ); } // //----< event handler for MouseDown >-------------------------------- System::Void controlControl::controlControl_MouseDown( System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e ) { bkgrBrush = gcnew SolidBrush(Color::Bisque); this->Invalidate(); ////////////////////////////////////////////////// // It is odd, but the following fails to compile // if(mousedown) // Apparently the invoker, in C++/CLI checks for // nullptr and does nothing if null // republish as our own event mousedown(this,e); } //----< event handler for MouseUp >------------------------------ System::Void controlControl::controlControl_MouseUp( System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e ) { bkgrBrush = gcnew SolidBrush(Color::WhiteSmoke); this->Invalidate(); // republish as our own event // if(mouseup) mouseup(this,e); }