943,691 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1586
  • C++ RSS
Jun 11th, 2007
0

How to link Buttons in C++.NET?

Expand Post »
How to link Buttons in C++.NET?
Example:
If I want to link "Button1" which is in "Form1" to "Form2", like if you click "Button1" in "Form1", the program will goto "Form2". What source code should I input?
Similar Threads
Reputation Points: 8
Solved Threads: 1
Junior Poster in Training
ongxizhe is offline Offline
68 posts
since Mar 2007
Jun 11th, 2007
0

Re: How to link Buttons in C++.NET?

Handle the click event for both buttons and in the event handler call the BringToFront method of the form you want to go to. I don't know your form setup, so I can't offer any more advice than that.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Jun 11th, 2007
0

Re: How to link Buttons in C++.NET?

I need to link the "Button1" from "Form1" to "Form2"

Form1:
Quote ...
#pragma once

namespace Botz0004 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::MaskedTextBox^ maskedTextBox1;
private: System::Windows::Forms::Button^ button1;
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->label1 = (gcnew System::Windows::Forms::Label());
this->maskedTextBox1 = (gcnew System::Windows::Forms::MaskedTextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->FlatStyle = System::Windows::Forms::FlatStyle::Popup;
this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label1->Location = System::Drawing::Point(73, 59);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(147, 16);
this->label1->TabIndex = 0;
this->label1->Text = L"What is your name\? ";
this->label1->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
//
// maskedTextBox1
//
this->maskedTextBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->maskedTextBox1->Location = System::Drawing::Point(30, 127);
this->maskedTextBox1->Name = L"maskedTextBox1";
this->maskedTextBox1->Size = System::Drawing::Size(233, 20);
this->maskedTextBox1->TabIndex = 1;
this->maskedTextBox1->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
//
// button1
//
this->button1->Location = System::Drawing::Point(105, 179);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(84, 23);
this->button1->TabIndex = 2;
this->button1->Text = L"Next";
this->button1->UseVisualStyleBackColor = true;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 270);
this->Controls->Add(this->button1);
this->Controls->Add(this->maskedTextBox1);
this->Controls->Add(this->label1);
this->Name = L"Form1";
this->Text = L"Botz0004";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
};
}

Form2:
Quote ...
#pragmaonce

namespace Botz0004 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>

/// Summary for Form1

///

/// WARNING: If you change the name of this class, you will need to change the

/// 'Resource File Name' property for the managed resource compiler tool

/// associated with all .resx files this class depends on. Otherwise,

/// the designers will not be able to interact properly with localized

/// resources associated with this form.

/// </summary>

public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//

//TODO: Add the constructor code here

//

}
protected:
/// <summary>

/// Clean up any resources being used.

/// </summary>

~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::MaskedTextBox^ maskedTextBox1;
private: System::Windows::Forms::Button^ button1;
protected:
private:
/// <summary>

/// Required designer variable.

/// </summary>

System::ComponentModel::Container ^components;

#pragmaregion Windows Form Designer generated code
/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

void InitializeComponent(void)
{
this->label1 = (gcnew System::Windows::Forms::Label());
this->maskedTextBox1 = (gcnew System::Windows::Forms::MaskedTextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//

// label1

//

this->label1->AutoSize = true;
this->label1->FlatStyle = System::Windows::Forms::FlatStyle::Popup;
this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label1->Location = System::Drawing::Point(73, 59);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(147, 16);
this->label1->TabIndex = 0;
this->label1->Text = L"What is your name\? ";
this->label1->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
//

// maskedTextBox1

//

this->maskedTextBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->maskedTextBox1->Location = System::Drawing::Point(30, 127);
this->maskedTextBox1->Name = L"maskedTextBox1";
this->maskedTextBox1->Size = System::Drawing::Size(233, 20);
this->maskedTextBox1->TabIndex = 1;
this->maskedTextBox1->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
//

// button1

//

this->button1->Location = System::Drawing::Point(105, 179);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(84, 23);
this->button1->TabIndex = 2;
this->button1->Text = L"Next";
this->button1->UseVisualStyleBackColor = true;
//

// Form1

//

this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 270);
this->Controls->Add(this->button1);
this->Controls->Add(this->maskedTextBox1);
this->Controls->Add(this->label1);
this->Name = L"Form1";
this->Text = L"Botz0004";
this->ResumeLayout(false);
this->PerformLayout();
}

#pragmaendregion

};
}
Last edited by ongxizhe; Jun 11th, 2007 at 11:11 am.
Reputation Points: 8
Solved Threads: 1
Junior Poster in Training
ongxizhe is offline Offline
68 posts
since Mar 2007
Jun 12th, 2007
0

Re: How to link Buttons in C++.NET?

Help will be appreciated.
Reputation Points: 8
Solved Threads: 1
Junior Poster in Training
ongxizhe is offline Offline
68 posts
since Mar 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C++ Variable help
Next Thread in C++ Forum Timeline: Where to get good C++ GUI tutorials?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC