Click here to Skip to main content
16,012,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I'm trying to create checkboxs dynamically where that will places in rows & columns, i'm struggling with it for a couple of days and i completely run out of new ideas...
This part of program is working, but it's not exactly what i wanted to get:

Some thing like this alignment:



ch01 ch02 ch03 ch04
ch11 ch12 ch13 ch14
ch21 ch22 ch23 ch24

What I have tried:

const int tx =5;
		const int rx =8;
		int H1,L1;
		CRect rect;
		GetClientRect(&rect);
		H1 = rect.bottom/tx;
		L1 = rect.right/rx;

		for (int i=0;i<tx;i++)

		for (int j=0; j<rx; j++)
		{ 
		CPoint p;
		p.SetPoint(j*L1,i*H1);
		CButton* testbutton= new CButton();
		testbutton->Create(NULL, WS_VISIBLE | BS_AUTOCHECKBOX, CRect(10+p.x,10+p.y,H1+p.x,L1+p.y),this ,IDC_CHECK+(i+1)*(j+1)-1);
		
                q = IDC_CHECK+(i+1)*(j+1)-1;

		GetDlgItem(IDC_CHECK)->ShowWindow(SW_HIDE);
		testButton->GetCheck()==0;
		UpdateWindow();
Posted
Updated 9-Aug-19 6:06am
v6
Comments
[no name] 9-Aug-19 5:31am    
"but it's not exactly what i wanted to get".... And what exactly you like to get?
Satish Prattipati 9-Aug-19 5:44am    
create checkboxs or buttons in rows and columns.
Stefan_Lang 9-Aug-19 10:55am    
I have no idea if that helps, but in your second for loop, you always reset j, k, and q to 0 before creating your button - that means all buttons are in the same location. You probably need to move that initialization outside of the loop.
Satish Prattipati 9-Aug-19 11:32am    
yes, thanks

1 solution

It depends where this code is being performed. But one of the things you need to do (if you are not already) is handling the WM_SIZE message, and positioning each of the buttons correctly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900