473,890 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to re-draw controls on a Form at a regular interval?

Hello everyone,
I am using C# on a Pocket PC 2003 project based on .Net Compact Framework of
Visual Studio 2005. I want to re-draw some controls of a Form (Window) at a
regular interval (for example, change the title of some Label or something
similar). The issues I met with are,

1. My application has several Forms/Windows. How to check whether the
specific Form/Window (which I want to re-draw) is active? If the Form/Window
is not active, I think I should not re-draw the Form/Window. Am I correct?
Or, whether or not the Form/Window is active, I should always re-draw the
Form/Window?

2. Any code samples specific for C# of .Net Compact Framework?
thanks in advance,
George
Nov 26 '06 #1
8 2781
"George" <Ge****@discuss ions.microsoft. comwrote in message
news:85******** *************** ***********@mic rosoft.com...
[...]
1. My application has several Forms/Windows. How to check whether the
specific Form/Window (which I want to re-draw) is active?
Define "active".
If the Form/Window
is not active, I think I should not re-draw the Form/Window. Am I correct?
That depends on your definition of "active".
Or, whether or not the Form/Window is active, I should always re-draw the
Form/Window?
Probably. But since we don't know exactly what you mean by "active", it's
hard to say.
2. Any code samples specific for C# of .Net Compact Framework?
Assuming you use regular .NET components that are available in the Compact
Framework, you should not need examples specific to the Compact Framework.

As for the specific procedure, you might look into the Forms.Timer class.
This is probably the closest to what you'd want for causing a form to be
redrawn at a regular interval (though, IMHO you probably wind up just
changing the data for some control on the form at that regular interval and
let the regular redraw mechanism take care of the actual screen refresh).

Pete
Nov 26 '06 #2
When doing .Net Compact Framework I would say try it with more devices if
you have. You will realize some behavour change with different devices I
bet.

chanmm

"George" <Ge****@discuss ions.microsoft. comwrote in message
news:85******** *************** ***********@mic rosoft.com...
Hello everyone,
I am using C# on a Pocket PC 2003 project based on .Net Compact Framework
of
Visual Studio 2005. I want to re-draw some controls of a Form (Window) at
a
regular interval (for example, change the title of some Label or something
similar). The issues I met with are,

1. My application has several Forms/Windows. How to check whether the
specific Form/Window (which I want to re-draw) is active? If the
Form/Window
is not active, I think I should not re-draw the Form/Window. Am I correct?
Or, whether or not the Form/Window is active, I should always re-draw the
Form/Window?

2. Any code samples specific for C# of .Net Compact Framework?
thanks in advance,
George
Nov 27 '06 #3
Thanks for your advice, Chan! Do you have any samples which meet with my
question?
regards,
George

"Chan Ming Man" wrote:
When doing .Net Compact Framework I would say try it with more devices if
you have. You will realize some behavour change with different devices I
bet.

chanmm

"George" <Ge****@discuss ions.microsoft. comwrote in message
news:85******** *************** ***********@mic rosoft.com...
Hello everyone,
I am using C# on a Pocket PC 2003 project based on .Net Compact Framework
of
Visual Studio 2005. I want to re-draw some controls of a Form (Window) at
a
regular interval (for example, change the title of some Label or something
similar). The issues I met with are,

1. My application has several Forms/Windows. How to check whether the
specific Form/Window (which I want to re-draw) is active? If the
Form/Window
is not active, I think I should not re-draw the Form/Window. Am I correct?
Or, whether or not the Form/Window is active, I should always re-draw the
Form/Window?

2. Any code samples specific for C# of .Net Compact Framework?
thanks in advance,
George
Dec 5 '06 #4
Thanks Peter!
(though, IMHO you probably wind up just
changing the data for some control on the form at that regular interval and
let the regular redraw mechanism take care of the actual screen refresh).
Yes. This is just what I want. Do you have any samples to do this or close
to this question?
regards,
George
"Peter Duniho" wrote:
"George" <Ge****@discuss ions.microsoft. comwrote in message
news:85******** *************** ***********@mic rosoft.com...
[...]
1. My application has several Forms/Windows. How to check whether the
specific Form/Window (which I want to re-draw) is active?

Define "active".
If the Form/Window
is not active, I think I should not re-draw the Form/Window. Am I correct?

That depends on your definition of "active".
Or, whether or not the Form/Window is active, I should always re-draw the
Form/Window?

Probably. But since we don't know exactly what you mean by "active", it's
hard to say.
2. Any code samples specific for C# of .Net Compact Framework?

Assuming you use regular .NET components that are available in the Compact
Framework, you should not need examples specific to the Compact Framework.

As for the specific procedure, you might look into the Forms.Timer class.
This is probably the closest to what you'd want for causing a form to be
redrawn at a regular interval (though, IMHO you probably wind up just
changing the data for some control on the form at that regular interval and
let the regular redraw mechanism take care of the actual screen refresh).

Pete
Dec 5 '06 #5
"George" <Ge****@discuss ions.microsoft. comwrote in message
news:37******** *************** ***********@mic rosoft.com...
>(though, IMHO you probably wind up just
changing the data for some control on the form at that regular interval
and
let the regular redraw mechanism take care of the actual screen refresh).

Yes. This is just what I want. Do you have any samples to do this or close
to this question?
Well, how are you displaying the data in the first place? I'm assuming you
have a form. Is the data displayed within the form by some control? Or do
you have some custom paint event handling code to draw the data directly
into the form?

For example, one easy way to display some text data in a form is to use some
kind of text control. Like a label or text box. Simply changing the Text
property of one of those controls is enough to cause the control itself to
be invalidated and force a redraw. You don't explicitly redraw...you just
change the data you want to change, and the related control and form handle
the rest for you.

Knowing more details about how you're actually displaying the data will help
in getting a good answer as to how to change that data in a manner
compatible with the usual Form redraw mechanisms.

Pete
Dec 5 '06 #6
"George" <Ge****@discuss ions.microsoft. comwrote in message
news:2B******** *************** ***********@mic rosoft.com...
The issue of your method is the text of some label is displayed only
passively -- but I need an auto-refresh approach. For example, if I open a
Form for a long time, and in this Form I want to display the updated
number
of new messages (like Outlook) -- the number of messages will increase
since
there are coming new messages, and this form needs to be refreshed at a
regular interval, other than passively upgrade the text.

Any comments or suggestions?
Every time you change the counter, you simply update the Text property of
the label. It will redraw automatically to reflect the new value.

If you would rather poll the counter on a regular basis (not too often, I
hope), then you can use a timer as I suggested earlier. In the timer, you
simply update the Text property of the label, and it will redraw
automatically to reflect the new value.

Pete
Dec 6 '06 #7

Peter Duniho wrote:
Every time you change the counter, you simply update the Text property of
the label. It will redraw automatically to reflect the new value.
Yes it will, IF whatever work you are doing that causes the counter to
change is being done on a background thread.

If you are doing all of the work on the UI thread and want to update
the Form to show progress then you are out of luck, unless you use
Application.DoE vents(), which is icky.

The trick is to do your work on a background thread. Have the
background job raise an event whenever the counter changes. In your
Form, subscribe to the event, and then use Invoke to call a method
under control of the UI thread again to update the counter.

You can read about multi-threading and Windows Forms on Jon Skeet's
site, here:

http://www.yoda.arachsys.com/csharp/...winforms.shtml

Dec 6 '06 #8
"Bruce Wood" <br*******@cana da.comwrote in message
news:11******** *************@j 72g2000cwa.goog legroups.com...
Peter Duniho wrote:
>Every time you change the counter, you simply update the Text property of
the label. It will redraw automatically to reflect the new value.

Yes it will, IF whatever work you are doing that causes the counter to
change is being done on a background thread.
Not necessarily. After all, one approach would be to process messages
intermittently (in response to network i/o events, a timer, etc.). A GUI
message pump will work just fine in that case.

But even if one ignores those options, one hopes that the OP has done
*something* to allow GUI events to occur while his processing is going on.
Otherwise, the OP has no usable UI at all. Why bother with forms at all, if
there is to be no user interaction?
If you are doing all of the work on the UI thread and want to update
the Form to show progress then you are out of luck, unless you use
Application.DoE vents(), which is icky.
No more icky than, for example, showing a modal dialog (which effectively
does the same thing).
The trick is to do your work on a background thread.
That is one trick, yes. There are other means to accomplish the end.
Have the
background job raise an event whenever the counter changes.
Or simply use Invoke to change the label's Text property, rather than
bothering with creating an event and adding a delegate to it.

Pete
Dec 6 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4326
by: Nel | last post by:
I have a question related to the "security" issues posed by Globals ON. It is good programming technique IMO to initialise variables, even if it's just $foo = 0; $bar = ""; Surely it would be better to promote better programming than rely on PHP to compensate for lazy programming?
4
6437
by: Craig Bailey | last post by:
Anyone recommend a good script editor for Mac OS X? Just finished a 4-day PHP class in front of a Windows machine, and liked the editor we used. Don't recall the name, but it gave line numbers as well as some color coding, etc. Having trouble finding the same in an editor that'll run on OS X. -- Floydian Slip(tm) - "Broadcasting from the dark side of the moon"
1
4105
by: Chris | last post by:
Sorry to post so much code all at once but I'm banging my head against the wall trying to get this to work! Does anyone have any idea where I'm going wrong? Thanks in advance and sorry again for adding so much code... <TABLE border="1" bordercolor="#000000" cellspacing="0"> <TR>
4
18552
by: Alan Walkington | last post by:
Folks: How can I get an /exec'ed/ process to run in the background on an XP box? I have a monitor-like process which I am starting as 'exec("something.exe");' and, of course the exec function blocks until something.exe terminates. Just what I /don't/ want. (Wouldn't an & be nice here! Sigh) I need something.exe to disconnect and run in the background while I
1
3708
by: John Ryan | last post by:
What PHP code would I use to check if submitted sites to my directory actually exist?? I want to use something that can return the server code to me, ie HTTP 300 OK, or whatever. Can I do this with sockets??
10
4236
by: James | last post by:
What is the best method for creating a Web Page that uses both PHP and HTML ? <HTML> BLA BLA BLA BLA BLA
8
3666
by: Lothar Scholz | last post by:
Because PHP5 does not include the mysql extension any more is there a chance that we will see more Providers offering webspace with Firebird or Postgres Databases ? What is your opinion ? I must say that i like it to see mysql replaced by a real database (stored procedures etc.)
1
3642
by: joost | last post by:
Hello, I'm kind of new to mySQL but more used to Sybase/PHP What is illegal about this query or can i not use combined query's in mySQL? DELETE FROM manufacturers WHERE manufacturers_id NOT IN ( SELECT manufacturers_id FROM products )
3
3496
by: presspley | last post by:
I have bought the book on advanced dreamweaver and PHP recently. I have installed MySQL and PHP server but am getting an error on the $GET statement show below. It says there is a problem with the variable $GET but $GET is not a variable, I thought it came from the page that calls the PHP file? if(($_GET)==""){ this gets an error
1
13669
by: Brian | last post by:
I have an array like this: $events = array( array( '2003-07-01', 'Event Title 1', '1' //ID Number (not unique) ), array( '2003-07-02',
0
9815
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11215
Oralloy
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...
0
10802
jinu1996
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...
1
10908
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10451
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9618
agi2029
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...
1
8008
isladogs
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...
0
7160
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5835
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.