Buy here

  • Buy music products with Andertons Music Company
  • Buy music products with drumwright
  • Buy music products with Hartnolls Guitars
  • Buy music products with Thomann
  • Buy music products with Red Dog Music
  • Buy music products with Scan Computers
  • Buy music products with Professional Music Technology
Old 02-27-2009, 10:35 AM   #1
dafuzz
Senior Member
 
dafuzz's Avatar
 
Join Date: Feb 2008
Location: SE London
Posts: 3,079
Default Visual C#

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
dafuzz is offline   Reply With Quote
Old 02-27-2009, 11:35 AM   #2
roundthebend
Senior Member
 
roundthebend's Avatar
 
Join Date: Dec 2006
Posts: 2,245
Default

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.
roundthebend is offline   Reply With Quote
Old 02-27-2009, 12:08 PM   #3
dafuzz
Senior Member
 
dafuzz's Avatar
 
Join Date: Feb 2008
Location: SE London
Posts: 3,079
Default

Quote:
Originally Posted by roundthebend View Post
I don't quite understand what you're trying to achieve
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
dafuzz is offline   Reply With Quote
Old 02-27-2009, 12:35 PM   #4
arrowodd
Senior Member
 
arrowodd's Avatar
 
Join Date: Apr 2007
Location: Chippenham
Posts: 371
Default

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
arrowodd is offline   Reply With Quote
Old 02-27-2009, 12:53 PM   #5
roundthebend
Senior Member
 
roundthebend's Avatar
 
Join Date: Dec 2006
Posts: 2,245
Default

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);
               }
            }
roundthebend is offline   Reply With Quote
Old 02-27-2009, 01:07 PM   #6
dafuzz
Senior Member
 
dafuzz's Avatar
 
Join Date: Feb 2008
Location: SE London
Posts: 3,079
Default

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;
   }
}
What was wrong with that???

*sigh*

Thanks again
__________________
All practise and no theory
dafuzz is offline   Reply With Quote
Old 02-27-2009, 01:20 PM   #7
roundthebend
Senior Member
 
roundthebend's Avatar
 
Join Date: Dec 2006
Posts: 2,245
Default

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
roundthebend is offline   Reply With Quote
Old 02-27-2009, 02:47 PM   #8
musophilr
Senior Member
 
Join Date: Feb 2008
Posts: 1,296
Default

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.
musophilr is online now   Reply With Quote
Old 02-27-2009, 03:05 PM   #9
arrowodd
Senior Member
 
arrowodd's Avatar
 
Join Date: Apr 2007
Location: Chippenham
Posts: 371
Default

Quote:
Originally Posted by musophilr View Post
Why did people stop writing C? At least it was legible ...
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:
Originally Posted by musophilr View Post
... come to think of it why did people stop writing assembler? At least you could debug it with the minimum of tools.
Not when you writing assembler on a scrap of paper, encoding it to hex and poking it into a ZX81's memory it wasnt. debugger? didn't have a bloody assembler. [did get one for spectrum though].

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.
arrowodd is offline   Reply With Quote
Old 02-27-2009, 03:14 PM   #10
musophilr
Senior Member
 
Join Date: Feb 2008
Posts: 1,296
Default

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!!
musophilr is online now   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:05 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.