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)
Its possible that some of my class members will not be initialized when one of my virtual members gets called even before the constructor. How can I avoid this?
If possible, initialize them in-line: public class MyClass { public ArrayList myArrayList = new ArrayList(); public MyClass(){} public override void MyOverride() { // When this gets called by the base class constructor, myArrayList will be initialized. } }
I have a derived DataGridColumnStyle. From within my Paint override, how can I get at other values in the DataGrid
You can get a reference to the DataGrid with code such as: Dim grid As DataGrid = Me.DataGridTableStyle.DataGrid Once you have the grid, you can use an indexer to get the value of any particular column on the same row. Dim someValue as Object = grid(rowNum, 5) ’ value in column 5….
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