By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,346 Members | 2,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,346 IT Pros & Developers. It's quick & easy.

Clicking buttons and opening forms

P: 2
Hi.

How about helping a novice...

In c# I have Form1 and Form2.
On Form1 I also have one button. When I click that button, IŽd like it to open Form2 - now how do I get about that...As I say....im REAL new to this..

So far...all this has been, is drag and drop i VS, not much code yet
Apr 23 '07 #1
Share this Question
Share on Google+
3 Replies


radcaesar
Expert 100+
P: 759
In the click event of that button

Form frm2=new Form2();
frm2.ActiveForm.show();
Apr 23 '07 #2

P: 2
I get this Error

'System.Windows.Forms.Form' does not contain a definition for 'ActiveForm'

This is what I have
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8.  
  9. namespace DeviceApplication1
  10. {
  11.     public partial class Form1 : Form
  12.     {
  13.         public Form1()
  14.         {
  15.             InitializeComponent();
  16.         }
  17.  
  18.         private void button1_Click(object sender, EventArgs e)
  19.         {
  20.             Form frm2 = new Form2();
  21.             frm2.ActiveForm.show();
  22.  
  23.         }
  24.     }
  25. }
  26.  
Apr 23 '07 #3

prabunewindia
100+
P: 199
try this

Form frm2=new Form2();
frm2.show();
Apr 24 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.