What class or method do I use to retrieve system metrics like the width of a scrollbar
In the .NET framework, you use the SystemInformation class from the System.Windows.Forms namespace. This class has comparable information to what GetSystemMetrics() returned in VC6. There is also a Screen class that contains additions display device properties.
How can I tell if an ALT, Shift or CTL key is pressed without catching an event
Use the static property Control.ModifierKeys. Console.WriteLine(Control.ModifierKeys); if( (Control.ModifierKeys & Keys.Shift) != 0) Console.WriteLine(‘the shift key is down’); if( (Control.ModifierKeys & Keys.Alt) != 0) Console.WriteLine(‘the alt key is down’); if( (Control.ModifierKeys & Keys.Control) != 0) Console.WriteLine(‘the control key is down’);
How do I convert a string to a double or int? What plays the role of atof and atoi in C#
You use static members of the Convert class found in the System namespace to handle conversions in the .NET framework. string s = ’45’; int h = Convert.ToInt32(s); double d = Convert.ToDouble(s);
How do I set the width of a combobox to fit the entries in its list
You can iterate through the list to find the longest text extent using MeasureString, and then use this as the combobox width adding a fudge factor for the dropdown button. System.Drawing.Graphics g = comboBox1.CreateGraphics(); float maxWidth = 0f; foreach(object o in comboBox1.Items) { float w = g.MeasureString(o.ToString(), comboBox1.Font).Width; if(w > maxWidth) maxWidth = w; } g.Dispose(); comboBox1.Width = (int) maxWidth + 20; // 20 is to take care of button width
How do I display checkboxes in the nodes of a treeview
Set the TreeView.CheckBoxes property to true.