Creating array of buttons in Visual C++
Dear All
I have code in C# program:
int myHeight=30;
int myWidth=90;
Button[,] ba = new Button[2, 2];
for (int i=0; i<2;i++)
for (int j = 0; j < 2; j++)
{
ba[i, j] = new System.Windows.Forms.Button();
ba[i, j].Height = myHeight;
ba[i, j].Width = myWidth;
ba[i, j].Location = new Point( i * myWidth,j * myHeight);
ba[i, j].Text = i.ToString() + j.ToString();
panel1.Controls.Add(ba[i, j]);
}
How write it in VC++?
My problem is
Button[,] ba = new Button[2, 2];
I do not know how write it in VC++
thank you
Re: Creating array of buttons in Visual C++
The first question is - why do you need7wnat to create this array in the heap? :confused:
Why not just set the class member variable:
Code:
CButton m_arButton[2, 2];
Then you could create the button controls using CButton::Create method.
See MSDN for details.
Re: Creating array of buttons in Visual C++
Also MSDN has a couple of good Tutorials in VC++
Re: Creating array of buttons in Visual C++
can you do it without MFC
Re: Creating array of buttons in Visual C++
Sure! but it would be more complex than using MFC.
Create a Win32 project.
Declare the array:
Code:
HWND hwndButton[2, 2,];
And read MSDN in "Platform SDK: Windows User Interface" section about buttons, button creating and using:
Buttons
Using Buttons
Re: Creating array of buttons in Visual C++
this code
CButton m_arButton[2, 2];
and
HWND hwndButton[2, 2,];
does not work without new *.h files.
this one is working
Button Bbutt ;
but i need more
i trying to use
Button Bbutt [2];
but
------ Build started: Project: pka, Configuration: Debug Win32 ------
Compiling...
pka.cpp
d:\alex\projects\pka\pka\Form1.h(366) : error C2728: 'System::Windows::Forms::Button' : a native array cannot contain this managed type
Did you mean 'array<System::Windows::Forms::Button>'?
d:\alex\projects\pka\pka\Form1.h(366) : error C2227: left of '->{ctor}' must point to class/struct/union/generic type
Build log was saved at "file://d:\alex\Projects\pka\pka\Debug\BuildLog.htm"
pka - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
My project use standard windows libraries, without ATL
Re: Creating array of buttons in Visual C++
Quote:
Originally Posted by alexon1ine
this code
CButton m_arButton[2, 2];
and
HWND hwndButton[2, 2,];
does not work without new *.h files.
What do you mean?
Have you created a new VC++ project? Which type of project?
Quote:
this one is working
Button Bbutt ;
but i need more
i trying to use
Button Bbutt [2];
What is Button ? Is ot still c# ? :confused:
Did you look at MSDN sample code in the link I had posted you?
Quote:
but
------ Build started: Project: pka, Configuration: Debug Win32 ------
Compiling...
pka.cpp
d:\alex\projects\pka\pka\Form1.h(366) : error C2728: 'System::Windows::Forms::Button' : a native array cannot contain this managed type
Did you mean 'array<System::Windows::Forms::Button>'?
d:\alex\projects\pka\pka\Form1.h(366) : error C2227: left of '->{ctor}' must point to class/struct/union/generic type
Build log was saved at "file://d:\alex\Projects\pka\pka\Debug\BuildLog.htm"
pka - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
My project use standard windows libraries, without ATL
IWhat is "System::Windows::Forms::Button"?
Is it still c#? :confused:
Re: Creating array of buttons in Visual C++
No it's not C#, it's C++
buty form from C#
Re: Creating array of buttons in Visual C++
Quote:
Originally Posted by alexon1ine
No it's not C#, it's C++
buty form from C#
Sounds like this is a problem (form from C# in the c++ project)!
Re: Creating array of buttons in Visual C++
thanks for all of your for help :)
I need learn more
Anyone used the array of the buttons in C++?
If yes, plz write code with declaration
Re: Creating array of buttons in Visual C++
I already posted you the "code with declaration"! :mad:
If you are not be able to use it properly - it is your problem! However, you are always welcome to get some help. The only thing you have to do in this case - provide some useful information about your problem and the code being used.
If you can't let your project work with an array of buttons - please begin with only one button. After such a project will have worked - change the button declaration to the array and try with it.
Re: Creating array of buttons in Visual C++
Are we talking about Managed C++/CLI? Then we're in the wrong forum, but anyway:
Code:
// create 2d array of buttons
cli::array<Button^, 2>^ buttons = gcnew cli::array<Button^, 2>(2, 2);
// initialize buttons
for (int x = 0; x < 2; ++x)
{
for (int y = 0; y < 2; ++y)
{
buttons[x, y] = gcnew Button();
//...
}
}
- petter
Re: Creating array of buttons in Visual C++
unbelievably...
but fact
It's works :))))))
Thank you
Re: Creating array of buttons in Visual C++
Quote:
Originally Posted by wildfrog
Are we talking about Managed C++/CLI? Then we're in the wrong forum, but anyway:
- petter
Where is it C++/CLI forum?
I use Visual.Net
My project in C++ language
Re: Creating array of buttons in Visual C++
Quote:
Originally Posted by alexon1ine
Where is it C++/CLI forum?
http://www.codeguru.com/forum/forumd...aysprune=&f=17 - just goto the combobox "Forum Jump" and select "Managed C++ and C++/CLI"
Quote:
I use Visual.Net
My project in C++ language
Not really. Probably, Managed C++/CLI? :rolleyes:
Re: Creating array of buttons in Visual C++
You are a rights
Managed C++/CLI