Tuesday, February 25, 2014

New Login Form and Controls

Setting tabs order of a form controls

While working with a windows application, we navigate between controls using tab key of key board. By default tab key navigate the focus b/w controls in the same order how to. If we want to set the sequence of tab on our own, it can be done by setting the tab order. To do this goto view menu and select tab order, which shows the current tab sequence. Now click on each control sequentially, in the way we want to move the tabs again goto view menu and select tab order

AcceptButton and CancelButton properties of Form:-

Form control has the above two properties, which allow us to map button on a form with Keyboard keys.

- AcceptButton property if set with a button that button gets clicked, whenever we press enter key of keyboard.

- CancelButton property is set with a button that button gets clicked, whenever we press ESC key of keyboard.

- Procedure to set these two properties --> open the property window of form and under accept button choose the button btnLogin and under CancelButton choose the button btnCancel.

- In the above form, perform the following validation.
  1. Check username and password text box are mandatory field.
  2. Password should be ranging b/w 5 – 10 character.
  3. Allow the users to close the form even without entering any data.
- To do the above validation go to the form properties of password text box and set its max length property as 10, so that it will not allow more then 10 character.
- Now define a validation event procedure for user name text box and bind the event procedure as pwdTextBox also, and then write the following code under the event procedure.
TextBox tb  = sender as TextBox;
if (tb.Text.Trim().Length == 0)
 {
      MessageBox.Show(“Can not Leave empty”);
     e.Cancel = true;
      return;
 }

  if (tb.Name == “txtPwd”)
  {
     if (tb.Text.Trim().Length < 5)
   {
      MessageBox.Show(“Pwd should be ranging between 5-10 char”);
      e.Cancel = true;
   }
  }

- Validation event fires when the control is leaving its focus to validate the content of the control.

No comments: