How can I autosize the rowheights in my datagrid
Here is a solution suggested by Matthew Benedict. It uses reflection to access the protected DataGridRows collection so he can set the row height. public void AutoSizeGrid() { // DataGrid should be bound to a DataTable for this part to // work. int numRows = ((DataTable)gridTasks.DataSource).Rows.Count; Graphics g = Graphics.FromHwnd(gridTasks.Handle); StringFormat sf = new StringFormat(StringFormat.GenericTypographic); SizeF size; // Since DataGridRows[] is not exposed directly by the DataGrid // we use reflection to hack internally to it.. There is actually // a method get_DataGridRows that returns the collection of rows // that is what we are doing here, and casting it to a System.Array MethodInfo mi = gridTasks.GetType().GetMethod('get_DataGridRows', BindingFlags.FlattenHierarchy | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); System.Array dgra = (System.Array)mi.Invoke(gridTasks,null); // Convert this to an ArrayList, little bit easier to deal with // that way, plus we can strip out the newrow row. ArrayList DataGridRows = new ArrayList(); foreach (object dgrr in dgra) { if (dgrr.ToString().EndsWith('DataGridRelationshipRow')==true) DataGridRows.Add(dgrr); } // Now loop through all the rows in the grid for (int i = 0; i < numRows; ++i) { // Here we are telling it that the column width is set to // 400.. so size will contain the Height it needs to be. size = g.MeasureString(gridTasks[i,1].ToString(),gridTasks.Font,400,sf); int h = Convert.ToInt32(size.Height); // Little extra cellpadding space h = h + 8; // Now we pick that row out of the DataGridRows[] Array // that we have and set it’s Height property to what we // think it should be. PropertyInfo pi = DataGridRows[i].GetType().GetProperty('Height'); pi.SetValue(DataGridRows[i],h,null); // I have read here that after you set the Height in this manner that you should // Call the DataGrid Invalidate() method, but I haven’t seen any prob with not calling it.. } g.Dispose(); }
How do I create a ‘Negative’ representation of an image?
This is quite simple actually. All you need to do is determine the color of a given pixel, and then subtract the RGB values from 255 (the maximum) and then reset the pixel. Here is the pertinent code. [Code – C#] for(int x = 0; x < mybitmap.Width; x++) { for(int y = 0; y < mybitmap.Height; y++) { //get the current color of the pixel System.Drawing.Color c = mybitmap.GetPixel(x,y); mybitmap.SetPixel(x,y, System.Drawing.Color.FromArgb(255 - c.R, 255 - c.G, 255 - c.B)); } } Note: This modifies the existing image, so work on a copy if you want to maintain the original.
How does VS.Net find the referenced assemblies when I build a project from the command line?
There are a couple of ways to specify where VS.Net looks for the assemblies that you reference in your project when building from the command line. One way is to specify the ‘HintPath’ for the reference: <Reference Name = 'MyAssembly.dll' AssemblyName = 'MyAssembly.dll' HintPath = '..\work\samples\assemblies\MyAssembly.dll' /> However, this would require all of the systems that build the application to have the exact same directory structure locally. There are often times when this is not wanted (or needed), such as having a script on a build machine. In this type of situation, you can use the DEVPATH environment variable, or make use of the Public Assembly folder functionality To use the DEVPATH environment variable, you would simply add the folder that contains the assembly (e.g. ‘c:\work\samples\assemblies’) to the list of directories. Then, you will need to specify the <developmentMode> element in the machine configuration file: <configuration> <runtime> <developmentMode developerInstallation='true'> </runtime> </configuration> This will instruct the CLR to locate the assemblies based on the DEVPATH environment variable. A less restrictive way to specify the assembly locations is by making use of the Public Assembly Folder functionality. This is done by adding a path to the PublicAssemblies registry key. Open up the registry, and locate the ‘HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.0\AssemblyFolders’ key (for VS.Net 2003, you would look under the ‘…\VisualStudio\7.1\AssembliesFolders’ key). You will see a subkey named ‘PublicAssemblies’. This is where you will want to add additional keys to create your own Public folders. To add your own folder, create a key (e.g. MyAssemblies), and set the default value to be the desired path (e.g. ‘c:\work\samples\assemblies’). The option you choose will simply depend on your needs.
How can I print my rich text
There is no direct support for printing rich text in the .NET Framework. To print it, you can use interop with the SendMessage API and these three messages to do your printing. EM_SETTARGETDEVICE : specify the target device EM_FORMATRANGE : format part of a rich edit control’s contents for a specific device EM_DISPLAYBAND : send the output to the device Here is a link to a MSDN article by Martin Muller that implements this interop solution. Getting WYSIWYG Print Results from a .NET RichTextBox
How to retrieve the assembly version, name, etc. contained in the ‘AssemblyInfo.cs’, from inside the running app?
Here is a way to do this: 1) string strVersion = Application.ProductVersion; 2) Assembly assembly = Assembly.GetCallingAssembly(); string strVersion = assembly.GetName().Version.ToString(); The Application class offers also access to additional information like ProductName and so on. (Information provided by Holger Persch in our forums)