How do color the tabs on my TabControl

Ken Tucker offers this solution. Set the TabControl’s DrawMode to OwnerDraw, and then handle the DrawItem event to draw things yourself. Here are both VB and C# sample projects that display a gradient tab for the active tabpage.

How can I put Controls, a ProgressBar for example, into a StatusBar?

You cannot place controls into a StatusBar control in the designer. However, you can add any no. of Controls to the StatusBar programatically through it’s Controls property. After adding the Controls, set their Visible, Location and Bounds property appropriately. You could then create a status bar that looks like this, for example:

How do I implement an ownerdrawn listbox

Check out this sample project at gotnetdot.com. It derives from Form and implements the owner drawing by handling the DrawItem event and MeasureItem event. You can also download a sample that implements an owner drawn listbox by deriving from ListBox and overriding the virtual methods OnDrawItem and OnMeasureItem. Here is a OnDrawItem override that draws colored rectangles in the listbox. protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { //undo the selection rect on the old selection if( oldSelectedRect != e.Bounds && oldSelectedIndex > -1 && oldSelectedIndex < Items.Count) { e.Graphics.DrawRectangle(new Pen((Color) Items[oldSelectedIndex], 2), oldSelectedRect); } //draw the item .. here we just fill a rect if( e.Index > -1 && e.Index < Items.Count) e.Graphics.FillRectangle(new SolidBrush( (Color)Items[e.Index] ), e.Bounds); //draw selection rect if needed if(SelectedIndex == e.Index) { e.Graphics.DrawRectangle(new Pen(Color.Black,2), e.Bounds); oldSelectedRect = e.Bounds; oldSelectedIndex = e.Index; } }

How can I change the FontStyle of a selection without losing the styles that are present

If you visit the selection a character at the time, you can get the current FontStyle and modify it directly to add or remove a style like Bold or Italic. Doing it a character at a time will avoid losing the other styles that are set. The problem with doing it a whole selection at a time is that the FontStyle of the entire selection is the common styles set among all characters in the selection. So, if one char is bold and one is not, then bold is not set when you retrieve the fontstyle for the entire selection. Doing things a character at the time, avoids this problem and allows things to work OK. You can download a working sample(CS,VB). private void AddFontStyle(FontStyle style) { int start = richTextBox1.SelectionStart; int len = richTextBox1.SelectionLength; System.Drawing.Font currentFont; FontStyle fs; for(int i = 0; i < len; ++i) { richTextBox1.Select(start + i, 1); currentFont = richTextBox1.SelectionFont; fs = currentFont.Style; //add style fs = fs | style; richTextBox1.SelectionFont = new Font( currentFont.FontFamily, currentFont.Size, fs ); } } private void RemoveFontStyle(FontStyle style) { int start = richTextBox1.SelectionStart; int len = richTextBox1.SelectionLength; System.Drawing.Font currentFont; FontStyle fs; for(int i = 0; i < len; ++i) { richTextBox1.Select(start + i, 1); currentFont = richTextBox1.SelectionFont; fs = currentFont.Style; //remove style fs = fs & ~style; richTextBox1.SelectionFont = new Font( currentFont.FontFamily, currentFont.Size, fs ); } } private void button1_Click(object sender, System.EventArgs e) { AddFontStyle(FontStyle.Bold); } Here is a suggestion from Nicholas Clark on how to avoid seeing the character by character changes appear as you apply the styles one character at a time in the above code. Create a hidden RTB and store the selected text in it. Then apply the attributes and copy it back into the original richtextbox, so that you don’t see the selection changing. private void change_font(FontStyle style,bool add) { richTextBox2.Rtf = richTextBox1.SelectedRtf; int lengt = richTextBox2.Text.Length; int length = richTextBox1.SelectionLength; int start = richTextBox1.SelectionStart; for (int i = 0; i < lengt; i++) { richTextBox2.Select(i,1); Font cfont = richTextBox2.SelectionFont; FontStyle fs = cfont.Style; if (add) { fs = fs | style; } else { fs = fs & ~style; } richTextBox2.SelectionFont = new Font( cfont.FontFamily, cfont.Size, fs ); } richTextBox2.Select(0,richTextBox2.Text.Length); richTextBox1.SelectedRtf = richTextBox2.SelectedRtf; richTextBox1.Select(start,length); this.richTextBox1.Focus(); isChanged = true; }

How can I create and save a RTF file

One way to do this is to use the RichTextBox.SaveFile method. private void button1_Click(object sender, System.EventArgs e) { // Create a SaveFileDialog & initialize the RTF extension SaveFileDialog saveFile1 = new SaveFileDialog(); saveFile1.DefaultExt = ‘*.rtf’; saveFile1.Filter = ‘RTF Files|*.rtf’; // get a file name from the user if (saveFile1.ShowDialog() == DialogResult.OK) { // Save the RTF contents of the RichTextBox control that // was dragged onto the Window Form and populated somehow richTextBox1.SaveFile(saveFile1.FileName, RichTextBoxStreamType.RichText); //use to save RTF tags in file //RichTextBoxStreamType.PlainText);//use to save plain text in file } }