PDA

View Full Version : C++ new hand problem 3 please help (about GUI Interface)




chunhohuen
Apr 22, 2011, 10:28 AM
With the great help in the previous posts, I want to thank all of them!;)

This is quite a long post and I hope it does not bore you:o

After I write and the function in the previous posts, now I use them in the GUI Interface but I think GUI is my weakest part....

First,I create 2 forms.

Form 1 is let the user input the name and select whether create a new account or use the old account.

http://i971.photobucket.com/albums/ae195/chunhohuen/Form1.jpg?t=1303483591


The header file of Form 1 is :
#pragma once
#include "Form2.h"
#include <fstream>

namespace login_GUI {

using namespace System;
.....
using namespace System::Runtime::InteropServices; //For the class Marshal

/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
void read();
void write();
void find();
void setuser();
}
...
...

private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
void read() {}
void write(){}
void find(){}
void setuser(){}
...
...

#pragma endregion

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) // The create new user bottom

{
Form2 ^F2= gcnew Form2();
F2->ShowDialog();
}


private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) // The login as old botton

{
Form2 ^F2= gcnew Form2();
F2->ShowDialog();
}
};
}




Form 2 is show the user input and the buttom to close the form.

http://i971.photobucket.com/albums/ae195/chunhohuen/Form2.jpg?t=1303484659


The header file of Form 2 is :
#pragma once

namespace login_GUI {

using namespace System;
...
...
...
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) // the close button
{
this->Close();
}
};


My problem is I have no idea to use my written function applied in the GUI.....:(



chunhohuen
Apr 22, 2011, 10:31 AM
I divide it to 2 posts in order to avoiding one too long post.


The details function are :

The code :

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

char inputusername[99];// let the user to input the user name

void find()

{
ifstream file;
file.open("file.txt");

string input=inputusername;
string input_line;
bool found = false;

while( file >> input_line ) {
if( input_line.compare(input) == 0 ) {
cout << "The name " << input_line << " was found in file.\n";
found = true;
break;
}
}

if( found == false ) {
ofstream fout ("file.txt",ios::app);
fout<<inputusername<<endl;
fout.close();
}

file.close();

}


void setuser() //function of set the username
{
cout<<"Enter the username: "<<endl;
cin>>inputusername;
int score=0;
}


void read() //read the file and show the details
{
cout<<endl;
ifstream fin("file.txt");
char ch;
while (fin.get(ch))
cout<<ch;
fin.close();
}


void write() //read the input to the file
{
ofstream fout ("file.txt",ios::app);
fout<<inputusername<<endl;
fout.close();
}

jiminaus
Apr 22, 2011, 06:06 PM
Mate, let me pass on a few points about forum etiquette.

Surround your code in ... tags. The mods are probably getting sick and tired of doing this for you. The easiest way to do is to highlight the code then click the # button in the message editor toolbar.

Be more appropriate with your subjects. The purpose of subject lines is so people can best guess what the threads about. Use specific terms. Don't put "please help" in a subject line, it won't get you anymore help then you would leave it out.

Tell what the problem is. Don't just post code and expect us to work it out. Be as specific as possible. Tell us what your're expecting to happening, what is happening, what's not happening. Copy and paste error messages. Tell us what you've already tried to do yourself to fix the problem. (I'm sounding like chown33! LOL).

Finally, take this to a Windows programming forum. This is a Mac programming forum. Coding in Windows on Mac hardware either via boot camp or virtualisation doesn't count as Mac programming.

chunhohuen
Apr 23, 2011, 01:18 AM
Mate, let me pass on a few points about forum etiquette.

Surround your code in ... tags. The mods are probably getting sick and tired of doing this for you. The easiest way to do is to highlight the code then click the # button in the message editor toolbar.

Be more appropriate with your subjects. The purpose of subject lines is so people can best guess what the threads about. Use specific terms. Don't put "please help" in a subject line, it won't get you anymore help then you would leave it out.

Tell what the problem is. Don't just post code and expect us to work it out. Be as specific as possible. Tell us what your're expecting to happening, what is happening, what's not happening. Copy and paste error messages. Tell us what you've already tried to do yourself to fix the problem. (I'm sounding like chown33! LOL).

Finally, take this to a Windows programming forum. This is a Mac programming forum. Coding in Windows on Mac hardware either via boot camp or virtualisation doesn't count as Mac programming.

THX for the tips I will try to correct the question:)

chunhohuen
Apr 23, 2011, 02:34 AM
Thanks for the tips that now I correct my question in this way.:p

I have rewritten my function become more simple.

The code is:

char inputusername[99];

void createnewaccount() //function of set the username
{
cout<<"Enter the username: "<<endl;
cin>>inputusername;
int score=0;
ofstream fout ("file.txt",ios::app);
fout<<inputusername<<endl;
fout.close();
}


void createnewaccount() //function of set the username
{
cout<<"Enter the username: "<<endl;
cin>>inputusername;
int score=0;
ofstream fout ("file.txt",ios::app);
fout<<inputusername<<endl;
fout.close();
}

But, there is a problem:(, I don not think there are any cin function in the GUI. Therefore, if I cannot use those function in GUI.

I know that the textbox of the GUI can let user input the data and label can display the user input.
How can transfer the cin to textbox and use the cout as label?

wlh99
Apr 23, 2011, 12:52 PM
Thanks for the tips that now I correct my question in this way.:p

I have rewritten my function become more simple.

The code is:


As was pointed out, this is a Mac forum. You are asking a Windows specific question. Most likely few people here have Visual Studio, few know Visual c++, and no one will be able to help you.

You should look for a forum that offers Windows help.

balamw
Apr 23, 2011, 06:00 PM
Most likely few people here have Visual Studio, few know Visual c++, and no one will be able to help you.

Many of us do have and use VC++, but are hiding out here.

chunhohuen, what resources are you using to learn Visual C++/Windows Forms/.NET?

What you are asking for should be covered in any book on the subject. You should not expect to learn programming without a good reference resource.

I don't know of one myself, but this looks like it covers the basics. http://www.amazon.com/Ivor-Hortons-Beginning-Visual-Programmer/dp/0470500883

B

MattMcClinch
Apr 23, 2011, 09:35 PM
You have much to learn about object-oriented programming.

First, forget cin and cout. They are of no use to you.

Second, find out the names of your textbox and label objects. They are most likely something like textbox1 and label1. Once you locate them, please change them to something more descriptive.

Now it is just a matter of getting and setting the "Text" property of your textbox and label objects. Note: it might be called "text" or "label" or "string" or something else entirely. I am going to call it "Text".


label1.Text = "Enter the user name:";


inputusername = textbox1.Text;


At this point, you are going to get an error, because inputusername is a character array, and does not match the type of textbox1.Text.