|
Access the text. If it's System::String, then you can use the IndexOf and Substring methods. Note that this is more than 10 times slower than C/C++ functions for very large strings, which is what I found out today when I rewrote a block of code to see if unmanaged version would be faster than the managed version for immutable System::String type.
|
|
|
|
|
I'm struggling for a couple of days now. i have two forms,
The main form and some popup form with textboxes.
I open the popupform from the mainform then fill in some information on
the popupform and send it with a button. When that button is clicked
the mainform has to detect it and grab the data from the popupform before closing it.
but so far i'm not able to get that click event from the popupform
i tried the following which will compile but does nothing:
rowpopup^ popup = gcnew rowpopup();
popup->button_savetoform->Click += gcnew EventHandler(this, &Main::add_new_item);
I got some advice to work with delegates and after a lot of reading and googling
i still couldn't find how to use it in this situation.
Does anyone have an idea?
|
|
|
|
|
the code you write is actually....working....so...if you write here or post as attachment the full code i will check what's wrong
|
|
|
|
|
OK, i wrote a little test program which does the same.
#pragma once
#include "form2.h"
namespace Test2 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ testbutton;
private: System::Windows::Forms::Label^ testlabel;
private: System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
public:
void InitializeComponent(void)
{
this->testbutton = (gcnew System::Windows::Forms::Button());
this->testlabel = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
this->testbutton->Location = System::Drawing::Point(12, 326);
this->testbutton->Name = L"button_test";
this->testbutton->Size = System::Drawing::Size(75, 23);
this->testbutton->TabIndex = 0;
this->testbutton->Text = L"Test";
this->testbutton->UseVisualStyleBackColor = true;
this->testbutton->Click += gcnew System::EventHandler(this, &Form1::testbutton_click);
this->testlabel->AutoSize = true;
this->testlabel->Location = System::Drawing::Point(9, 19);
this->testlabel->Name = L"label_test";
this->testlabel->Size = System::Drawing::Size(35, 13);
this->testlabel->TabIndex = 1;
this->testlabel->Text = L"";
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(382, 361);
this->Controls->Add(this->testlabel);
this->Controls->Add(this->testbutton);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
this->PerformLayout();
Form2^ popup = gcnew Form2();
popup->button_send->Click += gcnew System::EventHandler(this, &Form1::raised_event);
}
private:
#pragma endregion
private: System::Void testbutton_click(System::Object^ sender, System::EventArgs^ e) {
testlabel->Text = "new form open";
Form2^ popup = gcnew Form2();
popup->ShowDialog();
}
private: void raised_event (System::Object^ sender, System::EventArgs^ e)
{
Form2^ popup = gcnew Form2();
testlabel->Text = popup->textbox->Text;
}
};
}
Form2
#pragma once
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 Test2 {
public ref class Form2 : public System::Windows::Forms::Form
{
public:
Form2(void)
{
InitializeComponent();
}
protected:
~Form2()
{
if (components)
{
delete components;
}
}
public: System::Windows::Forms::RichTextBox^ textbox;
protected:
public: System::Windows::Forms::Button^ button_send;
protected:
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->textbox = (gcnew System::Windows::Forms::RichTextBox());
this->button_send = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
this->textbox->Location = System::Drawing::Point(12, 12);
this->textbox->Name = L"textbox";
this->textbox->Size = System::Drawing::Size(268, 147);
this->textbox->TabIndex = 0;
this->textbox->Text = L"";
this->button_send->Location = System::Drawing::Point(12, 165);
this->button_send->Name = L"button_send";
this->button_send->Size = System::Drawing::Size(75, 23);
this->button_send->TabIndex = 1;
this->button_send->Text = L"Send";
this->button_send->UseVisualStyleBackColor = true;
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 198);
this->Controls->Add(this->button_send);
this->Controls->Add(this->textbox);
this->Name = L"Form2";
this->Text = L"Form2";
this->Load += gcnew System::EventHandler(this, &Form2::Form2_Load);
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void Form2_Load(System::Object^ sender, System::EventArgs^ e) {
textbox->Text = "hoi";
}
};
}
|
|
|
|
|
so....here we are:
in form 1 substitute:
private: System::Void testbutton_click(System::Object^ sender, System::EventArgs^ e) {
testlabel->Text = "new form open";
Form2^ popup = gcnew Form2();
popup->ShowDialog();
}
private: void raised_event (System::Object^ sender, System::EventArgs^ e)
{
Form2^ popup = gcnew Form2();
testlabel->Text = popup->textbox->Text;
}
};
private:
Form2^ popup;
void testbutton_click(System::Object^ sender, System::EventArgs^ e) {
testlabel->Text = "new form open";
popup = gcnew Form2();
popup->button_send->Click += gcnew EventHandler(this, &Form1::raised_event);
popup->ShowDialog();
}
void raised_event (System::Object^ sender, System::EventArgs^ e)
{
testlabel->Text = popup->textbox->Text;
}
i'm pretty sure you'll understand my changes.
Maybe it would be better to use delegates....i'll write you some code for that
#pragma once
#include "Form2.h"
namespace delete1 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private:
void testbutton_click(System::Object^ sender, System::EventArgs^ e) {
testlabel->Text = "new form open";
Form2^ popup = gcnew Form2();
popup->myPersonalDelegateCl += gcnew Form2::myPersonalDelegate(this,&Form1::raised_from_delegate);
popup->ShowDialog();
}
void raised_from_delegate (String ^txt)
{
this->testlabel->Text=txt;
}
System::Windows::Forms::Button^ testbutton;
System::Windows::Forms::Label^ testlabel;
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->testbutton = (gcnew System::Windows::Forms::Button());
this->testlabel = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
this->testbutton->Location = System::Drawing::Point(12, 326);
this->testbutton->Name = L"button_test";
this->testbutton->Size = System::Drawing::Size(75, 23);
this->testbutton->TabIndex = 0;
this->testbutton->Text = L"Test";
this->testbutton->UseVisualStyleBackColor = true;
this->testbutton->Click += gcnew System::EventHandler(this, &Form1::testbutton_click);
this->testlabel->AutoSize = true;
this->testlabel->Location = System::Drawing::Point(9, 19);
this->testlabel->Name = L"label_test";
this->testlabel->Size = System::Drawing::Size(35, 13);
this->testlabel->TabIndex = 1;
this->testlabel->Text = L"";
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(382, 361);
this->Controls->Add(this->testlabel);
this->Controls->Add(this->testbutton);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
};
}
#pragma once
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 Test2 {
public ref class Form2 : public System::Windows::Forms::Form
{
public:
Form2(void)
{
InitializeComponent();
}
delegate void myPersonalDelegate(String ^txt);
myPersonalDelegate^ myPersonalDelegateCl;
protected:
~Form2()
{
if (components)
{
delete components;
}
}
private:
void Form2_Load(System::Object^ sender, System::EventArgs^ e) {
textbox->Text = "hoi";
}
void button_send_Click(System::Object^ sender, System::EventArgs^ e) {
this->myPersonalDelegateCl(this->textbox->Text);
}
System::Windows::Forms::RichTextBox^ textbox;
System::Windows::Forms::Button^ button_send;
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->textbox = (gcnew System::Windows::Forms::RichTextBox());
this->button_send = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
this->textbox->Location = System::Drawing::Point(12, 12);
this->textbox->Name = L"textbox";
this->textbox->Size = System::Drawing::Size(268, 147);
this->textbox->TabIndex = 0;
this->textbox->Text = L"";
this->button_send->Location = System::Drawing::Point(12, 165);
this->button_send->Name = L"button_send";
this->button_send->Size = System::Drawing::Size(75, 23);
this->button_send->TabIndex = 1;
this->button_send->Text = L"Send";
this->button_send->UseVisualStyleBackColor = true;
this->button_send->Click += gcnew System::EventHandler(this, &Form2::button_send_Click);
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 198);
this->Controls->Add(this->button_send);
this->Controls->Add(this->textbox);
this->Name = L"Form2";
this->Text = L"Form2";
this->Load += gcnew System::EventHandler(this, &Form2::Form2_Load);
this->ResumeLayout(false);
}
#pragma endregion
};
}
ps1 alway split code in .h and in .cpp
ps2 don't ever write personalized code between #pragma region Windows Form Designer generated code and #pragma endregion
modified on Friday, May 21, 2010 5:27 AM
|
|
|
|
|
The delegate works perfect Thank you
the other code raised the event but didn't get the information from the textbox.
so i'll study the delegate.
Just one quiestion you changed the namespace of Form1 this results in compiler errors.
is there a reason you did this?
|
|
|
|
|
it was just the name i used...so no reason for that
|
|
|
|
|
there is simplest way if you are still enterested
|
|
|
|
|
Hi ,
when i am trying to build managed c++ project in visual studio .net 2003 , i am getting this kind of
description in output window,and not able to generate .exe.
Microsoft (R) .NET Resource Generator
[Microsoft .Net Framework, Version 1.1.4322.2443]
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.
Usage:
ResGen inputFile.ext [outputFile.ext]
ResGen /compile inputFile1.ext[,outputFile1.resources] [...]
Where .ext is .resX, .txt, or .resources
Converts files from one resource format to another. If the output
filename is not specified, inputFile.resources will be used.
The /compile option takes a list of .resX or .txt files to convert to
.resources files in one bulk operation, replacing .ext with .resources for
the output file name.
.txt files have this format:
# Use # at the beginning of a line for a comment character.
name=value
more elaborate name=value
and I am getting warnings like this
XtendedMenu warning LNK4099: PDB 'libc.pdb' was not found with 'C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib\nochkclr.obj' or at 'D:\HandHelld\projects\SVNRep-HandHeld\Trunk\QCID\Source\QCID\WIN\QCID\Release\libc.pdb'; linking object as if no debug info
NetSegmentedProgressControl warning LNK4099: PDB 'libc.pdb' was not found with 'C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib\nochkclr.obj' or at 'D:\HandHelld\projects\SVNRep-HandHeld\Trunk\QCID\Source\QCID\WIN\QCID\Release\libc.pdb'; linking object as if no debug info
NetSRPControl warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
NetSRPControl warning LNK4099: PDB 'libc.pdb' was not found with 'C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib\nochkclr.obj' or at 'D:\HandHelld\projects\SVNRep-HandHeld\Trunk\QCID\Source\QCID\WIN\QCID\Release\libc.pdb'; linking object as if no debug info
NetBarGraphControl warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
NetBarGraphControl warning LNK4099: PDB 'libc.pdb' was not found with 'C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib\nochkclr.obj' or at 'D:\HandHelld\projects\SVNRep-HandHeld\Trunk\QCID\Source\QCID\WIN\QCID\Release\libc.pdb'; linking object as if no debug info
The application is not generating .resources files in release build, where as in Debug build , i am getting same warnings ,still able to generate .exe. In release build not able to generate exe and resource files (.resources from .resx)
Any help is greatly appreciated.
Thanks,
sharada veena.
|
|
|
|
|
hello
i have to deliver a project to the doctor and i need a simple program or rich example in vc++.net please
& thank u all
|
|
|
|
|
Nobody here has the time to do your work for you. If you need a sample of some type of coding then look at the articles here on CodeProject and also use Google/Bing to search the internet.
It's time for a new signature.
|
|
|
|
|
Hi,
I have written a piece of code to save data from a Windows form in a file, and to read it from the file back into the Windows form. This works fine on the computer on which I've written the code (Windows 7). However, now I try to run the program on another computer (Windows XP), and a strange thing happens: when I read the data from the file, a rectangle character appeard at the end of each line.
When I write the data to the file, another such character is written to the file. So every time I save and read a file, an extra rectangle character is added. I'm using streamwriter / streamreader for the file input / output. Any idea how to prevent this strange behaviour?
|
|
|
|
|
Can someone tell me how to use sizeof() during debugging by any means at all (watch, immediate window, etc...)? All I keep getting are stupid error messages. For instance, in the Immediate window I typed:
? sizeof(bool)
which gave me the message
error: identifier 'sizeof' out of scope
I can't seem to find documentation for this anywhere.
Thanks.
|
|
|
|
|
In C#, and in C++, sizeof is an operator, and not a function. It is something that is calculated at compile-time, and not at run-time. As such, the debugger does not know the sizeof operator, as it is a language-specific way of expressing an operator.
The way your type your expression, the debugger will interpret it as:
Call Debug.Print(sizeof(bool))
Since the sizeof function does not exist, you get an out of scope error message.
|
|
|
|
|
Xpnctoc wrote: All I keep getting are stupid error messages.
On the contrary, you are getting helpful error messages. You just need to use the information to help you figure out what is happening.
It's time for a new signature.
|
|
|
|
|
I have never done this before, but I'm going to have to disagree with nearly everything that has been put forth in the responses so far.
I created a new scratch C++/CLI project to see if there was a problem in the way my other C++ project was configured. However, using sizeof in the Immediate window continues to produce the "out of scope" error.
Then I created a new scratch C# project to put Michel's response to the test. When I type
? sizeof(bool)
in the Immediate window, it returns an output of "1". So whatever is going on with "sizeof" in C++/CLI is not extendable to C#.
Regarding Richard's comment about me calling the "out of scope" message stupid, I'm going to stand by what I said. "Sizeof" -- especially if Michel is right calling it an operator rather than a function -- is part of the language. It's not some custom function of some special class where an extra reference is needed. So how can it ever be out of scope? In that regard, the message makes no sense. Therefore it is utterly unhelpful. That makes it, IMHO, fully deserving of the label "stupid".
|
|
|
|
|
I still stand by my answer. In c#, the debugger can use the .Net compiler support libraries to compile your statement on the fly. In native code, there is no such thing.
I must admit that I've never tried it in C#, but in unmanaged C++, this behaviour is 'expected'.
Whether to label it stupid, is is entirely up to you.
|
|
|
|
|
But I'm not dealing with strictly unmanaged C++ anyway. My project is a "mixed mode" C++/CLI project. By definition, the project has to be .NET-aware. And the breakpoint that I set was actually in a managed code section (i.e., in one of the Windows Forms event handlers). So why can't it use the same .NET compilation support as C#?
Even if the project was 100% unmanaged, the compiler still has to convert a sizeof call into a useable via some kind of library. Why can't the debugger make use of that part of the compiler?
I don't label the problem itself as "stupid". I obviously don't understand it and was trying to get some clarification. What I do label as "stupid" is the "out of scope" error message. It just seems to me that there has to be a lot better/more helpful wording for when this error condition is encountered -- something like:
"'Sizeof' operator is unsupported in debugging."
If they had a truly informative error message like that, I wouldn't have had to start this post to begin with. It still wouldn't answer the "why" questions, but at least it would be a lot less cryptic than some vague "out of scope" message. After all, if sizeof is an operator rather than a function as you originally suggested, how the heck can an operator -- a built-in part of the language -- be out of scope?
|
|
|
|
|
Xpnctoc wrote: the compiler still has to convert a sizeof call into a useable via some kind of library.
No it merely calculates the size of the operand and puts the resulting value in the object code. There is no associated library call because sizeof() is an operator, just like + .
Xpnctoc wrote: If they had a truly informative error message
I think this rant should be directed at Microsoft.
It's time for a new signature.
|
|
|
|
|
Richard MacCutchan wrote: No it merely calculates the size of the operand and puts the resulting value in the object code. There is no associated library call because sizeof() is an operator, just like +.
And yet other operators like + and == are fully accessible within the Immediate window. You said it yourself... there is no associated library because sizeof is an operator. How can any operator -- an integral part of the language -- ever be out of scope? I mean, wouldn't it strike you as really messed up if suddenly you got an error message saying + was "out of scope"?
If 'sizeof' is only evaluated at compile time and treated as a constant in the executable, and Immediate cannot access it as part of the available evaluation syntax, then it seems to me 'sizeof' would be better termed as a MACRO than an operator -- just like using the #define precompiler directive.
|
|
|
|
|
Well, you are right in all you say and I am (partly) wrong. My biggest mistake was to take your query at face value, rather than checking what results I get. I have just tested this by adding sizeof(variable) in my watch window while debugging and it shows the correct value. So, we go back to the original problem that you are seeing: where exactly, and under what conditions, are you typing your query?
It's time for a new signature.
|
|
|
|
|
The actual query I'm using is what I originally listed:
? sizeof(bool)
rather than
? sizeof(boolean_variable)
To reproduce what I'm getting:
1. Make a new project: C++, CLR, Windows Forms Application
2. Double-click the form to generate the Form_Load event.
3. Put a break point on the closing brace of the Form_Load event handler method.
4. Run the application.
5. When the break point is hit, bring up the Immediate window and type "? sizeof(bool)" (without the quotes, of course)
6. Result is: "error: identifier 'sizeof' is out of scope"
If you take identical steps but use a C# project, you will get an output of "1". Michel had mentioned that we should expect the error message in unmanaged C++, but from the steps I've outlined above, we're not dealing with unmanaged C++. We're dealing with CLR-aware C++, so it seems to me we should have the same .NET support as C#.
BTW, this is under VS 2008 (and Windows 7 64-bit if that makes a difference).
|
|
|
|
|
OK, I can reproduce this under VS2010 (full and Express versions). I guess the only way forward is to raise this with Microsoft. I'm still confused as to why this happens with managed but not unmanaged code; I guess two different debuggers.
It's time for a new signature.
|
|
|
|
|
Hi all, could any one help me out of this
I just want to include a logo.jpg file in my .exe file. I have tried using Image Class (System.Drawing) in Visual C++, but after opening the .exe, and when tried to print, an error is popping up indicating the logo.jpg is missing, it is successful only after including the logo.jpg in the folder.
private: System::Void printDocument_PrintPage(System::Object^ sender, System::Drawing::Printing::PrintPageEventArgs^ e)<br />
{<br />
Image^ newImage = Image::FromFile( "logo.jpg" );<br />
e->Graphics->DrawImage( newImage, 605, 70, 150, 100 );<br />
}
I want to know, is there any other method of including the logo to my print page, which doesn't need a logo.jpg file to be included in the respective folder
Any help is appreciated...Thanks
|
|
|
|
|
this is msdn link[^] what are you looknig for, you can also google for "visual studio resource resx"
...if you are using "visual c++" or "visual c#" this is made so easy by using the designer
|
|
|
|
|