( Index )
Month

Brief Information about the May '10 CSIG Meeting

Catch Me If You Can - A Simple Graphics Program

by Bruce Arnold
Catch Me!

Welcome to the CSIG, a Special Interest Group of the ACGNJ. This is an exciting time for the C Language programming since Microsoft now has 4 different language compilers: C++, C++ Express, C-Sharp, and C-Sharp Express. These are all capable of creating Windows (tm) programs. (Some are FREE!)

Here's a brief synopsis of this month's meeting:

The object of this program is to study some simple graphic techniques using Dot Net. As can be seen in the screen shot above, the program displays a colored circle on a colored background. Additionally, the circle or balloon has some text printed inside. When the user moves the mouse over to the balloon, it "runs away" from the mouse.

The program uses a number of DOT NET Library functions including the following:

DrawString
MeasureString
Font()
Point
SolidBrush
Random
DoubleBuffered
ClientRectangle
DrawEllipse
FillEllipse


There are a number of ways to refer to Microsoft's latest compilers and code. Here's what Wikipedia says: The Common Language Infrastructure (CLI) is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of the Microsoft .NET Framework. The specification defines an environment that allows multiple high-level languages to be used on different computer platforms without being rewritten for specific architectures.

Microsoft .Net Framework 3.5
C++ 9.0
.Net 3.5
CLI
Common Language Infrastructure
Managed

Sample Code

// // Paint Message Handler // private: System::Void Form1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) { e; sender; // avoid unreferenced parameter error message during compilation. Rectangle windowRect = ClientRectangle; // Get size of window. Graphics ^g = e->Graphics; g->FillEllipse(BalloonBrush, // Fill the whole balloon with color BalloonCenter.X - BalloonRadius, BalloonCenter.Y - BalloonRadius, 2 * BalloonRadius, 2 * BalloonRadius); g->DrawEllipse(Pens::Black, // Draw a black line around it. BalloonCenter.X - BalloonRadius, BalloonCenter.Y - BalloonRadius, 2 * BalloonRadius, 2 * BalloonRadius); g->DrawEllipse(Pens::White, // Draw a white line around it. BalloonCenter.X - BalloonRadius - 1, BalloonCenter.Y - BalloonRadius - 1, 2 * BalloonRadius + 2, 2 * BalloonRadius + 2); Drawing::Font ^mFont = gcnew Drawing::Font("Arial", 24, Drawing::FontStyle::Bold); String ^mString = gcnew String("Catch Me!"); Drawing::SizeF mFontSize = g->MeasureString(mString,mFont); g->DrawString(mString, mFont, Brushes::Yellow, (float)BalloonCenter.X-(mFontSize.Width/2), (float)BalloonCenter.Y-(mFontSize.Height/2) ); } // // Randomize the center of the balloon // Point Form1_GetRandPoint(Rectangle rr) { Point pp; if ((rr.Right - rr.Left) < 1 || (rr.Bottom - rr.Top) < 1) { pp.X; pp.Y = 0; return pp; // trap potential divide by zero } pp.X = rr.Left + pRand->Next(rr.Right - rr.Left); pp.Y = rr.Top + pRand->Next(rr.Bottom - rr.Top); return pp; } // // Randomize the color of the Balloon to descrete values. // Color Form1_GetRandColor() { int arg[3]; arg[0] = 0; arg[1] = 128; arg[2] = 192; int alpha[3]; alpha[0] = 0xEF; alpha[1] = 0xF0; alpha[2] = 0xFF; return Color::FromArgb( alpha[2], // leave alpha solid. arg[pRand->Next(3)], arg[pRand->Next(3)], arg[pRand->Next(3)] ); }

SOURCE CODE

Source Code Files

For help, email me at b a r n o l d @ i e e e . o r g
Back to C++ Main Page