Reputation: 87087
i have a pretty simple rectangluar WinForm that uses timers to check the end content of a number of files. Works fine.
Now, the list of files to check is dynamic. Could be 3. could be 30. It dependant upon some value in the database, which i check regularly. That's also fine.
What I wish to do is visual this, on my winform. For each file, have a red circle. when the file is being 'checked', show that circle as green. once finished, red again.
Cheers!
Upvotes: 2
Views: 1788
Reputation: 6472
Yes just create the control (new) and add it to the form. see here link for and example or two.
The rest of you question is pretty open - there are many ways to do what you want.
Upvotes: 1
Reputation: 31071
Controls
collection of the parent container (e.g. the form). You could either (a) manually work out the coordinates of each new control based on the last one added, or (b) put them inside a FlowLayoutPanel
.Graphics
object.Upvotes: 9
Reputation: 25278
In cases like this I create a "model" control, that has all the properties of the controls you want to add. For example the red dot, with its size and other properties already set. Then set that either out of view or ake it invisible. Then when you need to create your controls dynamically, clone that model control, and just set its location, (and make it visible if need be), then add it to the forms control collection
Upvotes: 1
Reputation: 104196
Implement a custom control and do something like this:
SuspendLayout();
MyCircleControl circle = new MyCircleControl ();
// Set properties
circle.Location = new Point(0,0);
circle.Color = Color.Red;
Controls.Add(circle );
ResumeLayout(false);
This is actually what the designer is doing. Have a look at the Designer.cs file.
Upvotes: 1
Reputation: 916
Since you say that the list of files is held in a database anyway, I would add a datagridview to the form in design mode. This dgv would use the table with the files as its datasource, thus creating rows dynamically. I would also either add a column to the dgv or the table itself to hold a boolean/bit for whether the file is being read. This would then show as a column in the dgv. From there you would just get the dgv row for the file you are reading when it is being read, and change the image for the boolean column to be a green or red circle that you create in your favorite image editor.
Upvotes: 0