próbowałem już tak.
ale niestety ani zapis
cmb_Stop->Items->Add(tmenu->return_v());
ani
cmb_Stop->Items->Add(gcnew String(tmenu->return_v()));
ani
cmb_Stop->Items->Add(gcnew String(tmenu->return_v().c_str));
Funkcja return_v wygląda tak :
vector<string> TMenu::return_v(){
return v[0];
}
TModification.h
#pragma once
#include <string>
#include "TMenu.h"
namespace Project2 {
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>
/// Summary for TModification
/// </summary>
public ref class TModification : public System::Windows::Forms::Form
{
public:
TModification(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~TModification()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ btn_Add_Line;
protected:
private: System::Windows::Forms::TextBox^ tbx_Name;
private: System::Windows::Forms::ComboBox^ cmb_Stop;
private: System::Windows::Forms::ComboBox^ cmb_Type;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::RichTextBox^ rtbx_List_Stop;
private: System::Windows::Forms::Button^ btn_Add_Stop;
private: System::Windows::Forms::Button^ btn_Delete_Stop;
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->btn_Add_Line = (gcnew System::Windows::Forms::Button());
this->tbx_Name = (gcnew System::Windows::Forms::TextBox());
this->cmb_Stop = (gcnew System::Windows::Forms::ComboBox());
this->cmb_Type = (gcnew System::Windows::Forms::ComboBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->rtbx_List_Stop = (gcnew System::Windows::Forms::RichTextBox());
this->btn_Add_Stop = (gcnew System::Windows::Forms::Button());
this->btn_Delete_Stop = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// btn_Add_Line
//
this->btn_Add_Line->Location = System::Drawing::Point(342, 52);
this->btn_Add_Line->Name = L"btn_Add_Line";
this->btn_Add_Line->Size = System::Drawing::Size(75, 23);
this->btn_Add_Line->TabIndex = 0;
this->btn_Add_Line->Text = L"Dodaj Linie ";
this->btn_Add_Line->UseVisualStyleBackColor = true;
this->btn_Add_Line->Click += gcnew System::EventHandler(this, &TModification::btn_Add_Line_Click);
//
// tbx_Name
//
this->tbx_Name->Location = System::Drawing::Point(40, 26);
this->tbx_Name->Name = L"tbx_Name";
this->tbx_Name->Size = System::Drawing::Size(100, 20);
this->tbx_Name->TabIndex = 1;
//
// cmb_Stop
//
this->cmb_Stop->FormattingEnabled = true;
this->cmb_Stop->Location = System::Drawing::Point(37, 156);
this->cmb_Stop->Name = L"cmb_Stop";
this->cmb_Stop->Size = System::Drawing::Size(121, 21);
this->cmb_Stop->TabIndex = 2;
this->cmb_Stop->SelectedIndexChanged += gcnew System::EventHandler(this, &TModification::comboBox1_SelectedIndexChanged);
//
// cmb_Type
//
this->cmb_Type->FormattingEnabled = true;
this->cmb_Type->Items->AddRange(gcnew cli::array< System::Object^ >(4) {L"Autobusowy", L"Autobusowy/Tranwajowy", L"Tranwajowy",
L"Metro"});
this->cmb_Type->Location = System::Drawing::Point(40, 81);
this->cmb_Type->Name = L"cmb_Type";
this->cmb_Type->Size = System::Drawing::Size(121, 21);
this->cmb_Type->TabIndex = 3;
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(40, 62);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(25, 13);
this->label1->TabIndex = 4;
this->label1->Text = L"Typ";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(37, 141);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(58, 13);
this->label2->TabIndex = 5;
this->label2->Text = L"Przystanki ";
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(43, 7);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(40, 13);
this->label3->TabIndex = 6;
this->label3->Text = L"Nazwa";
//
// rtbx_List_Stop
//
this->rtbx_List_Stop->Location = System::Drawing::Point(230, 104);
this->rtbx_List_Stop->Name = L"rtbx_List_Stop";
this->rtbx_List_Stop->Size = System::Drawing::Size(173, 136);
this->rtbx_List_Stop->TabIndex = 7;
this->rtbx_List_Stop->Text = L"";
//
// btn_Add_Stop
//
this->btn_Add_Stop->Location = System::Drawing::Point(38, 196);
this->btn_Add_Stop->Name = L"btn_Add_Stop";
this->btn_Add_Stop->Size = System::Drawing::Size(63, 23);
this->btn_Add_Stop->TabIndex = 8;
this->btn_Add_Stop->Text = L"Dodaj";
this->btn_Add_Stop->UseVisualStyleBackColor = true;
//
// btn_Delete_Stop
//
this->btn_Delete_Stop->Location = System::Drawing::Point(119, 196);
this->btn_Delete_Stop->Name = L"btn_Delete_Stop";
this->btn_Delete_Stop->Size = System::Drawing::Size(60, 23);
this->btn_Delete_Stop->TabIndex = 9;
this->btn_Delete_Stop->Text = L"Usuń";
this->btn_Delete_Stop->UseVisualStyleBackColor = true;
//
// TModification
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(466, 261);
this->Controls->Add(this->btn_Delete_Stop);
this->Controls->Add(this->btn_Add_Stop);
this->Controls->Add(this->rtbx_List_Stop);
this->Controls->Add(this->label3);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->cmb_Type);
this->Controls->Add(this->cmb_Stop);
this->Controls->Add(this->tbx_Name);
this->Controls->Add(this->btn_Add_Line);
this->Name = L"TModification";
this->Text = L"TModification";
this->Load += gcnew System::EventHandler(this, &TModification::TModification_Load);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void comboBox1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void btn_Add_Line_Click(System::Object^ sender, System::EventArgs^ e) {
String^ name = tbx_Name->Text;
}
private: System::Void TModification_Load(System::Object^ sender, System::EventArgs^ e) {
TMenu^ tmenu = gcnew TMenu;
MessageBox::Show(gcnew String(tmenu->return_v().c_str()));
//cmb_Stop->Items->Add(TMenu::return_v());
// TMenu::return_v();
}
};
}
TMenu.h
#pragma once
#include <string>
#include <fstream>
#include "Str.h"
#include <vector>
#include <iostream>
#include <conio.h>
#include "Nawigacja.h"
#include "TModification.h"
#include <stdio.h>
namespace Project2 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace std;
/// <summary>
/// Summary for TMenu
/// </summary>
public ref class TMenu : public System::Windows::Forms::Form
{
public:
TMenu(void);
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~TMenu()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ btn_Search;
private: System::Windows::Forms::Button^ button2;
private: vector<string> *v ;
protected:
public:
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->button1 = (gcnew System::Windows::Forms::Button());
this->btn_Search = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(109, 176);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"Zakończ";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &TMenu::button1_Click_1);
//
// btn_Search
//
this->btn_Search->Location = System::Drawing::Point(109, 43);
this->btn_Search->Name = L"btn_Search";
this->btn_Search->Size = System::Drawing::Size(75, 23);
this->btn_Search->TabIndex = 2;
this->btn_Search->Text = L"Wyszukaj";
this->btn_Search->UseVisualStyleBackColor = true;
this->btn_Search->Click += gcnew System::EventHandler(this, &TMenu::button3_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(126, 111);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(75, 23);
this->button2->TabIndex = 3;
this->button2->Text = L"button2";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &TMenu::button2_Click);
//
// TMenu
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 261);
this->Controls->Add(this->button2);
this->Controls->Add(this->btn_Search);
this->Controls->Add(this->button1);
this->Name = L"TMenu";
this->Text = L"TMenu";
this->Load += gcnew System::EventHandler(this, &TMenu::TMenu_Load);
this->ResumeLayout(false);
}
#pragma endregion
///// Deklaracja MEtod
public: System::Void TMenu_Load(System::Object^ sender, System::EventArgs^ e) ;
private: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e);
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) ;
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) ;
public: vector<string> return_v();
public: void load_data();
public: void show_data();
};
}
TMenu.cpp
#include "TMenu.h"
namespace Project2{
TMenu::TMenu(){
InitializeComponent();
v = new vector<string>;
}
vector<string> TMenu::return_v(){
return v[0];
}
void TMenu::load_data() {
int numerWiersza = 0;
string wiersz;
ifstream f("przystanki.txt");
if (f.is_open())
{
while (getline (f, wiersz,'\t'))
{
v->push_back(wiersz);
}
}
f.close();
}
void TMenu::show_data(){
int i = 0 ;
for (i = 0; i<v->size();i++)
MessageBox::Show(gcnew String(v->at(i).c_str()));
}
/// Otwarcie Modification
System::Void TMenu::button3_Click(System::Object^ sender, System::EventArgs^ e){
TModification^ new_Window = gcnew TModification;
this->Hide();
new_Window->ShowDialog();
this->Show();
}
/// Pokaż dane
System::Void TMenu::button2_Click(System::Object^ sender, System::EventArgs^ e){
show_data();
}
/// Close
System::Void TMenu::button1_Click_1(System::Object^ sender, System::EventArgs^ e){
Application::Exit();
}
/// Wczytywanie danych
System::Void TMenu::TMenu_Load(System::Object^ sender, System::EventArgs^ e){
load_data();
}
}