How do I change my application’s icon
In the Solution Explorer window, you’ll see a file called app.ico in your project. This file contains your application icon. You can change this to a different file in the project properties screen which you see by right-clicking the project node in the Solution Explorer, and selecting Properties..
How do I use the OpenFileDialog
using System.Text; using System.IO; …. private void button1_Click(object sender, System.EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = ‘Open text file’ ; dlg.InitialDirectory = @’c:\’ ; dlg.Filter = ‘txt files (*.txt)|*.txt|All files (*.*)|*.*’ ; if(dlg.ShowDialog() == DialogResult.OK) { StreamReader sr = File.OpenText(dlg.FileName); string s = sr.ReadLine(); StringBuilder sb = new StringBuilder(); while (s != null) { sb.Append(s); s = sr.ReadLine(); } sr.Close(); textBox1.Text = sb.ToString(); } }
How do I make my textbox use all upper (or lower) case characters
Use the CharacterCasing property of the TextBox. textBox1.CharacterCasing = CharacterCasing.Upper; // textBox1.CharacterCasing = CharacterCasing.Lower;
How can I allow my user to add more than 1 type of object to my collection, during design-time?
The default CollectionEditor will allow your user to add objects of type returned by your collection’s indexer method. You can make this CollectionEditor allow your user to pick the type of object to add by deriving from CollectionEditor and making the change as shown below. This will introduce a drop-down in the editor’s ‘Add’ button to allow the user to pick the type he wants to add. public class CustomCollectionEditor : System.ComponentModel.Design.CollectionEditor { private Type[] types; public CustomCollectionEditor(Type type) : base(type) { types = new Type[]{typeof(ItemType1), typeof(ItemType2), typeof(ItemType3), typeof(ItemType4)}; } // Return the types that you want to allow the user to add into your collection. protected override Type[] CreateNewItemTypes() { return types; } } [Editor(typeof(CustomCollectionEditor), typeof(UITypeEditor))] public class CustomCollection : IList { … }
I am populating a ListBox by binding it to an ArrayList. The initial display is OK, but later changes to my ArrayList are not shown in my ListBox. How can I get the changes to show properly
In an ArrayList, the ’plumbing’ is not available to support two-way binding as with a dataset. So, you have to handle the synchronization yourself. One way to do this is to set the listBox1.DataSource to null and then reset it to your ArrayList. Another way is to use the CurrencyManager as shown in the code below. private System.Windows.Forms.ListBox listBox1; private System.Windows.Forms.Button button1; private ArrayList myArrayList; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); myArrayList = new ArrayList(); myArrayList.Add(‘orange’); myArrayList.Add(‘green’); myArrayList.Add(‘blue’); myArrayList.Add(‘red’); listBox1.DataSource = myArrayList; } …… //change the arraylist private void button1_Click(object sender, System.EventArgs e) { myArrayList[1] = ‘pink’; myArrayList.Add(‘lavendar’); //use currency manger to sync up the listbox BindingManagerBase bm = this.listBox1.BindingContext[myArrayList]; CurrencyManager cm = (CurrencyManager) bm; if (cm != null) cm.Refresh(); //Or, you can just reset the datasource //listBox1.DataSource = null; //listBox1.DataSource = myArrayList; }