Wednesday, September 26, 2007

C# Tips

I am working in C# 2005

1.Modal Dialog and Modeless Dialog in C#
2.C# MDI forms
3.Opening the Chm file
4.CheckOnClick property in a menuitem
 set the Checked property as true or false

Modal Dialog and Modeless Dialog in C# :
-------------------------------------------------------------
if we are having Two Forms in our Project,  From the  Form1, we will display the Form2 as Modal and Modeless dialog.

Class Form2
{

}

class  Form1
{
     void btnShowForm2_Click()
     {
 Form2 frm = new Form2();

 frm.Show() ;// For Modeless Dialog
 frm.ShowDialog() ;//  This is for Modal dialog
 
     }
}

2.C# MDI forms
----------------------
     From Main Form, we will create the another Form means
this can be made as MDI forms.

 Wecan display more than one forms at a time in MDI forms.

For the parent Form, we have to enable the IsMdiContainer property as true.

and then drill down in to the coding as follows :

 class ChildForm
 {
 }
 class ParentForm
 {
  
  //this.IsMdiContainer = true;

  private void mnuShowChildForm_Click()
  {
   ChildForm frm = new ChildForm();
   frm.MdiParent = this;
   frm.Show();
  }
 }


Only MdiParent property of the child form is set to the Parent form's Object.

 
3. Sometimes we faced the problem in opening chm files content display problem.

while opening the chm file, sometimes it displays the dialog with "always ask before opening this file"  check box.

if this check box is not selected by us then it will not display the chm contents. So To display the chm file contents, we must enable

"always ask before opening this file"  check box.

4.CheckOnClick property in a menu item  Sometimes we may need Checked property in a menuitem. For Instance, if the user selects the menuitem then it will show the Checked mark in a menuitem and if we select once again, the checkbox will
not be shown. this selection process takes place continously like Toggle on or off.

 
 For Doing this one, the menu item is having the property CheckOnClick .

if we enable this property, then we can display the check mark and we can change the execution behavior also based on the check mark.

 CheckedState property is set to true or false based on whether the check  mark is currently displayed in a menuitem or not.

This feature can be aptly used in the following Scenario.

 if we have MDI parent form, based on the checked selection of the menuitem we have to display the MDI child form.


if the menuitem is selected for the first time, we have to display the child form. if the menuitem is selected once again, then the child form must be

hided...

 By default set the menuitem's CheckOnClick property as true and Checked property as false.

  For doing this one , add the menu event handler as follows :

 void mnuShowChildForm_Click()
 {
  if( mnuShowChildForm.Checked == true)
  {
   childFormObject.Show();
  }
  else
  {
   childFormObject.Hide();
  }
 }
 

 

 

No comments: