ContextMenuStrip

Context menus are appeared when user right-click. They looks like a floating menu. Different context menus can be displayed in a form based on the location where user has clicked. Multiple context menus can be created and they has to be assigned to specific controls in the form.

Default Event: Click which is fired when user click on the item in the contextmenustrip.

Property: For every control including form a propery called contextMenuStrip will be present which is used to assign a context menu strip to it which is displayed when user right click on that control in the run time.

Steps to create context menu strip

Drag and drop a contextmenustrip control to the form which is displayed at the bottom panel of the form but also shows up auto generated textboxes at the top of the form to add items.
You can create the context menu strip items just by adding text in the automatically generated textboxes which are displayed at the top of the form.
Double click on the each item to see the generated event handler of that specific item and you can create event handler for each item to write some code that has to be executed when you click on that item in the runtime.

For every control including Form will have a property called contextMenuStrip where you can add context menu strip name which has to displayed when user right click on that control.

Example code to copy and paste content of a text box by using context menu present on form
Create a context menu with 3 items – Copy, Paste and clear
Create a textbox and assign context menu to the form.

  string s = string.Empty;
        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            s = textBox1.Text;
        }

        private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Text = s;
        }

        private void clearToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";

        }
Thursday, 18 February 2016
Posted by Sudhir Chekuri

ToolStrip

It is a menu present at the top of the form which is capable of hosting Button, Label, SplitButton, DropDownButton, Separator, ComboBox, TextBox and ProgressBar controls.

Default Event: Click which is fired when user click on the controls in toolbox.

Steps to create ToolStrip

Drag and drop a ToolStrip control to the form which is displayed on the bottom panel of the form but also shows up the dropdown with list of controls at the top of the form.
You can use the dropdown available at the top of the form to select and add controls in the ToolStrip which is present at the top of the form.
Double click on the ToolStrip item to see the generated event handler of that specific item and you can create event handler for each item to write some code that has to be executed when you click on that item in the runtime.

Example to display message box when you click on ToolStrip item
private void toolStripComboBox1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("You selected combo box in toolstrip");
        }

        private void toolStripLabel1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("You selected label in toolstrip");

        }
Posted by Sudhir Chekuri

MenuStrip

MenuStrip adds a menu bar at the top of the windows form.

Default Event: Click which is fired when you click on that specific menuitem. Each item will have its own click event.

Steps to create a MenuStrip

Drag and drop a menustrip control to the form which is displayed on the bottom panel of the form but also shows up auto generated textboxes at the top of the form to add items.
You can create the menu items just by adding text in the automatically generated textboxes which are displayed at the top of the form.
Double click on the menu item to see the generated event handler of that specific item and you can create event handler for each item to write some code that has to be executed when you click on that item in the runtime.

Example code to show a message box with the text on the menu item
private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show(newToolStripMenuItem.Text);
        }

        private void projectToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show(projectToolStripMenuItem.Text);

        }
Posted by Sudhir Chekuri

TabControl

Controls are displayed under different tabs.
Different controls can be displayed in the same location and with the selection of tab controls inside that tab are displayed in the runtime.
Wednesday, 17 February 2016
Posted by Sudhir Chekuri

SplitContainer

Divides a container’s display area into two resizable panels to which you can add controls.

You can drag and drop controls into one of the two container and in the runtime the panels can be resized.
Posted by Sudhir Chekuri

GroupBox

Displays a frame around the controls with an optional caption. The frame of the groupbox will be visible in the output.

Properties:

Text: The text that is displayed as the caption on groupbox control in output.

Steps to use a panel

Drag and drop a group box
Add controls inside it.
Arrange them relatively inside the group box.
Now you can arrange the group box in a form which brings all the controls inside it without any change in their relative distances of controls inside it.

Default Event: Enter which is fired when groupbox become active by using control inside it.

Code to change text of groupbox when user enters selects a textbox inside it
private void groupBox1_Enter(object sender, EventArgs e)
        {
            //Place a textbox inside Groupbox and click inside it
            groupBox1.Text = "GroupBox Text";

        }
Posted by Sudhir Chekuri

FlowLayoutPanel

It is capable of holding multiple controls inside it and it will arrange them in automatically an order.

Properties:

FlowDirection: Specifies the direction in which controls are laid out.

Example: LeftToRight, RightToLeft, TopDown, BottomUp

WrapContents: Set to wrap controls inside it or false to make controls go outside the border of the panel.

Steps to use FlowLayoutPanel
Drag and drop a FlowLayoutPanel.
Then drag and drop controls into FlowLayoutPanel and you can see that they are automatically arrange in an order.

Default Event: Paint which is fired when it is created

Code to change the FlowDirection when it is created
private void flowLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {
            flowLayoutPanel1.FlowDirection = FlowDirection.RightToLeft;

        }
Posted by Sudhir Chekuri

Followers

Total Pageviews

Powered by Blogger.

- Copyright © 2013 DevStudent - Metrominimalist - Powered by Blogger - Designed by Johanes Djogan -