In my current application, I have to set cettain defaults to controls that are displayed or are used.
so i have a class to which i send the form as a control, and iterate through each of its controls and child controls
However, I have to also edit the Interval property of any timers present in the form.
Timers come under the Windows.Forms.Timer namespace and i am currently iterating through all the Controls in the form.
How would I go about finding Timers in a form? - foreach (Control c in control.Controls)
-
{
-
this.applyControlValues(c);
-
if (c.HasChildren == true)
-
this.applyKeyStrokes(c);
-
}
within applyKeyStrokes i check if the control c is of type text edit, or dropDown list, or gridview, etc
Thankyou
9 2853
If i got you right, Why can't you access that control using FormName.TimerName to change its properties ?
Every form has to have a certain look and feel property.
Yes its funny that i change this on runtime (and do not creqate a static compiled method, but all becasue the client require to change the look and feel as they want)
So if i have 5 forms
and i pass the forms to a class which scans thruogh all the controls contained inside it using Fom.Controls
So whenever i create a new form, to apply the look and feel, all i do is pass the form object and the values and properties are set accordingly.
So if i have 5 forms, and all 5 forms have timers (could be off different names, and some forms may have more than 1 timer) then in this case i would like to iterate through all the timers inside the form !!!
Hope this is not a bad way to implement it.
Wouldnt mind other opinions!
Every form has to have a certain look and feel property.
Yes its funny that i change this on runtime (and do not creqate a static compiled method, but all becasue the client require to change the look and feel as they want)
So if i have 5 forms
and i pass the forms to a class which scans thruogh all the controls contained inside it using Fom.Controls
So whenever i create a new form, to apply the look and feel, all i do is pass the form object and the values and properties are set accordingly.
So if i have 5 forms, and all 5 forms have timers (could be off different names, and some forms may have more than 1 timer) then in this case i would like to iterate through all the timers inside the form !!!
Hope this is not a bad way to implement it.
Wouldnt mind other opinions!
I think you should consider using Properties to pass the controls you are wanting to deal with. This will save you the time and resource of looping through and looking for them.
-Frinny
For every Control C that you get, if they are really a derrived class, you can discover what it is. Just the same way as if you were checking if they were a TextBox or anything?
Consider for example: -
//assume c is the current control to examine
-
if (c.GetType()==typeof(System.Windows.Forms.Timer)
-
{//the control is a timer, cast it as a Timer and set it's properties
-
}
-
For every Control C that you get, if they are really a derrived class, you can discover what it is. Just the same way as if you were checking if they were a TextBox or anything?
Consider for example: -
//assume c is the current control to examine
-
if (c.GetType()==typeof(System.Windows.Forms.Timer)
-
{//the control is a timer, cast it as a Timer and set it's properties
-
}
-
HI plater
Actaully I did try that code...
It never enters into that condition.
I even tried
Timer t = (Timer)c;
but this gives a compile time error that I cannot directly cast a control to a Timer.
For the moment, I am implementing the timer properties from each page, and any changes means that I have to repeat the process (hopefully without missing any forms with timers in it)
The timers are controlling a progress bar to refresh the data on the screen.
Ah ha!
It's because Timer doesn't inhereit from Control.
When you had a Timer to a Form, it doesn't get put in it's controls.
They take in a reference to the container and can be found with this: -
foreach (IComponent ic in this.components.Components)
-
{
-
if (ic.GetType() == typeof(System.Windows.Forms.Timer))
-
{//the control is a timer, cast it as a Timer and set it's properties
-
}
-
}
-
Ah ha!
It's because Timer doesn't inhereit from Control.
When you had a Timer to a Form, it doesn't get put in it's controls.
They take in a reference to the container and can be found with this: -
foreach (IComponent ic in this.components.Components)
-
{
-
if (ic.GetType() == typeof(System.Windows.Forms.Timer))
-
{//the control is a timer, cast it as a Timer and set it's properties
-
}
-
}
-
Yep that worked,
I realised it didnt inherit from a control.
However, that code which you provided, can only be placed in the form where the controls reside.
What I do is pass the form class to another class, which iterates through all controls and sets their default values. However when I send the form to this class, I cannot access the components object, maybe because it is protected.
Would I have to change any properties of the form?
Thanks a lot
See I found that funny to. Forms have a public property called "Container" that also has an IComponent Collection, but it always claims to be null.
Can you pass the form and a reference to it's protected container to your function? (Not the greatest, but it might work?
See I found that funny to. Forms have a public property called "Container" that also has an IComponent Collection, but it always claims to be null.
Can you pass the form and a reference to it's protected container to your function? (Not the greatest, but it might work?
Yes the Form.Container always sits at null.
For the moment i have a zillion forms, and only a few with timers in it.
For the moment I will look at setting the timer property within every But will create an overloaded method with passing the forms protected container !
Cheers, thanks a lot
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Nathan Kovac |
last post by:
I have a feeling I am missing something simple, but I just can't find it.
Perhaps someone can give me a lead on where to look. I will describe the
issue then post my code to the web service. My...
|
by: WhiteSocksGuy |
last post by:
Help! I am new to Visual Basic .Net (version 2002) and I am trying to get a
System.Timers.Timer to work for me to display a splash screen for about two
seconds and then load the main form. I have...
|
by: Michael C# |
last post by:
Hi all,
I set up a System.Timers.Time in my app. The code basically just updates
the screen, but since the processing performed is so CPU-intensive, I wanted
to make sure it gets updated...
|
by: N! Xau |
last post by:
hi
I need a way to threat a certain number of timers in a homogeneous way.
Let's say I have this code:
select X
case 1
timer1.enabled = true
case 2
|
by: Jerry Spence1 |
last post by:
I am trying to create timers on demand by doing the following:
Dim NewTimer As New System.Timers.Timer
NewTimer.Interval = 10000
AddHandler NewTimer.Elapsed, AddressOf Timeup
NewTimer.Enabled =...
|
by: Maarten |
last post by:
Hi
In my aplication it seems that my timer slows down everything,
is there a better and/or diferent way than using a timer
Maarten
|
by: Dave |
last post by:
MS Virtual Server 2005 (not R2) with .Net 2003
I created a Console App and A windows form both with Timers in it. For the
console i used system.timers and the windows form i used...
|
by: Liverpool fan |
last post by:
I have a windows application written using VB .NET that encompasses a
countdown timer modal dialog. The timer is a System.Timers.Timer with
an interval of 1 second. AutoReset is not set so accepts...
|
by: nev |
last post by:
I know when is best to use some templates but listed below are most that I don't know when is best to use or even know how to use:
I am creating a windows application with mysql backend.
1....
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |