|
Thilek wrote: i am writing a directory scanning program..
Since you are using C++/CLI, I don't see any need of using standard C++ for directory search. There is Directory::GetDirectories() method which will help you on this. Read this[^] article which talks about how to do it recursively.
Thilek wrote: the program should show the filenames one by one while searching the directory.
Thilek wrote: listBox1->EndUpdate();
Problem here is you are calling EndUpdate only after finishing the loop. So control is redrawing only after completing the full loop. You need to change this so that control will draw immediatly once the item is added.
|
|
|
|
|
Hi,
I have 7 forms in my project. Form 6 has a text box, I wish for the text entered in Form 6 to be passed to a label in Form 7. I am new to C++ and would really appreciate any advice. I have posted the code I am trying to work with but i keep getting error C2248. Please Help!! Thanks.
public ref class Form6 : public System::Windows::Forms::Form
{
public:String^str1;
public:
Form6(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Application::Exit();
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
Application::Exit();
}
private: System::Void label2_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
this->textBox2->Text = this->textBox1->Text;
this->textBox1->Text = "";
this->textBox1->Text = "Saved";
}
private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
}
public: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
str1 = this->textBox2->text;
Form6::Hide();
Form7 myForm;
if(myForm.ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
//Do stuff
}
}
private: System::Void Form6_Load(System::Object^ sender, System::EventArgs^ e) {
str1 = "str1default";
}
private: System::Void textBox2_TextChanged(System::Object^ sender, System::EventArgs^ e) {
str1=textBox2->Text;
}
};
}
|
|
|
|
|
liverpoolfan wrote: I wish for the text entered in Form 6 to be passed to a label in Form 7
There are many ways to do this.
1 - Use delegates.
2 - Pass value via constructor
3 - Create a public method on Form7 which updates the control.
|
|
|
|
|
I originally posted this in the other C++ forum. The only reply I got suggested this was a better place. Its been a pain in the rear for OVER A YEAR so far!!
I have opened a Windows Forms Application in VS2005 and have added 2 forms – Form1 and Form2.
Each form generates code as follows:
[code]
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 DCAMwfa {
public ref class Form2 : public System::Windows::Forms::Form
{
public:
Form2(void)
...
[/code]
I have tried to use a button on Form1 to display a Form2 but consistently failed, being told one way or another that Form2 does not exist in DCAMwfa:
‘Form2’ is not a member of ‘DCAMwfa’
Syntax error: identifier ‘Form2’
This is in spite of the above generated code defining Form2 and the fact that ??intellisense?? tells me that Form1 and Form2 are included in DCAMwfa as I type DCAMwfa::
Using VB and C# I have no problems, yet using C++ I can get nowhere. I need to use C++ because I use one .dll which produces large unsigned integers and function pointers.
Code such as:
[code]
Form CAMERAfrm ^ = gcnew Form();
CAMERAfrm->ShowDialog(this);
[/code]
allows me to display a new blank form but not a new Form2. The same happens with Show and ShowForm
Can someone please tell me what is going wrong?
Ron G
|
|
|
|
|
You need to include the second form's header file to use it. Something like #include "Form2.h" on form1.
|
|
|
|
|
Thanks for your very rapid reply.
However, I confess I love VB and C#, and the more I explore C++ the more that love grows - despite the 'limitations'
I included the include statement at the beginning of Form1.h - under the #pragma once section. Then:
Form2 DCAM = gcnew Form2();
DCAM.ShowDialog(this);
//error c3673: 'DCAMfrma::Form2': class does not have a copy constructor
Form2 DCAM;
DCAM.ShowDialog(this);
//OK at last
I confess I still do not comprehend the rationale. I'm so unused to 'defining' relationships so many times. When VB first came out it was hailed as a real G4 language. Programming languages should be getting simpler. All my text work is done by voice. Programming should be going that way.
I would relish the day I can talk to my computer as Dillon talks to Andromeda (and Rommy) but if C++ dominates and VB drifts more in that direction, it would become hell - like the Atreides guru talking to his computer in Dune.
But truly, thanks
Ron
|
|
|
|
|
regnwald wrote: Form2 DCAM = gcnew Form2();
This is incorrect. C++/CLI uses handles to access managed types. You should use handle(^ ) symbol. Like,
Form2^ DCAM = gcnew Form2();
DCAM->ShowDialog(); or use stack semantics
Form2 form2;
form2.ShowDialog(); regnwald wrote: despite the 'limitations'
Limitations? What limitations are you seeing?
It looks like you are just getting started with C++/CLI. I recommend this[^] book.
|
|
|
|
|
You are, of course, correct. I am new to C++/CLI - in fact to any dialect of C++. I checked that link you gave and will have to take the plunge. Going back to school at 72 at least keeps me alive.
I note in that link that C++/CLI is supposed to be less twisted!! But then why:
private: System::Void dSLRToolStripMenuItem1_Click(System::Object^ sender, System::EventArgs^ e) {
dslrfrm DSLR; // DSLR is a particular implementation of the dslrfrm class
DSLR.Width =293; // This works OK
DSLR.panel2->Location.X=30; //No error: Does nothing - intellisense OK
DSLR.panel2->Location.Y=30; //No error: Does nothing - intellisense OK
DSLR.Refresh(); //No improvement
DSLR.ShowDialog(this); // DSLR is shown as a child of cppPOSTERwfa::Form1
}
All these "::" and "." and "->" and "^" and "*" that speak volumes yet do they really make talking to Rommy (I mean ...) so much more usefully precise?? Limitations? Not many really. I stayed with VB1 to VB5 then VB5 to VS2005 and I think I wish I had stayed with VB5. I write snippets of assember (I grew up on that and DOS) But a .dll I want to use puts out function pointers and unsigned long. Perhaps I'll restrict my exposure to C++ to making a small library that calls the .dll functions I need and containig the pointer work and call that from VB5. Home-Sweet-Home.
But I will give that book a go. Oh, I just remembered using that hat symbol once, just as you said. Senior moments don't help.
Kind regards
Ron
_
|
|
|
|
|
I'm developing a tic tac toe multiplayer game, the game is up and it is working on a single pc, I want it to be playable across two computers in LAN, I'll be using TCP/IP for this and I have already set up a chat server program. So I know how to do communication. The concern is that I have a GameBoard class which does everything, from making a move, to restarting the game and checking for winner etc. It is independent of the form except of the mouse clicks, the form just reads in the GameBoard's properties, attributes and updates itself. How may I expand it into a
multiplayer game, I want to establish a client to client architecture, should I expand the GameBoard class, should I serialize the GameBoard class and deserialize it on the other side, or just send the specific move done?
Whats good, please tell me and help me out how it will be done. I mean just the head up
|
|
|
|
|
If you didn't think of multi-player when designing it in the first place, you may need to do some refactoring like splitting a class into multiple classes.
It is always better performance to send across as little as possible. So you should probably send only the moves done rather than the entire class.
«_Superman_»
|
|
|
|
|
hi guys,
i been writing a program that connect to a remote database in speedhosting.co.cc .But i been having problem to connect its showing error when i run it...
Error message :
An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll
Additional information: Unable to connect to any of the specified MySQL hosts.
below is my coding :-
#pragma once
namespace trialcpp {
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 MySql::Data::MySqlClient;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ cmdLogin;
private: System::Windows::Forms::Button^ cmdExit;
protected:
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->cmdLogin = (gcnew System::Windows::Forms::Button());
this->cmdExit = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
this->cmdLogin->Location = System::Drawing::Point(52, 190);
this->cmdLogin->Name = L"cmdLogin";
this->cmdLogin->Size = System::Drawing::Size(75, 23);
this->cmdLogin->TabIndex = 0;
this->cmdLogin->Text = L"Login";
this->cmdLogin->UseVisualStyleBackColor = true;
this->cmdLogin->Click += gcnew System::EventHandler(this, &Form1::cmdLogin_Click);
this->cmdExit->Location = System::Drawing::Point(175, 190);
this->cmdExit->Name = L"cmdExit";
this->cmdExit->Size = System::Drawing::Size(75, 23);
this->cmdExit->TabIndex = 1;
this->cmdExit->Text = L"Exit";
this->cmdExit->UseVisualStyleBackColor = true;
this->cmdExit->Click += gcnew System::EventHandler(this, &Form1::Exit_Click);
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(326, 266);
this->Controls->Add(this->cmdExit);
this->Controls->Add(this->cmdLogin);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void Exit_Click(System::Object^ sender, System::EventArgs^ e) {
this->Close();
}
private: System::Void cmdLogin_Click(System::Object^ sender, System::EventArgs^ e) {
MySqlConnection ^conDatabase = gcnew MySqlConnection("DataSource = 'http://sql304.xxxx.xxx; User Name='username'; Password='password'; database='database name'");
conDatabase->Open();
System::Windows::Forms::MessageBox::Show("Connection Successful");
conDatabase->Close();
}
};
Kindly help me guys plz.. thanks a lot.
Regards,
Thilek
|
|
|
|
|
Thilek wrote: Kindly help me guys plz
I will try however I tend to be more successful helping experienced developers.
Advise: Add a try/catch and examine the exception information for the error.
|
|
|
|
|
Thilek wrote: Additional information: Unable to connect to any of the specified MySQL hosts.
What does the InnerException says? Since you haven't provided enough information about the error, consider checking the following points.
1 - Make sure no firewal is not blocking the port.
2 - Make sure port in which MySQL listenes is open and allows remote connections. I believe, it listens on port 3306 on default settings.
|
|
|
|
|
its using port 3306 i off my firewall. yet its showing the same error.. is there any others way i can connect to mysql using different classes or connecters..?
|
|
|
|
|
Thilek wrote: is there any others way i can connect to mysql using different classes or connecters
The one from MySQL, which you have used is the correct. Here[^] you get connection strings. Make sure you are using a valid format and the server address you have provided is accessible from where you are connecting.
|
|
|
|
|
after i change the string value to :
MySqlConnection ^conDatabase = gcnew MySqlConnection("Server=sql304.byetcluster.com;Database='speed_2972829_worm'; Uid='username' ;Pwd='password'; Protocol=pipe; Port=3306; CharSet=UTF8");
i get this error :
An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll
Additional information: Reading from the stream has failed.
i am confused...hmm.. can help me ya ?
|
|
|
|
|
Thilek wrote: Reading from the stream has failed.
Looks like it is a bug in connector. See here[^]. Not sure it got fixed
|
|
|
|
|
well i think the server dont support remote login from .net.. with php no problem..
|
|
|
|
|
hi guys,
i been working on a worm scanner lately... i got a funtion that list all the files in a directory.. but the the filename is on vector but i need to list them in a list box. but when i compile there is no problem but when i run it there is problem showing :
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: Input string was not in a correct format.
Below is my coding :
if (ListFiles(directory, L"*", files)) {
for (vector<wstring>::iterator it = files.begin();
it != files.end();
++it) {
std::string filename = WStringToString(it->c_str());;
std::string s=filename;
String ^someString= gcnew String(s.c_str());
listBox1->Items->Add(String::Format(someString,"\n"));
// wcout << it->c_str() << endl;
}
}
Kidly help me plz guys... the program must make the filenames to be shown in the list ya in anyways, even its not in System::String as long its showed there is gud enough... i been working on this 3 days but nvr solved it.....
Regards,
Thilek
|
|
|
|
|
Hi,
String::Format requires the place holders ({0},{1}..) in the format string to work. You have used String::Format with an invalid format string. I can't see any need of String::Format here. As I understand, you need to add a newline character to the string. It can be done like
listBox1->Items->Add(String::Concat(someString,"\n")); BTW, a list shows one item in a row. So why do you need to add line break?
|
|
|
|
|
really thanks a lot my fren. its really helped me. about the newlinew was a silly mistake done by me after sitting and breaking my head for 3 days to solve it...
Thanks alot. God bless you.
|
|
|
|
|
You are welcome.
|
|
|
|
|
Why is this code throwing exception
gameBoard->gameBtns = gcnew array<Button^>(GameBoard::TOTAL_BOXES);
for each(Button^ btn in gameBoard->gameBtns)
btn->Enabled = true;
where TOTAL_BOXES is defined as 9
but this code doesn't
Button^ temp = gcnew Button();
temp->Enabled = true;
|
|
|
|
|
Hi,
Ahmed Manzoor wrote: Button^ temp = gcnew Button();
creates a button, so you can operate on it.
Ahmed Manzoor wrote: gameBtns = gcnew array<button^>(GameBoard::TOTAL_BOXES);
Does not generate any buttons, all it does is generate an array that will be able to hold some buttons.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
so I'll have to generate each button individually?
|
|
|
|