Pages

Saturday, October 25, 2008

how to trap "delete" key event in C#

"delete" key is a special, it has different function from other key. That's why we can't use ordinary key down / key press event. For example, I have richTextBox called "rtbInput", pictureBox called "picLine" and I want to update line number whenever user delete some text. This is my code to do that :

private void rtbInput_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
            if(e.KeyCode == Keys.Delete )                 
                LineNumber.DrawLineNumber(picLine.CreateGraphics(), rtbInput, picLine); 
    //this is my function to draw line number
}
note that function named "rtbInput_PreviewKeyDown" means I attached this handler to previewKeyDown event of the richTextBox.

Wednesday, October 15, 2008

manually create table of figures

You may want to include table of figures or table of tables but you cannot do automatically. This steps will show how to add table of figures (TOF for short).
  1. block the caption of your picture, on "insert" tab, click "bookmark". A bookmark dialog will shows up.
  2. add the bookmark name. Make sure to insert the name that represent the picture. Example : name "pic2_1" for picture 2.1, "pic2_11" for picture 2.11, "pic2_1_1" for picture 2.1.1
  3. click "add". this will insert your bookmark to the bookmark table ( until now, I can't find the way view that table). If you found "add" disabled, it means you insert wrong character for bookmark name
  4. set your tabs. right-click on your documents and select "paragraphs....", click "tabs". The "tabs" dialog will shown.
  5. add your tab stop. Insert position, set the alignment and leader, click set. Do this for each tab-stops. for example mine use 2,75 cm, left, leader : 1, and 15,5 cm, right, leader : 2. second tab is used for entering "......" between name and page number and to ensure the page number are "right aligned".
  6. you can insert page number for your table entry by clicking "cross-reference" at "insert" tab. This will show reference dialog. select "reference type" as bookmark and "insert reference to" as page number (you want to insert page number). Select bookmark and click insert. note that you must insert page number at the page where the bookmark located. if you're not, the number will not shown up.
  7. don't edit the page number manually because it will updated before printing and makes your editing useless.
  8. you can update manually by right-clicking near page number and select "update field".
This is my TOF entry for example, look for tab stops :




easy creating table of contents

If you writing a experiment report or something,
maybe you want to include table of contents (or TOC for short) for you report. I'l show you how..... First thing first, after everything is set, you must insert page number, don't forget that. This is my example. After do that, follow all steps below :
  1. block the word you want to use as entry word on TOC. Like below....
  2. on "references" tab, click "Add text"
  3. select the level you want. For example, in picture above, I'm using "chapter I" as level 1 in table of contents, "1.Subchapter" as level 2, "a. subchapter" as level 3.
  4. If you found the word you've selected changed. You can change manually. Or, you can modify "Heading 1 default" right-click on "heading1" at "home" tab. This is the default format for level 1 heading (you can change later after adding TOC).
  5. after you have entered all entry word, try to view your document map.
  6. If you see unwanted entry on your document map, just click on your map to jump on tha entry. Block that word, on "references" tab, click "Add text". You will found that corresponding level is cheked. Simple check "do not show in table of content". This will remove from entry. just check on your document map.
  7. If all set, jump to page you want the TOC to be inserted. On "references" tab, click "table of contents" and select "automatic table".
  8. After you've edit some pages, you may want to update your TOC. you can do this by clicking "update", it usually located at the top of your TOC.
  9. you can change the format of your table entry, but do this after you've update your entire table.
  10. You can change heading for your TOC by clicking "table of contents" on "references" tab and selecting "insert table of contents". this will show "TOC" dialog. Click "modify" button. Select the level you want, click "modify". On "style based on" you can select from heading if you've change the default heading or just simply edit the format.
thats all. Now you have a TOC.

how to insert page number with different format?

sometimes you want to insert different page number format, for example on several pages with format : i, ii, iii, and several pages with number like: 1,2,3. You can do that by following steps below :
  1. put your cursor at the end of page.
  2. select "page layout" tab, click "breaks", select "next page".
  3. on next page, double click header (and footer).
  4. unmark "link to previous". this make your header (and footer) not same as previous page.
  5. thus, changing page number in this page doesn't change page number in previous page .