Textbox in Text-Datei speichern



  • Hi,
    ich hoffe ihr könnt mir helfen. Folgendes Problem:
    Der Benutzer des Programms gibt seine Daten(Name,Adresse...) in vorgefertigte Textboxen ein. Anschließend sollen diese Daten durch einen klick auf speichern in eine Text Datei gespeichert werden. Ich habe allerdings überhaupt keine Ahnung wie das funktioniert.
    Hier der bisherige Quellcode:

    Profildialog.h

    #pragma once
    #include "Maindialog.h"

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;

    namespace Luegendedektor {

    /// <summary>
    /// Summary for Profildialog
    ///
    /// 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 Profildialog : public System::Windows::Forms::Form
    {
    public:
    Profildialog(void)
    {
    InitializeComponent();
    //
    //TODO: Add the constructor code here
    //
    }

    protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~Profildialog()
    {
    if (components)
    {
    delete components;
    }
    }
    private: System::Windows::Forms::Label^ ort_label;
    protected:
    private: System::Windows::Forms::Label^ plz_label;
    private: System::Windows::Forms::Label^ str_label;
    private: System::Windows::Forms::Label^ geb_label;
    private: System::Windows::Forms::Label^ name_label;
    private: System::Windows::Forms::Label^ vorname_label;
    private: System::Windows::Forms::Label^ pers_label;
    private: System::Windows::Forms::TextBox^ vorname_textBox;
    private: System::Windows::Forms::TextBox^ name_textBox;
    private: System::Windows::Forms::TextBox^ geb_textBox;
    private: System::Windows::Forms::TextBox^ str_textBox;
    private: System::Windows::Forms::TextBox^ plz_textBox;
    private: System::Windows::Forms::TextBox^ ort_textBox;
    private: System::Windows::Forms::TextBox^ pers_textBox;
    private: System::Windows::Forms::Button^ ok_button;

    private: System::Windows::Forms::Button^ abbruch_button;
    private: System::Windows::Forms::Button^ speichern_button;

    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->ort_label = (gcnew System::Windows::Forms::Label());
    this->plz_label = (gcnew System::Windows::Forms::Label());
    this->str_label = (gcnew System::Windows::Forms::Label());
    this->geb_label = (gcnew System::Windows::Forms::Label());
    this->name_label = (gcnew System::Windows::Forms::Label());
    this->vorname_label = (gcnew System::Windows::Forms::Label());
    this->pers_label = (gcnew System::Windows::Forms::Label());
    this->vorname_textBox = (gcnew System::Windows::Forms::TextBox());
    this->name_textBox = (gcnew System::Windows::Forms::TextBox());
    this->geb_textBox = (gcnew System::Windows::Forms::TextBox());
    this->str_textBox = (gcnew System::Windows::Forms::TextBox());
    this->plz_textBox = (gcnew System::Windows::Forms::TextBox());
    this->ort_textBox = (gcnew System::Windows::Forms::TextBox());
    this->pers_textBox = (gcnew System::Windows::Forms::TextBox());
    this->ok_button = (gcnew System::Windows::Forms::Button());
    this->abbruch_button = (gcnew System::Windows::Forms::Button());
    this->speichern_button = (gcnew System::Windows::Forms::Button());
    this->SuspendLayout();
    //
    // ort_label
    //
    this->ort_label->Location = System::Drawing::Point(35, 186);
    this->ort_label->Name = L"ort_label";
    this->ort_label->Size = System::Drawing::Size(130, 20);
    this->ort_label->TabIndex = 14;
    this->ort_label->Text = L"Ort:";
    this->ort_label->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
    //
    // plz_label
    //
    this->plz_label->Location = System::Drawing::Point(35, 158);
    this->plz_label->Name = L"plz_label";
    this->plz_label->Size = System::Drawing::Size(130, 20);
    this->plz_label->TabIndex = 13;
    this->plz_label->Text = L"PLZ:";
    this->plz_label->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
    //
    // str_label
    //
    this->str_label->Location = System::Drawing::Point(35, 127);
    this->str_label->Name = L"str_label";
    this->str_label->Size = System::Drawing::Size(130, 20);
    this->str_label->TabIndex = 12;
    this->str_label->Text = L"Straße:";
    this->str_label->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
    //
    // geb_label
    //
    this->geb_label->Location = System::Drawing::Point(35, 95);
    this->geb_label->Name = L"geb_label";
    this->geb_label->Size = System::Drawing::Size(130, 20);
    this->geb_label->TabIndex = 11;
    this->geb_label->Text = L"Geburtsdatum:";
    this->geb_label->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
    //
    // name_label
    //
    this->name_label->Location = System::Drawing::Point(35, 65);
    this->name_label->Name = L"name_label";
    this->name_label->Size = System::Drawing::Size(130, 20);
    this->name_label->TabIndex = 10;
    this->name_label->Text = L"Name:";
    this->name_label->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
    //
    // vorname_label
    //
    this->vorname_label->Location = System::Drawing::Point(35, 35);
    this->vorname_label->Name = L"vorname_label";
    this->vorname_label->Size = System::Drawing::Size(130, 20);
    this->vorname_label->TabIndex = 9;
    this->vorname_label->Text = L"Vorname:";
    this->vorname_label->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
    //
    // pers_label
    //
    this->pers_label->Location = System::Drawing::Point(35, 216);
    this->pers_label->Name = L"pers_label";
    this->pers_label->Size = System::Drawing::Size(130, 37);
    this->pers_label->TabIndex = 15;
    this->pers_label->Text = L"Personalausweisnummer:\r\n(entspricht Profilname)";
    this->pers_label->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
    //
    // vorname_textBox
    //
    this->vorname_textBox->Location = System::Drawing::Point(171, 35);
    this->vorname_textBox->Name = L"vorname_textBox";
    this->vorname_textBox->Size = System::Drawing::Size(100, 20);
    this->vorname_textBox->TabIndex = 16;
    //
    // name_textBox
    //
    this->name_textBox->Location = System::Drawing::Point(171, 65);
    this->name_textBox->Name = L"name_textBox";
    this->name_textBox->Size = System::Drawing::Size(100, 20);
    this->name_textBox->TabIndex = 17;
    //
    // geb_textBox
    //
    this->geb_textBox->Location = System::Drawing::Point(171, 96);
    this->geb_textBox->Name = L"geb_textBox";
    this->geb_textBox->Size = System::Drawing::Size(50, 20);
    this->geb_textBox->TabIndex = 18;
    //
    // str_textBox
    //
    this->str_textBox->Location = System::Drawing::Point(171, 127);
    this->str_textBox->Name = L"str_textBox";
    this->str_textBox->Size = System::Drawing::Size(150, 20);
    this->str_textBox->TabIndex = 19;
    //
    // plz_textBox
    //
    this->plz_textBox->Location = System::Drawing::Point(171, 158);
    this->plz_textBox->Name = L"plz_textBox";
    this->plz_textBox->Size = System::Drawing::Size(50, 20);
    this->plz_textBox->TabIndex = 20;
    //
    // ort_textBox
    //
    this->ort_textBox->Location = System::Drawing::Point(171, 187);
    this->ort_textBox->Name = L"ort_textBox";
    this->ort_textBox->Size = System::Drawing::Size(150, 20);
    this->ort_textBox->TabIndex = 21;
    //
    // pers_textBox
    //
    this->pers_textBox->Location = System::Drawing::Point(171, 217);
    this->pers_textBox->Name = L"pers_textBox";
    this->pers_textBox->Size = System::Drawing::Size(150, 20);
    this->pers_textBox->TabIndex = 22;
    //
    // ok_button
    //
    this->ok_button->DialogResult = System::Windows::Forms::DialogResult::OK;
    this->ok_button->Location = System::Drawing::Point(56, 274);
    this->ok_button->Name = L"ok_button";
    this->ok_button->Size = System::Drawing::Size(75, 23);
    this->ok_button->TabIndex = 23;
    this->ok_button->Text = L"OK";
    this->ok_button->UseVisualStyleBackColor = true;
    //
    // abbruch_button
    //
    this->abbruch_button->DialogResult = System::Windows::Forms::DialogResult::Cancel;
    this->abbruch_button->Location = System::Drawing::Point(285, 274);
    this->abbruch_button->Name = L"abbruch_button";
    this->abbruch_button->Size = System::Drawing::Size(75, 23);
    this->abbruch_button->TabIndex = 24;
    this->abbruch_button->Text = L"Schließen";
    this->abbruch_button->UseVisualStyleBackColor = true;
    //
    // speichern_button
    //
    this->speichern_button->Location = System::Drawing::Point(171, 274);
    this->speichern_button->Name = L"speichern_button";
    this->speichern_button->Size = System::Drawing::Size(75, 23);
    this->speichern_button->TabIndex = 25;
    this->speichern_button->Text = L"Speichern";
    this->speichern_button->UseVisualStyleBackColor = true;
    this->speichern_button->Click += gcnew System::EventHandler(this, &Profildialog::speichern_button_Click);
    //
    // Profildialog
    //
    this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    this->ClientSize = System::Drawing::Size(412, 323);
    this->Controls->Add(this->speichern_button);
    this->Controls->Add(this->abbruch_button);
    this->Controls->Add(this->ok_button);
    this->Controls->Add(this->pers_textBox);
    this->Controls->Add(this->ort_textBox);
    this->Controls->Add(this->plz_textBox);
    this->Controls->Add(this->str_textBox);
    this->Controls->Add(this->geb_textBox);
    this->Controls->Add(this->name_textBox);
    this->Controls->Add(this->vorname_textBox);
    this->Controls->Add(this->pers_label);
    this->Controls->Add(this->ort_label);
    this->Controls->Add(this->plz_label);
    this->Controls->Add(this->str_label);
    this->Controls->Add(this->geb_label);
    this->Controls->Add(this->name_label);
    this->Controls->Add(this->vorname_label);
    this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedDialog;
    this->MaximizeBox = false;
    this->Name = L"Profildialog";
    this->Text = L"Profil erstellen";
    this->ResumeLayout(false);
    this->PerformLayout();

    }

    public: property String^ Vorname
    {
    String^ get(){return vorname_textBox->Text;}
    void set(String^ text) {vorname_textBox->Text=text;}
    }

    property String^ Nachname
    {
    String^ get(){return name_textBox->Text;}
    void set(String^ text) {name_textBox->Text=text;}
    }

    property String^ Geb
    {
    String^ get(){return geb_textBox->Text;}
    void set(String^ text) {geb_textBox->Text=text;}
    }

    property String^ Str
    {
    String^ get(){return str_textBox->Text;}
    void set(String^ text) {str_textBox->Text=text;}
    }

    property String^ Plz
    {
    String^ get(){return plz_textBox->Text;}
    void set(String^ text) {plz_textBox->Text=text;}
    }

    property String^ Ort
    {
    String^ get(){return ort_textBox->Text;}
    void set(String^ text) {ort_textBox->Text=text;}
    }

    property String^ Pers
    {
    String^ get(){return pers_textBox->Text;}
    void set(String^ text) {pers_textBox->Text=text;}
    }

    #pragma endregion

    private: System::Void speichern_button_Click(System::Object^ sender, System::EventArgs^ e)

    {

    }
    };
    }



  • StreamWriter

    Aber ich pers. würde den XmlSerializer bevorzugen...



  • Kannst du mir das bitte etwas genauer erklären?
    Wie gesagt ich bin noch Anfänger auf diesem Gebiet und ich wüsste gern was ich nun genau tun soll und wo ich das ganze in den Quellcode einfügen soll

    Danke



  • MSDN ist dein freund 🙂
    sorry wenn manche jetzt nich "Die Lösung" hier rein schreiben werden. Es ist aber ziemlich blöde, neulingen, den kompletten Code zu geben.


Anmelden zum Antworten