HighTechTalks DotNet Forums  

Panel with double buffer

Dotnet Framework (Drawing) microsoft.public.dotnet.framework.drawing


Discuss Panel with double buffer in the Dotnet Framework (Drawing) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
active
 
Posts: n/a

Default Panel with double buffer - 06-08-2007 , 07:42 PM






A Panel object does not allow DoubleBuffered to be set.



Simply creating a new control as below allows one to set that property so it
isn't that it can't be done.

It's just a little harder.

So, why did they set the property (or any property) to Protected?

What's the rational?



Thanks





Class MyPanel

Inherits System.Windows.Forms.Panel

Public Sub New()

MyBase.New()

'The reason for this class:

'The following protected property needed to be set to reduce flicker

Me.DoubleBuffered = True

End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

MyBase.Dispose(disposing)

End Sub

End Class



Reply With Quote
  #2  
Old   
Bob Powell [MVP]
 
Posts: n/a

Default Re: Panel with double buffer - 06-08-2007 , 08:40 PM






I think this was an oversight.

Some would call it an unimplemented feature.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


" active" <activeNOSPAM (AT) a-znet (DOT) com> wrote

Quote:
A Panel object does not allow DoubleBuffered to be set.



Simply creating a new control as below allows one to set that property so
it isn't that it can't be done.

It's just a little harder.

So, why did they set the property (or any property) to Protected?

What's the rational?



Thanks





Class MyPanel

Inherits System.Windows.Forms.Panel

Public Sub New()

MyBase.New()

'The reason for this class:

'The following protected property needed to be set to reduce flicker

Me.DoubleBuffered = True

End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

MyBase.Dispose(disposing)

End Sub

End Class




Reply With Quote
  #3  
Old   
active
 
Posts: n/a

Default Re: Panel with double buffer - 06-08-2007 , 10:31 PM



I don't think I was clear.

The question is why set ANY property to Protected.

It's a little harder to change then Public - but only a little harder (as I
illustrated below)
If the class prohibits inheritance Protected has a real effect,
but otherwise Protected and Public are basically the same.






"Bob Powell [MVP]" <bob (AT) spamkillerbobpowell (DOT) net> wrote

Quote:
I think this was an oversight.

Some would call it an unimplemented feature.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


" active" <activeNOSPAM (AT) a-znet (DOT) com> wrote in message
news:uIpJhaiqHHA.4420 (AT) TK2MSFTNGP04 (DOT) phx.gbl...
A Panel object does not allow DoubleBuffered to be set.



Simply creating a new control as below allows one to set that property so
it isn't that it can't be done.

It's just a little harder.

So, why did they set the property (or any property) to Protected?

What's the rational?



Thanks





Class MyPanel

Inherits System.Windows.Forms.Panel

Public Sub New()

MyBase.New()

'The reason for this class:

'The following protected property needed to be set to reduce flicker

Me.DoubleBuffered = True

End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

MyBase.Dispose(disposing)

End Sub

End Class






Reply With Quote
  #4  
Old   
Bob Powell [MVP]
 
Posts: n/a

Default Re: Panel with double buffer - 06-11-2007 , 05:39 AM



Well, now you're getting into aspects of architecture, which I can yack on
about all day :-)

The protected access keyword enforces the rule that class wishing to change
or affect certain behaviours of an object must derive from the base class in
question.

This was obviously a desire of the original design team.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


" active" <activeNOSPAM (AT) a-znet (DOT) com> wrote

Quote:
I don't think I was clear.

The question is why set ANY property to Protected.

It's a little harder to change then Public - but only a little harder (as
I illustrated below)
If the class prohibits inheritance Protected has a real effect,
but otherwise Protected and Public are basically the same.






"Bob Powell [MVP]" <bob (AT) spamkillerbobpowell (DOT) net> wrote in message
news:3890EBA6-7134-4E02-8D0C-897EF955B9FE (AT) microsoft (DOT) com...
I think this was an oversight.

Some would call it an unimplemented feature.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


" active" <activeNOSPAM (AT) a-znet (DOT) com> wrote in message
news:uIpJhaiqHHA.4420 (AT) TK2MSFTNGP04 (DOT) phx.gbl...
A Panel object does not allow DoubleBuffered to be set.



Simply creating a new control as below allows one to set that property
so it isn't that it can't be done.

It's just a little harder.

So, why did they set the property (or any property) to Protected?

What's the rational?



Thanks





Class MyPanel

Inherits System.Windows.Forms.Panel

Public Sub New()

MyBase.New()

'The reason for this class:

'The following protected property needed to be set to reduce flicker

Me.DoubleBuffered = True

End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

MyBase.Dispose(disposing)

End Sub

End Class







Reply With Quote
  #5  
Old   
active
 
Posts: n/a

Default Re: Panel with double buffer - 06-11-2007 , 11:48 AM



Bob, I think that is the definition.
What I'm wondering is, why would you, for example, create a Protected
property.
You make it slightly more difficult for a user to change that property, but
you don't prevent it.
(As in my example I make a new class that changes it. I suppose I could make
a new class with a public property that sets the Protected one.)
There must (I hope) be a rational for doing that.
Have you ever created a Protected property? If so why?

Thanks


"Bob Powell [MVP]" <bob (AT) spamkillerbobpowell (DOT) net> wrote

Quote:
Well, now you're getting into aspects of architecture, which I can yack on
about all day :-)

The protected access keyword enforces the rule that class wishing to
change
or affect certain behaviours of an object must derive from the base class
in
question.

This was obviously a desire of the original design team.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


" active" <activeNOSPAM (AT) a-znet (DOT) com> wrote in message
news:%23Microsoftya8lqHHA.4836 (AT) TK2MSFTNGP05 (DOT) phx.gbl...
I don't think I was clear.

The question is why set ANY property to Protected.

It's a little harder to change then Public - but only a little harder (as
I illustrated below)
If the class prohibits inheritance Protected has a real effect,
but otherwise Protected and Public are basically the same.






"Bob Powell [MVP]" <bob (AT) spamkillerbobpowell (DOT) net> wrote in message
news:3890EBA6-7134-4E02-8D0C-897EF955B9FE (AT) microsoft (DOT) com...
I think this was an oversight.

Some would call it an unimplemented feature.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


" active" <activeNOSPAM (AT) a-znet (DOT) com> wrote in message
news:uIpJhaiqHHA.4420 (AT) TK2MSFTNGP04 (DOT) phx.gbl...
A Panel object does not allow DoubleBuffered to be set.



Simply creating a new control as below allows one to set that property
so it isn't that it can't be done.

It's just a little harder.

So, why did they set the property (or any property) to Protected?

What's the rational?



Thanks





Class MyPanel

Inherits System.Windows.Forms.Panel

Public Sub New()

MyBase.New()

'The reason for this class:

'The following protected property needed to be set to reduce flicker

Me.DoubleBuffered = True

End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

MyBase.Dispose(disposing)

End Sub

End Class









Reply With Quote
  #6  
Old   
Bob Powell [MVP]
 
Posts: n/a

Default Re: Panel with double buffer - 06-11-2007 , 02:42 PM



Hi, Ok, Yes, a specific example.

Properties are not direct access to a variable such as a public or even
protected field. They are methods that can perform some task. In fact,
setting or getting the contents of a property may not even have a backing
variable or field associated with it.

In a specific control I wanted to be able to perform some initialisation
when a field changed so, I added a protected property that accessed a
private field. In this way I could ensure that derived classes would
automatically call the complex initialization routine when setting the field
value instead of having to set the value and then call the initialization
method explicitly or indeed, forget to do so causing some disaster
condition.

Another reason for having a protected property was in the case of a bit of
code that used the new TypeDescriptionProvider system. I wanted this object
to provide only those public properties defined by a special attribute. The
protected property never showed up in the course of simple reflection, such
as by the property grid. However, it could be accessed via reflection and
it, once again, called a complex reinitialization routine when the object
property changed.

I can't give you code or a more specific example because the work was for a
paying customer. I hope however that it helps.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


" active" <activeNOSPAM (AT) a-znet (DOT) com> wrote

Quote:
Bob, I think that is the definition.
What I'm wondering is, why would you, for example, create a Protected
property.
You make it slightly more difficult for a user to change that property,
but you don't prevent it.
(As in my example I make a new class that changes it. I suppose I could
make a new class with a public property that sets the Protected one.)
There must (I hope) be a rational for doing that.
Have you ever created a Protected property? If so why?

Thanks


"Bob Powell [MVP]" <bob (AT) spamkillerbobpowell (DOT) net> wrote in message
news:%23KG0GyArHHA.3284 (AT) TK2MSFTNGP03 (DOT) phx.gbl...
Well, now you're getting into aspects of architecture, which I can yack
on
about all day :-)

The protected access keyword enforces the rule that class wishing to
change
or affect certain behaviours of an object must derive from the base class
in
question.

This was obviously a desire of the original design team.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


" active" <activeNOSPAM (AT) a-znet (DOT) com> wrote in message
news:%23Microsoftya8lqHHA.4836 (AT) TK2MSFTNGP05 (DOT) phx.gbl...
I don't think I was clear.

The question is why set ANY property to Protected.

It's a little harder to change then Public - but only a little harder
(as
I illustrated below)
If the class prohibits inheritance Protected has a real effect,
but otherwise Protected and Public are basically the same.






"Bob Powell [MVP]" <bob (AT) spamkillerbobpowell (DOT) net> wrote in message
news:3890EBA6-7134-4E02-8D0C-897EF955B9FE (AT) microsoft (DOT) com...
I think this was an oversight.

Some would call it an unimplemented feature.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


" active" <activeNOSPAM (AT) a-znet (DOT) com> wrote in message
news:uIpJhaiqHHA.4420 (AT) TK2MSFTNGP04 (DOT) phx.gbl...
A Panel object does not allow DoubleBuffered to be set.



Simply creating a new control as below allows one to set that property
so it isn't that it can't be done.

It's just a little harder.

So, why did they set the property (or any property) to Protected?

What's the rational?



Thanks





Class MyPanel

Inherits System.Windows.Forms.Panel

Public Sub New()

MyBase.New()

'The reason for this class:

'The following protected property needed to be set to reduce flicker

Me.DoubleBuffered = True

End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

MyBase.Dispose(disposing)

End Sub

End Class










Reply With Quote
  #7  
Old   
active
 
Posts: n/a

Default Re: Panel with double buffer - 06-13-2007 , 10:26 AM




Bob

When I asked if you ever used Protected that was a mistake on my part since
that's not the best way to get the answer I want. (But look how you had to
reach to find a situation.)

What I'm wondering about, and there is no reason to expect you to be able to
get into someone elses mind, is why MS makes some Properties Protected??

Like:
Textbox.DefaultMargin
Panel.DoubleBuffered
Panel.FontHeight...

As I said before, I can create a control the inherits a control with
Protected properties and add a public property that changes a base control's
Protected property.

Would I be doing something that I shouldn't?


Thanks



Reply With Quote
  #8  
Old   
Bob Powell [MVP]
 
Posts: n/a

Default Re: Panel with double buffer - 06-13-2007 , 03:50 PM



Of course you'd be doing something you shouldn't. You'd be exposing
properties that have a design usage with a specific protection to
something else entirely.

Whatever approach to take you need to question the motives of the
original object and see why those properties were protected.

Take the example of Panel.DoubleBuffered; If this property were public,
you could turn on double buffering. However, as soon as you make a
control with a complexity that requires this operation you automatically
need to turn off OnPaintBackground so that you don't cause flashing or
multiple redraws of the back-buffer. As soon as you do this you need to
override but then you just bring along the baggage of Panel. You might
as well accept the fact of doing the job properly, creating an object
derived directly from Control or ScrollableControl and stop trying to
persuade Panel to do stuff it wasn't designed for.


--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





active wrote:
Quote:
Bob

When I asked if you ever used Protected that was a mistake on my part since
that's not the best way to get the answer I want. (But look how you had to
reach to find a situation.)

What I'm wondering about, and there is no reason to expect you to be able to
get into someone elses mind, is why MS makes some Properties Protected??

Like:
Textbox.DefaultMargin
Panel.DoubleBuffered
Panel.FontHeight...

As I said before, I can create a control the inherits a control with
Protected properties and add a public property that changes a base control's
Protected property.

Would I be doing something that I shouldn't?


Thanks



Reply With Quote
  #9  
Old   
active
 
Posts: n/a

Default Re: Panel with double buffer - 06-13-2007 , 07:07 PM



I think I understand now.
The answer to my question is that those properties can be changed, but
changing them may require more knowledge and care then changing the public
properties.


thanks



"Bob Powell [MVP]" <bob (AT) _spamkiller_bobpowell (DOT) net> wrote

Quote:
Of course you'd be doing something you shouldn't. You'd be exposing
properties that have a design usage with a specific protection to
something else entirely.

Whatever approach to take you need to question the motives of the original
object and see why those properties were protected.

Take the example of Panel.DoubleBuffered; If this property were public,
you could turn on double buffering. However, as soon as you make a control
with a complexity that requires this operation you automatically need to
turn off OnPaintBackground so that you don't cause flashing or multiple
redraws of the back-buffer. As soon as you do this you need to override
but then you just bring along the baggage of Panel. You might as well
accept the fact of doing the job properly, creating an object derived
directly from Control or ScrollableControl and stop trying to persuade
Panel to do stuff it wasn't designed for.


--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





active wrote:
Bob

When I asked if you ever used Protected that was a mistake on my part
since that's not the best way to get the answer I want. (But look how you
had to reach to find a situation.)

What I'm wondering about, and there is no reason to expect you to be able
to get into someone elses mind, is why MS makes some Properties
Protected??

Like:
Textbox.DefaultMargin
Panel.DoubleBuffered
Panel.FontHeight...

As I said before, I can create a control the inherits a control with
Protected properties and add a public property that changes a base
control's Protected property.

Would I be doing something that I shouldn't?


Thanks



Reply With Quote
  #10  
Old   
active
 
Posts: n/a

Default Re: Panel with double buffer - 06-13-2007 , 07:36 PM



I probably should have mentioned that I needed a drawing surface and was
using a picturebox but thought I could use a simpler scrollable control so I
tried a Panel which seemed to work OK except for some flashing.

So I created a control inherited from Panel with only the one change of
DoubleBuffered = True and that appeared to fix the flashing without and
adverse side effects. Maybe I just don't what to look for or maybe I'll get
hit latter.


Thanks for all the help






" active" <activeNOSPAM (AT) a-znet (DOT) com> wrote

Quote:
I think I understand now.
The answer to my question is that those properties can be changed, but
changing them may require more knowledge and care then changing the public
properties.


thanks



"Bob Powell [MVP]" <bob (AT) _spamkiller_bobpowell (DOT) net> wrote in message
news:upNDgQfrHHA.4804 (AT) TK2MSFTNGP04 (DOT) phx.gbl...
Of course you'd be doing something you shouldn't. You'd be exposing
properties that have a design usage with a specific protection to
something else entirely.

Whatever approach to take you need to question the motives of the
original object and see why those properties were protected.

Take the example of Panel.DoubleBuffered; If this property were public,
you could turn on double buffering. However, as soon as you make a
control with a complexity that requires this operation you automatically
need to turn off OnPaintBackground so that you don't cause flashing or
multiple redraws of the back-buffer. As soon as you do this you need to
override but then you just bring along the baggage of Panel. You might as
well accept the fact of doing the job properly, creating an object
derived directly from Control or ScrollableControl and stop trying to
persuade Panel to do stuff it wasn't designed for.


--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





active wrote:
Bob

When I asked if you ever used Protected that was a mistake on my part
since that's not the best way to get the answer I want. (But look how
you had to reach to find a situation.)

What I'm wondering about, and there is no reason to expect you to be
able to get into someone elses mind, is why MS makes some Properties
Protected??

Like:
Textbox.DefaultMargin
Panel.DoubleBuffered
Panel.FontHeight...

As I said before, I can create a control the inherits a control with
Protected properties and add a public property that changes a base
control's Protected property.

Would I be doing something that I shouldn't?


Thanks





Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.