Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Preventing OnDrawItem from being called?
 

Preventing OnDrawItem from being called?

in an inherited TabControl that's being ownerDrawn, is there any way to prevent OnDrawItem from being called when the width of the control is changed? essentially i need the tabstrip to stay the same but im changing the width of the control for the needed functionality (animated sliding right-aligned tabcontrol) ..i have a timer going while the width is < the itemSize height or whatever..it FUNCTIONS fine it's just that OnDrawItem() is getting called for each of the tabs EACH time the width is changed and it's causing horrible flickering, even with double buffering..i've set ControlStyle.ResizeRedraw to false without any luck, it's still calling OnDrawItem -- just wondering if there's any way to prevent OnDrawItem from being called, or preventing it from DOING anything when i'm animating (i've tried setting a boolean while im animating and if (!currently_animating)  { // do my DrawItem functionality here } but it's still doing some base set of drawing (I'm assuming the separator lines and such) ..any ideas? Thanks!
-Randy
MigrationUser 1  Sunday, March 02, 2003 12:16 AM
Just wanted to make sure you set the double buffering correctly -- this generally requires setting three styles, right? Did you set all three to true (AllPaintinginWMPaint, UserPaint, and DoubleBuffer)? And did you move all painting code to the overridden Paint event? Otherwise, I don't believe double-buffering can work. 
MigrationUser 1  Monday, March 03, 2003 9:45 AM
here are the 5 controlflags i have set:

this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.UserPaint,true); 
this.SetStyle(ControlStyles.DoubleBuffer,true);
this.SetStyle(ControlStyles.Selectable,true); 
this.SetStyle(ControlStyles.ResizeRedraw,false); 
MigrationUser 1  Monday, March 03, 2003 11:48 AM
Well, those look cool. The only other "simple" suggestion I can make is to verify that all your painting happens in the Paint event--that is, you don't grab a graphics object anywhere else other than your Paint event.
MigrationUser 1  Monday, March 03, 2003 11:53 AM
actually that is the problem..damn.
quick one for you, how would i construct the DrawItemEventArgs to send to OnDrawItem()?
right now in my OnPaint override:
if (!this._moving)
{
   for (int i=0;i<this.TabCount;i++)
   { 
   }
}

..but im not sure how to construct the DrawItemEventArgs for each tab because of the Rectangle required..how would i figure out the Rectangle to send it?

MigrationUser 1  Monday, March 03, 2003 11:57 AM
I haven't done an ownerdraw Tab, so I'm not up on the details (done combo/list/menu, but never tabs). Seems to me that you must somehow indicate from within the code that's painting your tabs that you need to have painting done (i usually set class-level flags for this) and then invalidate the form. In the Paint event, you check the flag and redraw the thing that needs to be redrawn. 
MigrationUser 1  Monday, March 03, 2003 12:11 PM
TabControl has a GetTabRect that returns the rectangle for the tab. 

Regarding your initial issue, you might be able to p/invoke the Win32 api LockWindowUpdate that is supposed to prevent Paint messages from being processed. Don't forget to "unlock" the window when you are done with your animation effect.

-mark
MigrationUser 1  Monday, March 03, 2003 1:18 PM

You can use google to search for other answers

Custom Search

More Threads

• Making the Property Hide according to control in Multiple selection.
• What is Regular Expression for US Phone Number(Windows application)?
• ICustomTypeDescriptor vs. Remoting
• can no longer open forms in the designer
• How to Access a project from another project
• Windows XP theme in windows application in .net
• Add controls to datagrid in VS2003
• Windows Forms : designerCould not be shown. dotnetfx setup messy?
• Set collection item value through PropertyDescriptor?
• Designer does not generate content code for object value