SetStyle on component? (prevent flickering)

D

Dirk Schippers

Hi,

I am using winforms in C++ to create a gui for my directx application.
The form is divided into 4 panels with three splitcontainers, (one for
vertical and two for horizontal).

Now, in the directx part, I render to the four panels by using their
handles, but I experience a lot of flickering when resizing the form or
the splitters.

I read that you can prevent flickering by setting the style to one or
more of ControlStyles::AllPaintingInWmPaint,
ControlStyles::DoubleBuffer, ControlStyles::UserPaint. But I can't set
it to the panels themselves because I then get a compiler error:
*error C3767: 'System::Windows::Forms::Control::SetStyle': candidate
function(s) not accessible*

I read somewhere that this is normal, that you should set the style to
the form (but that doesn't help) or that you should create a custom
Panel class inheriting from the normal panel class and set its style in
its constructor.

But there the problem comes up, how can I create a custom panel class to
be used inside a splitcontainer?

Or is there a totally different way to prevent the flickering I'm
experiencing?

Thanks,
Dirk.
 
H

Herfried K. Wagner [MVP]

Dirk Schippers said:
I am using winforms in C++ to create a gui for my directx application.
The form is divided into 4 panels with three splitcontainers, (one for
vertical and two for horizontal).

Now, in the directx part, I render to the four panels by using their
handles, but I experience a lot of flickering when resizing the form or
the splitters.

I read that you can prevent flickering by setting the style to one or more
of ControlStyles::AllPaintingInWmPaint, ControlStyles::DoubleBuffer,
ControlStyles::UserPaint. But I can't set it to the panels themselves
because I then get a compiler error:
*error C3767: 'System::Windows::Forms::Control::SetStyle': candidate
function(s) not accessible*

I read somewhere that this is normal, that you should set the style to the
form (but that doesn't help) or that you should create a custom Panel
class inheriting from the normal panel class and set its style in its
constructor.

Just create a class that derives from 'System.Windows.Forms.Panel' and add
your 'SetStyle' call there. I don't know if this is possible in C++/CLI
too, but at least in VB the derived control is available in the toolbox in a
separate section.
 
D

Dirk Schippers

Herfried K. Wagner [MVP] schreef:
Just create a class that derives from 'System.Windows.Forms.Panel' and
add your 'SetStyle' call there. I don't know if this is possible in
C++/CLI too, but at least in VB the derived control is available in the
toolbox in a separate section.

Yes, I know but that doesn't work when you use a splitcontainer as the
splitcontainer implements its own panels.

But ok, it can be solved by using the splitter with custom panels
instead of using the splitcontainer. It's a little bit more work then.

Thanks for your answer. If someone knows how to do it with
splitcontainers, please tell me!

BTW. I really think it is stupid that you can't call SetStyle without
creating a custom class. Can anyone tell me why this is?
 
J

Jeff Johnson

Yes, I know but that doesn't work when you use a splitcontainer as the
splitcontainer implements its own panels.

But ok, it can be solved by using the splitter with custom panels instead
of using the splitcontainer. It's a little bit more work then.

Thanks for your answer. If someone knows how to do it with
splitcontainers, please tell me!

BTW. I really think it is stupid that you can't call SetStyle without
creating a custom class. Can anyone tell me why this is?

Mainly because the underlying Windows API functions that are being called
can only be done so during window initialization, and the only way you have
of tapping into that initialization is by inheriting from a control and
putting code in the constructor.
 
D

Dirk Schippers

BTW. I really think it is stupid that you can't call SetStyle without
Mainly because the underlying Windows API functions that are being called
can only be done so during window initialization, and the only way you have
of tapping into that initialization is by inheriting from a control and
putting code in the constructor.

Ok, that's logical of course, if the component is initialized that way
and can't be changed later on, but I remember that that was different in
the old non-dotnet days, that you could do a SetWindowStyle(...) to
change things on your components.

But ok, it's acceptable, and I finally got it to working fine.

Thanks.
 
J

Jeff Johnson

Ok, that's logical of course, if the component is initialized that way and
can't be changed later on, but I remember that that was different in the
old non-dotnet days, that you could do a SetWindowStyle(...) to change
things on your components.

Yeah, but some styles can't be changed on the fly. For example, I don't
believe you can use this trick to change a single-line text box into a
multi-line one. You have to destroy and re-create the window. It may be the
same with these graphical style bits as well.

And even if it is possible to do it via the API, sometimes the answer to
these "Why can't I do this in .NET" questions is simply "Because MS forgot
to put it in there/didn't think it was important enough to put in there."
 

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

Top