Author Topic: Windows form coding help required.  (Read 1814 times)

0 Members and 1 Guest are viewing this topic.

mr_nick

  • Guest
Windows form coding help required.
« on: July 30, 2013, 09:42:39 AM »
OK, so I'm tentatively trying to get started with dotnet and am, as a means of learning the ropes, trying to port some of my old vlisp routines. I am getting the basics working (more or less) but there are some things that I'm not sure how to achieve so hope someone can help.

For this particular situation, I am trying to create a dialog box - a job for which I normally use ODCL. Again I have the basics working but some of it is currently very long-winded so want to try and trim it down a bit if possible.

On the dialog I have multiple pictureboxes and what I want to be able to do is press a button which will change the backcolor of all of them in one go. At this point in time I have simply got the same command many times over with just a different control name:

Code: [Select]
this.pictureBox1.BackColor = System.Drawing.Color.Green;
this.pictureBox2.BackColor = System.Drawing.Color.Green;
this.pictureBox3.BackColor = System.Drawing.Color.Green;

As you can appreciate, with many pictureboxes this makes for a lot of replication and I would ideally like to get away from that.

In my lisp/ODCL code I can create a loop which will allow me to modify multiple items as below:

Code: [Select]
(setq cnt 0)
(repeat 20
  (dcl_Control_SetBackColor (eval (read (strcat " MyDialog_Ctrl" (itoa (setq cnt (1+ cnt)))))) 3 )
)

So what I would like to know is how to replicate this type of loop in C# so that I can do away with the plethora of replicated lines?

huiz

  • Swamp Rat
  • Posts: 913
  • Certified Prof C3D
Re: Windows form coding help required.
« Reply #1 on: July 30, 2013, 10:21:43 AM »
For each myControl as Control in Me
 Mycontrol.BackColor = green
Next


Something like that. You can also check for the type of myControl if it is a Picturebox.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: Windows form coding help required.
« Reply #2 on: July 30, 2013, 10:31:56 AM »
The form you're creating is a container for control objects, you can iterate through the objects like a collection using for each statement.  It's also possible to create a collection of objects (list, hash set, dictionary...) on your form of you want more granular control over what objects are being changed

mr_nick

  • Guest
Re: Windows form coding help required.
« Reply #3 on: July 30, 2013, 10:48:52 AM »
Perfect. Thanks for the guidance - I have it working now. Onwards and upwards... hopefully.