473,657 Members | 2,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Invalid ate() ;
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 1630
"Nayan" <cn****@gmail.c omwrote in message
news:11******** **************@ n76g2000hsh.goo glegroups.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.c omwrote in message

news:11******** **************@ n76g2000hsh.goo glegroups.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.c omschrieb im Newsbeitrag
news:11******** **************@ n76g2000hsh.goo glegroups.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.Invalid ate() ;
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.de wrote:
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.c omwrote in message
news:11******** **************@ l75g2000hse.goo glegroups.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
11327
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 "painted" right on top of the frmUserSettings. Since the Main Menu form is smaller (in width and height) I can click on frmUserSettings and get it to the front (focus). But is there a way to do this programmatically? Can you help me? Here is...
8
2499
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 screen. Is there any way I can do that from the Activate event ? I know that if I place my code in the curent event it will work, but
1
1270
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 using the LOAD event for the form, the form was half-painted (if that makes sense) while the db call was being performed. I'd like the user to be able to look at a fully painted form (and hourglass cursor) while the call is being made.
6
1389
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. cform = New frmClients cform.Visible = False ' this does not seem to make form hidden (not visible) cform.TopLevel = False
4
2100
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 force the form to be painted on the screen first, then the actions start? Or should I pause the app for a few seconds while the form paints. Any suggestion woudl be appreciated!
79
3751
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 relevant name owner? If I make a whisky and call it "Jack Daniels", I most probably will have some serious legal problems. "Mozilla" partially appeared because NCSA stopped them from using "Mosaic" in the UA string. Is it some different...
0
1231
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 hours last night so it might be a good read for anyone who uses mdi's. 1. I have Parent form that is an MDI conatainer. On the top of the form I have a panel docked, and on the left hand side of the form I have a panel docked with a splitter....
8
7551
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 of username etc is done I then need to load, call whatever the syntax is the mainForm at the end of the loginscreen..????? how is that done so it starts at the mainForm_Load procedure??? As it stands now the mainform loads but just for a split...
15
4760
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 the FSW.Changed FileSystemEventhandler, I called the Show method 'frmMain.Show( )' on my form, the form appears but not completely painted and it appears to be hanging with the hourglass.
0
8385
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, 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...
0
8303
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
8723
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...
0
8602
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
7316
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...
0
5632
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
4150
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...
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
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...

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.