Visit

Saturday, August 27, 2011

Display WinForm as Modal and Modeless

Forms and dialog boxes are either modal or modeless. A modal form or dialog box must be closed or hidden before you can continue working with the rest of the application.

To display a form as a modal dialog box ..Call the ShowDialog method.

The following example shows how to display a dialog box modally.

// C#
//Display frmAbout as a modal dialog
Form frmAbout = new Form();
frmAbout.ShowDialog();

# Use ShowDialog() method instead of Show() method.

Friday, August 19, 2011

How to use Shortcut Key in C Sharp (C#) Programm

How to use Shortcut Key in C Sharp (C#) Programm.

I am created 2 forms using c# (Form A and Form B). From Form A i want to open Form B when I press a Key from Keyboard (F2).

Steps

1. Set Form A KeyPreview Property to True.
2. Write needed code in Form A KeyDown Event.


private void A_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F2)
{
new B().Show();
}
}

Done...Check it out.

Wednesday, August 10, 2011

TreeView Node Click Event in CSharp (C#)


In TreeView We need to Do any operation when a node clicked or selected.We can't trigger an event with the name of Node. We have to do it by triggering Tree Views Event.In this example i am used 'NodeMouseClick' Event.

1. Add a TreeView Control to your Form.
2. Add the Needed Nodes .
3. Now Double Click on TreeViews 'NodeMouseClick' Event.

4. Now Compare with Node.Name or Node.Text in the Event.just see the Code below.


private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
// Compare By Node.Name
if (e.Node.Name == "NodeJava")
{
MessageBox.Show("JAVA");
}
//Or
// Compare By Node.Text
if (e.Node.Text == "C#")
{
MessageBox.Show("C#");
}
}


*'NodeJava' is the Node Name ..and 'C#' is the Node Text in my example Code.I am just checking and showing the result in a MessageBox.
Checkout and Do Comment Here..