Create a notepad using C# and windows form
In this article I am going to describe some common control available in the C# and using these controls we design our own Notepad in C# with some advance feature like launch the html page directly in the browser by just one click, send email from the notepad via outlook or other email service installed in your computer and search selected text in google and Wikipedia etc. .
Some common controls used in mynotepad development are given bellow:
- Rich Textbox :Rich Textbox is an advanced textbox control with very interactive features and large number of properties. It supports the RTF (Rich Text Format) format. Rich textbox have some advance properties and it is in multiline mode by default . To use the Rich Textbox in the project the assembly required to refer is PresentationFramework (in PresentationFramework.dll) and the namespace is System.Windows.Control . Bellow I am going to describe some of its properties that we use in our project:
- Context menu strip: By this property we can get or set the context menu element that should appear whenever the context menu is requested by the user. Context Menu strip is explained letter.
- Cursor: Get and set the cursor that displays when the mouse pointer is over this element. In this project we set its value as IBeam . Other than IBeam there are many options like arrow, cross, default etc. .
- Dock: This property define automatically resize the control when the size of the parent container is changed. For our project we the value of this property as fill.
- Tooltip: Get or set the tool tip object that is displayed for this element in the user interface (UI).
These are some properties that we handle when in our project. There are many other properties of Rich Textbox that we explain when we need it.
- Menu Strip: The next control is menu strip that we use in our project. The menu strip adds the menu bar in Windows form ,we add menu area and then add default menus and create custom menus directly in visual studio. The assembly required for this control is System.Windows.Form(in System.Windows.Form.dll) an namespace is System.Windows.Form . We can add menu strip directly by drag and drop or at run time.
Picture given bellow shows how the item is added in the Menu Strip.
You can also add the items in menu strip by the wizard as shown bellow:
Note: Use & before the menu key to use hot keys. For example type &File in place of file in menu item. Than we can access this by pressing CTRL+F key on key board .
- Tool strip: The next control is tool strip that we use in our project. Tool Strip provide container for windows toolbar object.
The use of this can be shown as :
- Status Strip : The next control used is status strip. It is used to show some quick help and control to the user (at the bottom of notepad shows line number and column number). The C# status strip allow you to add label , progress bar and button also.
Now all the basic tool required to design the layout of the notepad have been covered. Bellow the steps to develop own customized notepad is given
- Open Visual Studio and create a new project by giving it an appropriate name.
- Now change the following properties of the Form1 that is default form.
- Give it a name.
- Set backcolor as control .
- Add appropriate icon by giving the path for icon property and set its size .
- Set the windowstate property as maximize so whenever the form runs it covers the complete screen.
- Set the text of form as Untitled Untitled-My Notepad, that we change at run time.
Now the the parent container is ready .
Drag and drop the Rich Textbox from the toolbox in the form and from properties window change its properties as
- Set only the dock property as fill so the size of Rich Textbox is changed according with size of the form.
Now Form look like as
- Now drag and drop the MenuStrip control from the control window and add the required menu items and their icons.
- Now add ToolStrip control from the toolbox and insert the required items with icons in it.
After the addition of the above control our form looks like as :
In the next few articles I will explain the code for each functionality and also attach the program code with the article
Please give your valueable suggestion and feedback.