locked
Buttons on main page RRS feed

  • Question

  • I have 2 buttons on my main page and I want them to open their respective pages when clicked. Im new to this so how would I go about doing this.
    Monday, May 17, 2010 3:07 PM

Answers

All replies

  • Hi,

    I assume that 'page' in your question means a windows form in a smart device project.

    Try the following code.

    using System;
    using System.Windows.Forms;
    
    namespace SmartDeviceProject1
    {
      public partial class MainForm : Form
      {
        private System.ComponentModel.IContainer components = null;
        private System.Windows.Forms.MainMenu mainMenu1;
    
        protected override void Dispose(bool disposing)
        {
          if (disposing && (components != null))
          {
            components.Dispose();
          }
          base.Dispose(disposing);
        }
    
        #region Windows Form Designer generated code
    
        private void InitializeComponent()
        {
          this.mainMenu1 = new System.Windows.Forms.MainMenu();
          this.button1 = new System.Windows.Forms.Button();
          this.button2 = new System.Windows.Forms.Button();
          this.SuspendLayout();
          // 
          // button1
          // 
          this.button1.Location = new System.Drawing.Point(17, 31);
          this.button1.Name = "button1";
          this.button1.Size = new System.Drawing.Size(72, 20);
          this.button1.TabIndex = 0;
          this.button1.Text = "Form1";
          this.button1.Click += new System.EventHandler(this.button1_Click);
          // 
          // button2
          // 
          this.button2.Location = new System.Drawing.Point(122, 31);
          this.button2.Name = "button2";
          this.button2.Size = new System.Drawing.Size(72, 20);
          this.button2.TabIndex = 1;
          this.button2.Text = "Form2";
          this.button2.Click += new System.EventHandler(this.button2_Click);
          // 
          // MainForm
          // 
          this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
          this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
          this.AutoScroll = true;
          this.ClientSize = new System.Drawing.Size(240, 268);
          this.Controls.Add(this.button2);
          this.Controls.Add(this.button1);
          this.Menu = this.mainMenu1;
          this.Name = "MainForm";
          this.Text = "MainForm";
          this.ResumeLayout(false);
    
        }
        #endregion
    
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Button button2;
        public MainForm()
        {
          InitializeComponent();
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
          Form1 frm1 = new Form1();
          frm1.Show();
          this.Hide();
        }
    
        private void button2_Click(object sender, EventArgs e)
        {
          Form1 frm2 = new Form1();
          frm2.Show();
          this.Hide();
        }
      }
    }
    Monday, May 17, 2010 3:51 PM
  • I'm using Windows phone application and i added portrait pages instead of forms because i haven't been given the option to add windows forms to my application. I'm using visual studio 2010 express and downloaed the developers kit from the microsoft website.
    Tuesday, May 18, 2010 2:28 AM
  • It looks like that you are developing applications for Windows Phone 7. If so I suggest that you ask the question in the Windows Phone 7 forum for better help: http://social.msdn.microsoft.com/Forums/en-US/windowsphone7series 
    Please mark the post that helps you, and unmark that does not. This benefits our community.
    • Marked as answer by warrentang Friday, May 21, 2010 2:45 AM
    Wednesday, May 19, 2010 6:07 AM