// screen.cs // C:>csc /t:winexe screen.cs // Well we want our program to be in a GUI window, so we need to inherit // from Form, which is in the library 'System.Windows.Forms'. using System; using System.Drawing; using System.Windows.Forms; class SimpleWindow : System.Windows.Forms.Form { private PictureBox Screen; // This is where we render to a Bitmap img, then at the end, we just // copy it to our screen! void Render() { Bitmap img = new Bitmap(300, 300); Graphics g = Graphics.FromImage(img); g.FillRectangle(Brushes.Blue, 10, 10, 260, 250); g.FillRectangle(Brushes.Red, 100, 100, 50, 50); g.DrawString("xbdev - simple rendering", this.Font, Brushes.White, 15, 15); g.DrawString("(Boxes are easy to draw)", this.Font, Brushes.Black, 15, 35); // Apply the graphics buffer - so we put it to our screen. Screen.Image = img; } // End of Render() // Window constructor SimpleWindow() { this.Screen = new System.Windows.Forms.PictureBox(); this.Screen.Name = "Screen"; this.Screen.Size = new System.Drawing.Size(300, 300); // We need to add our screen buffer to our window this.Controls.AddRange(new System.Windows.Forms.Control[] {this.Screen}); // Render to our backbuffer/screen. Render(); } // Our program entry point. static void Main() { System.Windows.Forms.Application.Run(new SimpleWindow()); } }// End of SimpleWindow Class