That's great. It all works - I can experiment further now I have a working example. Thanks for your help.
Ted
That's great. It all works - I can experiment further now I have a working example. Thanks for your help.
Ted
I think I can see what you are suggesting and am trying to experiment with it in a new application as here: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace IndexComponents { public partial class Form1 : Form { private ProgressBar pb1; private ProgressBar pb2; private ProgressBar pb3; private List _bars; public Form1() { InitializeComponent(); int[] someArrayWithTheValues = new int[3] { 1, 2, 3 }; //Field declaration in the Form/UserCotrol /// private List _bars; //somewhere after the InitializeComponents call /// _bars = new List(new ProgressBar[] { pb1, pb2, pb3 });//when you want to update the bars _bars = new List(new ProgressBar[] { pb1, pb2, pb3 });//when you want to update the bars for (int i = 0; i < 3; i++) { _bars[i] = someArrayWithTheValues[i]; } //With the mod operator you could also easily switch which hour should be displayed at the top: int hourToDisplayAtTop = 2; for (int i = 0; i < 3; i++) { _bars[i] = someArrayWithTheValues[(i + hourToDisplayAtTop) % 24]; } } } } I am now working on the last two(I hope!) build error which are flagged within the two for loops as below: Error 1 Cannot convert type 'int' to 'System.Windows.Forms.ProgressBar' Error 2 Cannot implicitly convert type 'int' to 'System.Windows.Forms.ProgressBar' Ted Edwards
Thanks for the suggestion Robert. The progress bars display the output of a pressure sensor over a 24 hour period. When I get a new reading, I shift values chronologically "down" one bar and put the new value in the "top" (most recent) bar. The coding begs for an iterative loop but I don't know how to address the bars name property with the index. So I ended up using a switch construct which works okay but is awkward to maintain. The List class is new to me and on your suggestion I had a quick look at it. I must say, it does not look promising but will try it out if I can.
Ted
But I'll need to do it again somewhere - and again, and again.........
Ted Edwards
If I'm in the wrong place or this is a stupid question I apologise in advance. I am having to write a data acquisition program in .NET (C#) before I’ve had time to learn it which is making for some interesting code. What I would really like to do is reference a group of 24 progress bar components within a for/next loop using the index of the loop. Does anyone know how to do this? The code I use at the moment is very inelegant and bugs me. Would appreciate any pointers (sorry ‘bout pun)
Ted Edwards
Thanks for all the help - everything is working now. A quirk was that I had event handler for form plugged in from both code and form event handler properties which compiled okay but handler was called twice when run. regards,
Ted Edwards
Yes, I think I see what you mean - I am trying it but the new form keyboard event handler is having trouble with the statment: if (e.KeyChar >= 48 && e.KeyChar <= 57) which gives an error Error: 'System.Windows.Forms.KeyEventArgs' does not contain a definition for 'KeyChar' What you both suggested seems to be the correct approach for what I need. I will investigate further...
Ted Edwards
Thanks Martin, I think you have pointed me in the right direction. It works if I point each component's KeyDown event handler at the new form KeyDown event handler. I will have to differentiate between keys or the components which are suppose to accept new values from the keyboard - won't! Thanks for your help,
Ted Edwards
Can anyone explain to me how I can detect a key pressed and deal with it in one piece of code whatever component has the current focus. I have trawed through the help files but most of what is thrown up pre-supposes a certain level of knowledge (i.e. that you know what you are doing!). I have a little program which controls the speed and timing (on/off) of a motor and I need to be able to stop the motor when any key is pressed as quickly as possible for safetly reasons whatever control currently has the focus. regards, Ted
Ted Edwards
This may not help but if you mean passing arguments by reference then I found I had to put the keyword "ref" in front of the argument - both in the definition and the use. i.e. MyFunc(ref int argument) & MyRef(ref argument). I hope this is of some help.
Ted Edwards
It is mostly the search I have trouble with. The problem is really me in that I should learn C# and Visual Studio properly. I never seem to have time, always pressure to make something work "quick and dirty". Ted
Ted Edwards
Thanks for pointing me in the right direction - I will investigate. Is it only me or does anyone else find the Visual Studio help system difficult to get meaningfull answers from? Ted Edwards
Ted Edwards
How do I tell Visual Studio C# 2005 about a DLL supplied with my USB hardware (motor control - MotorBee). I need to be able to call the functions in the DLL. Is it so trivial that its obvious? (not to me!) sysrev