A control’s Validating event is hit even when the user clicks on the Close box. How can I avoid this behavior

One way is to add code to your Validating handler and only execute the validation routine if the mouse is in the client area. This will avoid the click on the title bar and its system menu. You might also want to add special handling for the tab key so your validation is hit independent of the mouse location when you tab off the control. private bool tabKeyPressed = false; private void textBox1_Validating(object sender, System.ComponentModel.CancelEventArgs e) { if(tabKeyPressed || this.ClientRectangle.Contains(this.PointToClient(Cursor.Position))) { if(boolNotOKValues) //do your validating e.Cancel = true; //failed } tabKeyPressed = false; } protected override bool ProcessDialogKey(Keys keyData) { tabKeyPressed = keyData == Keys.Tab; return base.ProcessDialogKey(keyData); }

How can I swap colors in a bitmap or icon

You use ImageAttributes, adding a ColorMap that swaps the colors. Here is a code snippet. Bitmap originalBMP = (Bitmap) Image.FromFile(@’c:\circle.bmp’); //make a copy so original will still be available Bitmap swappedBMP = new Bitmap(originalBMP); Graphics g = Graphics.FromImage(swappedBMP); // Create a color map. ColorMap[] colorSwapper= new ColorMap[2]; colorSwapper[0] = new ColorMap(); colorSwapper[1] = new ColorMap(); colorSwapper[0].OldColor = Color.Red; //red changes to yellow colorSwapper[0].NewColor = Color.Yellow; colorSwapper[1].OldColor = Color.Blue;//blue changes to green colorSwapper[1].NewColor = Color.Green; // Create an ImageAttributes object, and call SetRemapTable ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetRemapTable(colorSwapper); //overdraw the bitmap with swapped colors g.DrawImage(swappedBMP, new Rectangle(0, 0, swappedBMP.Width, swappedBMP.Height),0, 0, swappedBMP.Width, swappedBMP.Height, GraphicsUnit.Pixel, imageAttr); pictureBox1.Image = swappedBMP; Here is similar code that wraps this technique in a method that swaps a single color. protected void DrawMyBitmap(Graphics gph, Color oldColor, Color newColor, Bitmap baseImage, Rectangle rect) { ImageAttributes imgattr = new ImageAttributes(); ColorMap[] clrmap = new ColorMap[1]{ new ColorMap() }; clrmap[0].OldColor = oldColor; clrmap[0].NewColor = newColor; imgattr.SetRemapTable(clrmap); gph.DrawImage(baseImage,rect,0,0,rect.Width, rect.Height,GraphicsUnit.Pixel,imgattr); }

The controls that I’ve try to add to my form at runtime don’t show up. What’s wrong

Make sure you implemented and executed code similar to the InitializeComponent method that VS adds to your Windows Forms project for controls added during design time. Recall that InitializeComponent() is called from your Forms constructor to create the controls, size, position and show the controls, and finally add the controls to the form’s Controls collection. So, your code at runtime should also implement these same steps. In particular, don’t forget the this.Controls.AddRange call that adds your new controls to the form’s Controls collection.

How do I set the mouse cursor position

The Cursor.Position property is a static property with both get and set methods available. Remember that the Point object used by the property is in screen coordinates. Here is code that move the mouse position down 20 points. Point pt = Cursor.Position; pt.Y += 20; Cursor.Position = pt;