3 Stimmen

Winforms TabControl verursacht fehlerhafte Paint-Ereignisse für UserControl

Für unser Projekt haben wir ein WinForms UserControl für die grafische Darstellung geschrieben.

Wir sehen ein seltsames Verhalten, wenn unser Steuerelement in einem TabControl platziert ist - unser Steuerelement feuert kontinuierlich Paint-Ereignisse, auch wenn es absolut keine Aktivität durch den Benutzer gibt.

Wir sehen dies nur im TabControl. Wenn wir unser Steuerelement in anderen Containern wie Formularen oder Splittern platzieren, wird Paint nur dann ausgelöst, wenn Sie es erwarten, z. B. wenn das Steuerelement zum ersten Mal angezeigt wird.

Kann mir jemand sagen, warum dies der Fall sein könnte?

Hier ist ein Stack-Trace von einem Haltepunkt im Paint-Handler unseres Steuerelements, falls das eine Hilfe ist. Unser Steuerelement ist BaseGraphXY, das auf einem TabControl sitzt, das auf einigen verschachtelten SplitContainern sitzt. Sorry für die Formatierung - konnte nicht bekommen, die SO-Editor zu stoppen, aus irgendeinem Grund umbrechen.

OverlordFrontEnd.exe!OverlordFrontEnd.MainForm.graphControl_Paint(object sender =  BI_BaseGraphXY.BaseGraphXY}, System.Windows.Forms.PaintEventArgs e = {ClipRectangle = {X=0,Y=0,Width=1031,Height=408}}) Line 422 C#
System.Windows.Forms.dll!System.Windows.Forms.Control.OnPaint(System.Windows.Forms.PaintEventArgs e) + 0x73 bytes   
BI_AppCore.dll!BI_BaseGraphXY.BaseGraphXY.OnPaint(System.Windows.Forms.PaintEventArgs e = {ClipRectangle = {X=0,Y=0,Width=1031,Height=408}}) Line 377 + 0xb bytes   C#
System.Windows.Forms.dll!System.Windows.Forms.Control.PaintTransparentBackground(System.Windows.Forms.PaintEventArgs e, System.Drawing.Rectangle rectangle, System.Drawing.Region transparentRegion = null) + 0x16c bytes   
System.Windows.Forms.dll!System.Windows.Forms.Control.PaintBackground(System.Windows.Forms.PaintEventArgs e = {ClipRectangle = {X=0,Y=0,Width=1029,Height=406}}, System.Drawing.Rectangle rectangle, System.Drawing.Color backColor, System.Drawing.Point scrollOffset) + 0xbc bytes    
System.Windows.Forms.dll!System.Windows.Forms.Control.PaintBackground(System.Windows.Forms.PaintEventArgs e, System.Drawing.Rectangle rectangle) + 0x63 bytes   
System.Windows.Forms.dll!System.Windows.Forms.Control.OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent) + 0x59 bytes    
System.Windows.Forms.dll!System.Windows.Forms.Control.PaintWithErrorHandling(System.Windows.Forms.PaintEventArgs e = {ClipRectangle = {X=0,Y=0,Width=1029,Height=406}}, short layer, bool disposeEventArgs = false) + 0x74 bytes    
System.Windows.Forms.dll!System.Windows.Forms.Control.WmPaint(ref System.Windows.Forms.Message m) + 0x1ba bytes 
System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x33e bytes 
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0x10 bytes    
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x31 bytes  
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 15, System.IntPtr wparam, System.IntPtr lparam) + 0x5a bytes  
[Native to Managed Transition]  
[Managed to Native Transition]  
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID, int reason = -1, int pvLoopData = 0) + 0x24e bytes 
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.WinFormsAppContext}) + 0x177 bytes    
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x61 bytes    
System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.ApplicationContext context) + 0x18 bytes 
Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() + 0x81 bytes    
Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() + 0xef bytes   
Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(string[] commandLine) + 0x2c0 bytes 
OverlordFrontEnd.exe!OverlordFrontEnd.Program.Main() Line 36 + 0x10 bytes   C#
[Native to Managed Transition]  
[Managed to Native Transition]  
mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) + 0x3a bytes    
Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x2b bytes  
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x66 bytes   
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x6f bytes    
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x44 bytes

1voto

Tab Control hat einige Macken, versuchen Sie, mit SetStyle zu basteln:

Me.SetStyle(ControlStyles.UserPaint oder ControlStyles.AllPaintingInWmPaint oder ControlStyles.OptimizedDoubleBuffer oder ControlStyles.DoubleBuffer oder ControlStyles.Selectable oder ControlStyles.ResizeRedraw, True)

1voto

Tom Bushell Punkte 5825

Mein Kollege hat eine Lösung für dieses Problem gefunden:

Das Problem mit dem Diagramm-Steuerelement war, dass die Eigenschaft BackColor standardmäßig auf System.Drawing.Color.Transparent eingestellt war. Dies führte zu einer Art "Rückkopplungsschleife" von Meldungen. Ich vermute, dass es auf diese Weise funktionieren soll? Jedenfalls habe ich den Konstruktor geändert, um System.Drawing.SystemColors.ControlLightLight als Standard-BackColor-Eigenschaft zu verwenden. Dies scheint das zusätzliche Malen der Grafik zu unterdrücken.

CodeJaeger.com

CodeJaeger ist eine Gemeinschaft für Programmierer, die täglich Hilfe erhalten..
Wir haben viele Inhalte, und Sie können auch Ihre eigenen Fragen stellen oder die Fragen anderer Leute lösen.

Powered by:

X