- To open any form at run time programmatically, you require to create an object for the form class.
obj.Show( );
Example for Invoking a Form Programatically
- Create a New windowsForms Application i.e.WABasics
- Create two Forms Form1,Form2
- Goto Form1 and generate the EventHandler for Form1 Click Event goto Source i.e.,Form1.cs And write the following Code
using System;
using
System.Collections.Generic;
using
System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using
System.Windows.Forms;
namespace WABasics
{
public partial class Form1 : Form
{
public
Form1( )
{
InitializeComponent();
}
private
void Form1_Click(object
sender, EventArgs e)
{
Form2
obj1 = new Form2();
obj1.Show();
}
}
}
|
Output :-
After Clicking on Form1
No comments:
Post a Comment