public static void MoveSplitterToLongestDisplayName(PropertyGrid propertyGrid, int iPadding) { try { Type pgObjectType = propertyGrid.SelectedObject.GetType(); string longestDisplayName = ""; // Iterate through all the properties of the class. foreach (PropertyInfo mInfo in pgObjectType.GetProperties()) { // Iterate through all the Attributes for each property. foreach (Attribute attr in mInfo.GetCustomAttributes(typeof(DisplayNameAttribute), false)) { if (attr.GetType() == typeof(DisplayNameAttribute)) { DisplayNameAttribute displayNameAttr = (DisplayNameAttribute)attr; if (displayNameAttr.DisplayName.Length > longestDisplayName.Length) { longestDisplayName = displayNameAttr.DisplayName; } } } } Size textSize = TextRenderer.MeasureText(longestDisplayName, propertyGrid.Font); PropertyGridManipulator.MoveSplitter(propertyGrid, textSize.Width + iPadding); } catch (Exception exception1) { MessageBox.Show(exception1.Message); //do nothing for now -- //if exception was thrown the private method MoveSplitterTo //of the C# version 2.0 framework's PropertyGrid's //PropertyGridView probably is no //longer named the same or has a different //method signature in the current C# framework } }
private void AdjustView() { //PropertyGridManipulator.ResizeDescriptionArea(this, -1); PropertyGridManipulator.MoveSplitter(this, 110); }