473,385 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Form not painted. Or is it?

I have been working on a card game (called Uno) for past few days.
Language used : C# 2.0

When I start a new game, a dialog window pops up asking the name of
the player. I enter the name, and then cards are distributed to the
computer and player. Then I set a flag true, to signal that the client
area is dirty - please paint it. There is a timer which check for this
flag and if it finds it true, it invalidates the form.

Concept :-

.... timer_tick handler code...
{
if (true == paintFlag)
{
...form.Invalidate() ;
paintFlag = false;
}
}

This should invoke the painting handler of my form.

Problem:
I see only the portion of the form painted where the first pop up
window was located (usually in the middle of the window), after the
pop up window is gone.

Why isn't the whole form painted? Or does it? If yes, why are the
cards not visible?

If you want, have a look at the code here -
http://cnayan.googlepages.com/2007-0...apshot-Uno.zip
I know the code in unoptimized right now. :)

Thanks in advance! :)
Nayan

Mar 18 '07 #1
6 1619
"Nayan" <cn****@gmail.comwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
>I have been working on a card game (called Uno) for past few days.
Language used : C# 2.0

When I start a new game, a dialog window pops up asking the name of
the player. I enter the name, and then cards are distributed to the
computer and player. Then I set a flag true, to signal that the client
area is dirty - please paint it. There is a timer which check for this
flag and if it finds it true, it invalidates the form.
Your whole approach is wrong here. Just paint everything in OnPaint and call
form.invalidate when things change. Get rid of the timer.

Michael
Mar 18 '07 #2
Please don't multipost.
Mar 19 '07 #3
Thanks Michael for the suggestion.

I know this is the usual approach. But instead of duplicating code
(form invalidation call) everywhere, I just set a flag which is easier
to do. Timer is ticking without any harm to the code. When it sees the
flag, it just invokes painting, apart from any other task to do.

I can change the code, but in my opinion, it won't solve the problem.
If the code is wrong please help me there. Later on, concept can be
revised/optimized.
First thing first, the program should work 100%.

Thanks a lot!
Nayan

On Mar 19, 12:41 am, "Michael C" <nos...@nospam.comwrote:
"Nayan" <cna...@gmail.comwrote in message

news:11**********************@n76g2000hsh.googlegr oups.com...

Your whole approach is wrong here. Just paint everything in OnPaint and call
form.invalidate when things change. Get rid of the timer.

Michael
Mar 19 '07 #4
Hi Nayan,

did you check, if the form.Invalidate-line is really reached?
did you mark the paintFlag variable as volatile?
maybe you have some problem with the memory-model.

Christof

"Nayan" <cn****@gmail.comschrieb im Newsbeitrag
news:11**********************@n76g2000hsh.googlegr oups.com...
>I have been working on a card game (called Uno) for past few days.
Language used : C# 2.0

When I start a new game, a dialog window pops up asking the name of
the player. I enter the name, and then cards are distributed to the
computer and player. Then I set a flag true, to signal that the client
area is dirty - please paint it. There is a timer which check for this
flag and if it finds it true, it invalidates the form.

Concept :-

... timer_tick handler code...
{
if (true == paintFlag)
{
...form.Invalidate() ;
paintFlag = false;
}
}

This should invoke the painting handler of my form.

Problem:
I see only the portion of the form painted where the first pop up
window was located (usually in the middle of the window), after the
pop up window is gone.

Why isn't the whole form painted? Or does it? If yes, why are the
cards not visible?

If you want, have a look at the code here -
http://cnayan.googlepages.com/2007-0...apshot-Uno.zip
I know the code in unoptimized right now. :)

Thanks in advance! :)
Nayan

Mar 19 '07 #5
Hi Christof,

I got the problem's solution :)

Actually everything is fine.. except the logic - I was calling
Invalidate() and then was setting the flag to false *somewhere* else
(in Paint method).

I corrected it and have continued the development. Thanks for
trying :)

Nayan

On Mar 19, 12:39 pm, "Christof Nordiek" <c...@nospam.dewrote:
Hi Nayan,

did you check, if the form.Invalidate-line is really reached?
did you mark the paintFlag variable as volatile?
maybe you have some problem with the memory-model.

Christof
Mar 19 '07 #6
"Nayan" <cn****@gmail.comwrote in message
news:11**********************@l75g2000hse.googlegr oups.com...
Thanks Michael for the suggestion.

I know this is the usual approach. But instead of duplicating code
(form invalidation call) everywhere, I just set a flag which is easier
to do.
A tiny bit easier, maybe.
Timer is ticking without any harm to the code. When it sees the
flag, it just invokes painting, apart from any other task to do.
The harm is that is can produce race conditions and potentially difficult to
find bugs.
Mar 19 '07 #7

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

Similar topics

8
by: Susan Bricker | last post by:
Hi. I am opening a form (frmUserSettings) just before (or so I thought) the Main Menu form (frmMainMenu) is opening but it's not getting the focus. It gets "painted" and then the Main Menu gets...
8
by: Prakash | last post by:
I have a msgbox in my form activate event with an OK button. However the msgbox shows up BEFORE the form is painted. I would like the msgbox to be visible after the form gets painted on...
1
by: Will | last post by:
Hi All, I'm trying to find the correct form event to use to make a call to a database AFTER my form has been completely painted. The call to the database takes a few seconds and when I tried...
6
by: John | last post by:
Hi Is there a way to open a form hidden/invisible while it is populating its controls, and then make it visible once it is done? I am using the following code but the form remains visible. ...
4
by: hzgt9b | last post by:
Using VB .NET 2003, I have a windows application that performs a series of file actions (copy, move, delete) but the actions are completing before the window is painted on the screen... how can I...
79
by: VK | last post by:
I wandering about the common proctice of some UA's producers to spoof the UA string to pretend to be another browser (most often IE). Shouldn't it be considered as a trademark violation of the...
0
by: Miro | last post by:
Something I have run into using VB Express 2005 with mdi forms. I have not been able to re-create this but I'll let out the information on how I came about fixing this. As it cost me about 4...
8
by: Mitch5713 | last post by:
I've got tthree forms at start up splashscreen- works fine however how do i set the time delay so it stays on the window longer,, shows longer?? Loginscreen- works fine, after the data processing...
15
by: Angelo | last post by:
Hi all, I'm using a FileSystemWatcher to monitor a directory. I want the FSW to pop up my already instantiated but invisible form. However, I'm running into some problems with this. 1) In...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
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...

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.