Probably need to show more than two lines of code. Also, as seeplus mentioned, not many people here actively use C++\CLI, so you're less likely to get help, but I could still try.
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 Form2
/// </summary>
///
ref class MyForm;
public ref class Form2 : public System::Windows::Forms::Form
{
public:
// Add a member function
void OnClickFunc();
public:
Form2(void)
{
//
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form2()
{
if (components)
{
OnClickFunc();
delete components;
}
if you don't mind me asking but why don't many people use C++\Cli ?
To be blunt, I do not use it because it is a screwy syntax extension attempting to solve a nonexistent problem that exists because microsoft felt a total do-over was better than simply updating and fixing MFC and, IMHO, because M$ wants you to use C# instead.
If they had not decided to mangle it, I would have used it. The xor stuff + the weird dynamic memory stuff is just pointless -- they could have hidden the dynamic memory instead of forcing use of garbage collection. All they really had to do there was use .. smart pointers, which the language supports.
Some formatting & indentation would not hurt either
Reading a huge wall of text without formatting and indentation makes getting a tooth extracted without anesthetic a less painful experience.
Why don't more programmers use C++/CLI? MS bloat and unneeded mangling of C++. The original WinAPI was C-based, and was somewhat of a nightmare to learn since the API was so huge. C++/CLI is IMO worse.
MS did the same thing with BASIC, turning it into Visual Basic. A Frankenstein's Monster that wasn't easy to learn and a PITA to do anything. It was the all the less than perfect C-based WinAPI ideas on steroids.
C# is yet another "we think we can do better, but it will end up making things worse" MS innovation that coddles and hobbles a programmer unnecessarily. Good programmers don't need to have their hand held by garbage collection, etc. Mediocre and bad programmers will find ways to trash memory despite it.
I think i've have found away round my problem now but will need to modify my code now to suit. How long it takes me find solutions when I get stuck I think I might go back to my borland C++ instead because I'm only an amature anyway.
C++/CLI is NOT ISO Standard C++. Never was, never will be.
I'm a hobbyist myself, and I prefer using tools that are as up-to-date, C++20 currently, as possible. So I use VS 2019/2020, Code::Blocks with a tweak to use an easily updated compiler, MSYS 2. 2 IDEs and one command-line compiler set-up.
Using Borland C++ will restrict severely what you can use in the C++ toolbox.
if you want to use the CLI, use it. it works, and there are examples and help online. Its just not popular; if it were anything other than microsoft's junk it would have 0 people using it (apart from its author and his best friend). Because it is microsoft, though, people use it and support/help/examples/etc exist, and M$ is usually fairly good with documentation as well.
Borland has been out of the game for decades. Builder is being kept up, sort of, if you can find a reasonably modern build for it that would be "ok". Its a very easy gui builder.
Actually I think its the GDI? CLI is usually 'command line interface', GDI is one of visual studio's windowing systems, and the managed gibberish .. I don't know its official name apart from 'managed'. If they called the managed GUI stuff CLI, ... sigh ..
Borland has morphed into Embarcadero - and there is still Delphi and C++! It's 'advantage' are the VCL components (based upon the old 'OWL'). The C++ compiler is based upon Clang and there are also some free versions for non-commercial usage.
C++/cli is MS's second attempt to merge C++ with .net (the previous version was just called Managed C++). It's Herb Sutter's baby - he did the design etc. And in IMO got it wrong. All that 'boxing' with ^ etc for the 'managed variables' et al. If you want to use .net then use c# (or vb.net if that's your tipple). We looked at it a while ago and basically said 'yuk'.