I am able to draw a close button on tab using e.Graphics.Drawimage in OnDrawItem event of TabControl but i want to display the favicon of the website on that tab after the DocumentCompleted event of webbrowser control but i cannot use e.Graphics.Drawimage in DocumentCompleted event.
Is there an alternative way to do this.
Thanks for your help.
OnDrawItem is the correct way. If you do it any other way, your icon will be erased the next time the tab needs to be redrawn (e.g. if you switch to a different tab, or minimize and then restore the window). In WinForms, you should only draw a control from that control’s draw events.
What you need to do is, in your DocumentCompleted event, save off the icon (e.g. in a field on your UserControl or Form class), and then call
Invalidateon the tab control. That will result in your OnDrawItem event getting fired. Your OnDrawItem can then draw the icon, as long as the field has been assigned. Something roughly like this: