|
-
December 14th, 2006, 04:52 AM
#1
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
-
December 14th, 2006, 04:58 AM
#2
Re: Creating array of buttons in Visual C++
The first question is - why do you need7wnat to create this array in the heap?
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.
-
December 14th, 2006, 05:03 AM
#3
Re: Creating array of buttons in Visual C++
Also MSDN has a couple of good Tutorials in VC++
- Sreehari
"Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us."
" Everybody is sent to Earth on a purpose. I am so Lagging behind that i won't die." – Calvin
-
December 14th, 2006, 05:16 AM
#4
Re: Creating array of buttons in Visual C++
can you do it without MFC
-
December 14th, 2006, 05:30 AM
#5
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
-
December 14th, 2006, 06:24 AM
#6
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
-
December 14th, 2006, 06:35 AM
#7
Re: Creating array of buttons in Visual C++
 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?
this one is working
Button Bbutt ;
but i need more
i trying to use
Button Bbutt [2];
What is Button ? Is ot still c# ?
Did you look at MSDN sample code in the link I had posted you?
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#?
-
December 14th, 2006, 07:02 AM
#8
Re: Creating array of buttons in Visual C++
No it's not C#, it's C++
buty form from C#
-
December 14th, 2006, 07:06 AM
#9
Re: Creating array of buttons in Visual C++
 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)!
-
December 14th, 2006, 07:25 AM
#10
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
-
December 14th, 2006, 07:35 AM
#11
Re: Creating array of buttons in Visual C++
I already posted you the "code with declaration"!
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.
-
December 14th, 2006, 07:50 AM
#12
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
-
December 15th, 2006, 01:36 AM
#13
Re: Creating array of buttons in Visual C++
unbelievably...
but fact
It's works )))))
Thank you
-
December 15th, 2006, 01:49 AM
#14
Re: Creating array of buttons in Visual C++
 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
-
December 15th, 2006, 03:45 AM
#15
Re: Creating array of buttons in Visual C++
 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"
I use Visual.Net
My project in C++ language
Not really. Probably, Managed C++/CLI?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|