|
|
#1 |
|
Senior Member
Join Date: Feb 2008
Location: SE London
Posts: 3,079
|
I'm having loads of fun messing about with the form designer, but I can't figure out how to add an array of controls.
I added a column of checkboxes and had to modify the code manually to turn them into an array to fit the backend code I'd already written, which was a bit of a pain. Now I want to add an array of text boxes and was hoping somebody knew of a quicker way? I've obviously used help and googled the matter but all I can find is how to code control arrays manually, which I already know how to do! Happy friday peeps! ![]()
__________________
All practise and no theory |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Dec 2006
Posts: 2,245
|
I don't quite understand what you're trying to achieve.
I think you might be better off on a C# forum - maybe the .Net one on www.webdeveloper.com. Or manic might come along and help, I think he's quite fluent in such things. |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Feb 2008
Location: SE London
Posts: 3,079
|
I'm just bored and caffeined up and I've been working on something in my spare time and was thinking about it just now.
I coded a form for a windows app in C# in notepad++. It took ages and looked pretty basic. It had an array of checkboxes and a parallel array of textboxes. An event handler attached to a button examines each checkBox via a loop and pulls text from the respective text box if a checkBox is ticked. I started messing about with Visual C# Express Edition and knocked up a better looking form in about 10 minutes. But when I looked at the underlying code VC#EE had come up with, it had declared all the checkboxes and textboxes as independant variables (i.e checkBox1, checkBox2...checkBoxN - where I'd coded checkBox[0], checkBox[1]...checkBox[N]). I went in manually and replaced the offending auto-code with my own which was a bit fiddly. Now I have to do the same with the textBoxes and I'm convinced there must be a quicker way. I wondered if there was a way to use the wysiwyg form editor to drop an array of controls onto a form without having to modify the auto-code myself?
__________________
All practise and no theory |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Apr 2007
Location: Chippenham
Posts: 371
|
Control arrays didn't make it from vb6 to the .net environment.
A quick search of my msdn suggests that the following articles may be of interest. ms-help://MS.MSDNQTR.v90.en/dv_vstechart/html/vbtchCreatingControlArraysInVisualBasicNETVisualCN ET.htm ms-help://MS.MSDNQTR.v90.en/dv_vstechart/html/controlarrays.htm |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Dec 2006
Posts: 2,245
|
OK, I'm not a C# person but I quickly bunged something together to see what I could learn that might be of use.
You could try this approach: Code:
foreach (Control blah1 in Form1.ActiveForm.Controls)
{
if (blah1 is System.Windows.Forms.CheckBox)
{
//Do your action
MessageBox.Show(blah1.Name);
}
}
|
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Feb 2008
Location: SE London
Posts: 3,079
|
Ta peeps
![]() This is essentially what I had in the event handler: Code:
for(int a=0;a<checkBox.Length;a++)
{
if(checkBox[a].Checked)
{
keywords += " " + keywordBox[a].Text;
}
}
*sigh* Thanks again
__________________
All practise and no theory |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Dec 2006
Posts: 2,245
|
I'm not sure why the control arrays thing hasn't been brought into Visual C# but I think it is just a case of trying to get everything to behave in a similar way.
You could add the checkbox and textbox controls to the page dynamically - http://msdn.microsoft.com/en-us/libr...00(VS.71).aspx |
|
|
|
|
|
#8 |
|
Senior Member
Join Date: Feb 2008
Posts: 1,296
|
Why did people stop writing C? At least it was legible ...
... come to think of it why did people stop writing assembler? At least you could debug it with the minimum of tools. |
|
|
|
|
|
#9 | |
|
Senior Member
Join Date: Apr 2007
Location: Chippenham
Posts: 371
|
Writing C against the windows api is a nightmare. I started windows programming with C and the windows 3.0 sdk. Switching on message id and then decoding wparam and lparam is not pretty code. And registering classes to allocate window extra bytes so you could associate data with specific windows is again ugly and time consuming. The first version of the MFC was a godsend. Still did a lot of graphics with direct calls rather than the wrapped up CDC stuff -- but for message handling and per-window data it were good.
Quote:
Realistically for most apps [rather than embedded code - which is world I've never visited] there's no point in writing assembler -- unless you want to re-write and re-optimise everytime the instruction set is extended or the pipe lining rules change. I've only written one assembler app in over fifteen years of professional coding. |
|
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Feb 2008
Posts: 1,296
|
Most of my work was realtime embedded stuff. Once we got into C, we could produce more machine code per unit time, but ultimately the statistic of 10 lines of PROPERLY SPECIFIED, DESIGNED, and TESTED code per day still stood. Its just that the "10 lines" represented 10 C statements instead of assembler instructions.
Debugging was cool, until microprocessors came along. Until then, to debug, all you did was halt the clock with a key on the front panel. Neons (or leds) would show you the status of each bit in each register, and on each bus. You could single step or clock slowly to watch what was happening. As soon as you put the entire cpu into one IC you no longer had access to that info, you relied on an ICE and an expensive debugger program. PITA!! |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|