How do I create a new image off a base image with certain portions of the base image modified, in code

This code depends on the actual bitmap in use. This logic sets a random rectangular portion in the image to a new color. public class ImageUtil { private Image baseImage; private void InitBaseImage(Image baseImage) { this.baseImage = baseImage.Clone() as Image; } private Image ApplyNewColorOnImage(Color newColor) { // Create a new bitmap off the base image. Image newImage = this.baseImage.Clone() as Image; Bitmap newBitmap = new Bitmap(newImage); // Set the Color cue pixels to the appropriate color. // This logic of course, depends on the actual bitmap. for (int i = 12; i <= 14; i++) for (int j = 2; j <= 14; j++) newBitmap.SetPixel(j, i, newColor); return newImage; } }

Why would I be getting a NullReferenceException in Windows Forms with no application code in the call stack

The CLR is catching an Access Violation that’s being thrown from unmanaged code, and that is propagating up as a NullReferenceException. I’ve seen this happen with certain common control library windows types if an application such as spy++ is running, and I see this is the TreeView control that is having troubles with a mouse down. Have you done any modification to the control through P/Invoke methods? (from [email protected] on microsoft.public.dotnet.framework.windowsforms)

How can I tell whether a scrollbar is visible in my DataGrid is visible

If you are using a derived DataGrid, then you can check the Visible property on the protected VertScrollBar property of DataGrid. So, you could check Me.VertScrollBar.Visible from within your derived DataGrid. To check it without access to the protected scrollbar properties is a little more work, but possible. One technique is to loop through the Controls property of the DataGrid looking for the scrollbar, and then checking its visible property at that time. [C#] //sample usage bool vSrollBarVisible = this.IsScrollBarVisible(this.dataGrid1); ….. private bool IsScrollBarVisible(Control aControl) { foreach(Control c in aControl.Controls) { if (c.GetType().Equals(typeof(VScrollBar))) { return c.Visible; } } return false; } [VB.NET] ’sample usage Dim vScrollBarVisible = Me.IsScrollBarVisible(Me.DataGrid1) …… Private Function IsScrollBarVisible(ByVal aControl As Control) As Boolean Dim c As Control For Each c In aControl.Controls If c.GetType() Is GetType(VScrollBar) Then Return c.Visible End If Next Return False End Function