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.T imer 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 2896
If i got you right, Why can't you access that control using FormName.TimerN ame 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!
Frinavale 9,735
Recognized Expert Moderator Expert
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
Plater 7,872
Recognized Expert Expert
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.
Plater 7,872
Recognized Expert Expert
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
Plater 7,872
Recognized Expert Expert
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 issue is simply getting
timers to work. I have a DatabaseManager.DataManagerFacade which contains a
timer. Every 6 seconds it updates stock data using an online webservice. I
wrote have 2 possible startup projects to make the service work. One...
|
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 two forms (frmSplash and
frmMain) and a code Module setup as my startup object.
Here is the code that I have, when I try to run this part of the splash
screen form shows and then program terminates. What am I doing wrong?
Thanks,
|
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 regularly; like every 1.5 secs. or so. I only
ran into one issue - the MyTimer_Elapsed event handler was not updating the
screen correctly all the time, often leaving large chunks of the screen
un-painted for several seconds.
On a whim I decided to...
|
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 = True
NewTimer.Start()
My problem then happens in the TimeUp routine
| |
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
system.windows.forms.timers.
Now for the problem, with both Apps the timers will stop for no reason. I
mean the logic in the timer events is simply timer.enable = false,
counter+=1, timer.enable=true then end sub. The only thing that i have
noticed is that...
|
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 the default of
True. The Elapsed event handler updates the dialog box with how long
before it will close, acting as a timer itself. The dialog has a time
to close property which is checked every time the Elapsed event fires.
The problem I have...
|
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. Windows Form - I use this mostly to create my windows forms
2. Dialog - I use this for windows that need user intervention
3. Explorer Form - maybe I will use this if I plan to make something like windows explorer
4. MDI Parent Form - I also use this...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |