Hello my question is if I can send data (objects) for an eventHandler for example:
namespace AdministradorS {
using namespace std;
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>
/// Resumen de loginAdmi
/// </summary>
public ref class loginAdmi : public System::Windows::Forms::Form
{
public:
loginAdmi(socketC sock)
{
//definir el objeto de tipo socket pero en donde?
InitializeComponent(sock);
//
//TODO: agregar código de constructor aquí
//
}
protected:
/// <summary>
/// Limpiar los recursos que se estén usando.
/// </summary>
~loginAdmi()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Label^ label1;
protected:
private: System::Windows::Forms::Button^ btnAceptar;
private: System::Windows::Forms::TextBox^ txtPassw;
private: System::Windows::Forms::TextBox^ txtUsuario;
private:
/// <summary>
/// Variable del diseñador necesaria.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Método necesario para admitir el Diseñador. No se puede modificar
/// el contenido de este método con el editor de código.
/// </summary>
void InitializeComponent(socketC sock)
{
this->label1 = (gcnew System::Windows::Forms::Label());
this->btnAceptar = (gcnew System::Windows::Forms::Button());
this->txtPassw = (gcnew System::Windows::Forms::TextBox());
this->txtUsuario = (gcnew System::Windows::Forms::TextBox());
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Font = (gcnew System::Drawing::Font(L"Lucida Calligraphy", 27.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label1->Location = System::Drawing::Point(309, 164);
this->label1->Margin = System::Windows::Forms::Padding(4, 0, 4, 0);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(236, 72);
this->label1->TabIndex = 7;
this->label1->Text = L"LOGIN";
//
// btnAceptar
//
this->btnAceptar->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 15.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->btnAceptar->Location = System::Drawing::Point(269, 542);
this->btnAceptar->Margin = System::Windows::Forms::Padding(4, 5, 4, 5);
this->btnAceptar->Name = L"btnAceptar";
this->btnAceptar->Size = System::Drawing::Size(276, 55);
this->btnAceptar->TabIndex = 6;
this->btnAceptar->Text = L"Aceptar";
this->btnAceptar->UseVisualStyleBackColor = true;
this->btnAceptar->Click += gcnew System::EventHandler(this, &loginAdmi::btnAceptar_Click); //ENVIAR OBJETO POR AQUI?
//
// txtPassw
//
this->txtPassw->Font = (gcnew System::Drawing::Font(L"Times New Roman", 18, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->txtPassw->Location = System::Drawing::Point(212, 398);
this->txtPassw->Margin = System::Windows::Forms::Padding(4, 5, 4, 5);
this->txtPassw->Name = L"txtPassw";
this->txtPassw->PasswordChar = '*';
this->txtPassw->Size = System::Drawing::Size(424, 49);
this->txtPassw->TabIndex = 5;
this->txtPassw->Text = L"PASSWORD";
this->txtPassw->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
//
// txtUsuario
//
this->txtUsuario->AccessibleDescription = L"USUARIO";
this->txtUsuario->Font = (gcnew System::Drawing::Font(L"Times New Roman", 18, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->txtUsuario->Location = System::Drawing::Point(212, 298);
this->txtUsuario->Margin = System::Windows::Forms::Padding(4, 5, 4, 5);
this->txtUsuario->Name = L"txtUsuario";
this->txtUsuario->Size = System::Drawing::Size(424, 49);
this->txtUsuario->TabIndex = 4;
this->txtUsuario->Text = L"USUARIO";
this->txtUsuario->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
//
// loginAdmi
//
this->AutoScaleDimensions = System::Drawing::SizeF(9, 20);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(803, 708);
this->Controls->Add(this->label1);
this->Controls->Add(this->btnAceptar);
this->Controls->Add(this->txtPassw);
this->Controls->Add(this->txtUsuario);
this->Margin = System::Windows::Forms::Padding(4, 5, 4, 5);
this->Name = L"loginAdmi";
this->Text = L"loginAdmi";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
void MarshalString(String ^ s, string& os) {
using namespace Runtime::InteropServices;
const char* chars =
(const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
os = chars;
Marshal::FreeHGlobal(IntPtr((void*)chars));
}
private: System::Void btnAceptar_Click(System::Object^ sender, System::EventArgs^ e) {
//UTILIZAR OBJETO AQUI
String ^ user = txtUsuario->Text; //obtiene el dato del textbox
String ^passw = txtPassw->Text; //obtiene el dato del textbox txtUsuario->Text;
string userS;
string passwS;
MarshalString(user, userS);
MarshalString(passw, passwS);
bool logeado = false;
//if(AdministradorS::socket.puertoS ==5400) //socket deberia ser la variable con el objeto entrante seteado
// MessageBox::Show("5400");
//else if(AdministradorS::socket.puertoS == 5500) //socket deberia ser la variable con el objeto entrante seteado
// MessageBox::Show("5500");
}
private: System::Void loginAdmi_Load(System::Object^ sender, System::EventArgs^ e) {
}
};
I would like to send here the sock object that I receive as a parameter
this->btnAceptar->Click += gcnew System::EventHandler(this, &loginAdmi::btnAceptar_Click); //ENVIAR OBJETO POR AQUI?
and receive it in this function to use it internally
private: System::Void btnAceptar_Click(System::Object^ sender, System::EventArgs^ e)
thanks in advance