Help -- Problem with redrawing UserControl

  • Thread starter Thread starter Dino Buljubasic
  • Start date Start date
D

Dino Buljubasic

Hi,

I am using C# 2.0 (VS2005) to build my user control that contains a
number of dynamically loaded ListViews. ListViewItems have their
ForeColor properties set to either black or blue to distinguish
between ListViewItems.

As long as no other application window (i.e. word or calculator, or
....) goes over my running form, ForeColor properties or each
ListViewItem stays black or blue as intended.

However, if another application window moves over my running form and
the ListViewItems, or if my form is maximized, the ListViewItems that
were covered by other window or invisible change their ForeColor to
black (ForeColor changes to black).

I use protected overloaded OnSizeChanged event to handle resizing my
user control as:


protected override void OnSizeChanged(EventArg e)
{
base.OnSizeChanged(e);

reloadUserControl();
}

This event calls first base.OnSizeChanged(e) event, then handles
redrawing and reloading of my user control. I have not identified any
other problems except this one.

Any Help Will Be Appreciated,
_dino_
 
Dino,

What exactly does the reloadUserControl() do? If you have a bunch of
controls sitting on your user control and they have been loaded with data,
why would they need to be reloaded when the size of the control is changed?
I would imagine the ListViews have to loaded at some point, but OnSizeChange
seems a little odd to me. Furthermore, unless you have overridden the
OnPaint methods of the ListView controls themselves, their should be no
reason for the ForeColor to change to something other than what you setup at
design time or changed on the fly at runtime. Are these custom ListView
controls sitting on your user control?

Dave
 
Hi Dave,

The dynamically loaded ListView controls are just regular ListView
controls and I have not overloaded any of their methods. My user
control (it is a custom built panel that behaves properly in any other
situation so far) act as a container to these ListVew controls.

reloadUserControl() reloads my custom panel with ListViews and
repopulate the ListVeiws each time my form (and therefore my panel)
resizes to accomodate more or less ListView controls. That is why I
call realoadUserControls() each time I resize. That seams to be
working well.

The problem is when I drag another window over my form. When I do
that, my ListViews dissaper shortly, then shows up again as I drag the
window over my form. However, when they show up again, the Font and
ForeColor of ListViewItems have changed.

Similarily, when I maximaze my form, the ListViews that were visible
while the form was in its original size have Font and ForeColor as
desired. However, the ListViews that were not loaded before
Form.Maximize do not.

The custom panel I have build simply display a number of ListViews one
above another. Each ListView has only 2 ListViewItems (in detail
view). As the hight of my user control grows, it is reloaded to
accomodate more ListViews and vice versa.

+--------------------------------------------------------+
| Panel holding ListVeiws |
| +--------------------------------------------------+ |
| | - - ListView1 with 2 ListVewItems- - - - - - - | |
| +--------------------------------------------------+ |
| +--------------------------------------------------+ |
| | - - ListView2 with 2 ListVewItems- - - - - - | |
| +--------------------------------------------------+ |
| etc ... |

Please ask if this is not clear. I think that resizing is not the
problem since it works just fine.

Thank you,
_dino_
 
.... another interesting thing ... if I drag a window ower my form
slowly, Fonts and ForeColor redraw correctly, if I do this fast, they
dont ???!!!???
 
Dino,

Sorry, I tried to adding new listviews with varying colors to a user control
on the fly at runtime, but I'm having no luck reproducing the problem that
your seeing. If I had to guess where your issue is, I would probably point
to the reloadUserControl() routine. The only other suggestion that I have
is to not use a "user control" as your container. Just create your ListView
controls in a panel that is sitting on the form itself since your creating
the ListView on the fly anyway.

Dave
 
Hi Dave,

I am using a custom built panel on my user control. That panel gets
dynamically loaded with ListViews. Somehow, the controls take
ForeColor and Font properties of their container (my custom panel)
when a window is dragged over my form (and the user control).

I am sure the problem is in my OnPaint of my custom panel. How is it
possible to make the container repaint all its controls when another
window is dragged over them? What I am missing in my OnPaint? How
does regular Panel handles this?

Thank you,
_dino_
 
For those interested, I have found out that this is rather an IDE
issue than coding issue. When I run my application from IDE, this
repainting problem occurs, when I run it from compiled .exe, the
problem is gone.

_dino_
 
Dino,

I'm reading through your email and wondering why you have overridden the
OnPaint method of your user control. Since the user control is covered by a
panel, which you fill with ListViews, the OnPaint method is basically doing
what? It's the same as covering a form with a panel and overriding the
form's OnPaint method...anything you "paint" will not be shown since the
panel is covering the form. Furthermore, you shouldn't have to "refresh"
the ListView controls. Once their added to the panel, they should act the
same way they would if you had added it to a form. So, what exactly do you
have in your OnPaint method of your custom USER control?

If none of this helps, try moving the problem outside of your current
application. For example, create a brand new windows application, add a
panel to the form, and copy all your logic for adding ListViews to the panel
to the new windows application. This will eliminate the use of a custom
control and may provide some insight into what's going on with your original
application.


Hope I'm helping and not making your life worse....

Later,
Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top