Hunt

Tuesday, April 27, 2010

WINDOWS APPLICATION COMMON FUNCTIONS..

add a class from solution explorer

and then paste this code

to clear all textbox values in winforms
--------------------------------------------------
vb.net
------------------
Public Sub ClearForm(ByVal Frm As Form, Optional ByVal All As Boolean = True)
Dim Ctr As Control
If All Then
For Each Ctr In Frm.Controls
If TypeOf Ctr Is TextBox Then
Ctr.Text = ""
End If
Next
End If
End Sub
--------------------------------------------------
IN FORM1

Dim s As New Class1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
s.ClearForm(Me)

End Sub
-------------------------------------------------

URL
http://www.devx.com/tips/Tip/30880
------------------------------------------------


C#
-----------------------------------------------
add a class from solution explorer

and then paste this code

using System.Windows.Forms;
public void ClrCrlVal(System.Windows.Forms.Control Container)
{
try
{
foreach (Control ctrl in Container.Controls)
{
if (ctrl.GetType() == typeof(TextBox))
((TextBox)ctrl).Text = "";
if (ctrl.GetType() == typeof(ComboBox))
((ComboBox)ctrl).SelectedIndex = -1;
if (ctrl.GetType() == typeof(CheckBox))
((CheckBox)ctrl).Checked = false;
if (ctrl.GetType() == typeof(Label))
((Label)ctrl).Text = "";
if (ctrl.GetType() == typeof(DateTimePicker))
((DateTimePicker)ctrl).Text = "";
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
-----------------------------------------------------

IN FORM

private void button1_Click(object sender, EventArgs e)
{
Class1 c = new Class1();
c.ClrCrlVal(this);
}
-----------------------------------------------

No comments:

Post a Comment