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.
How do I return values from a form
Add public properties to your form. Then these properties can be accessed by any object that creates an instance of your form.
When I try to set a particular font style, say italics, I get an error message ‘Property cannot be assigned to — it is read only’. How can I set this read only property
Code such as tabControl1.Font.Italic = true; will not work. Instead, you have to create a new Font object, and set the property during its creation. This code will work. tabControl1.Font = new Font(tabControl1.Font, FontStyle.Italic);