PavelTorgashov / FastColoredTextBox

Fast Colored TextBox for Syntax Highlighting. The text editor component for .NET.
Other
1.21k stars 463 forks source link

ArgumentException with FATabStrip #262

Closed fraaaaa4 closed 10 months ago

fraaaaa4 commented 10 months ago

Hello,

I have quite a nasty bug in a projet of mine where I use faTabStrip together with FastColoredTextbox to make a tabbed text editor. Every time I add a tab, and then switch back and forth, if I modify one of the two (e.g. even just, zooming in), the entire control crashes with an ArgumentException.

Here's the code I have for when it changes tab:

private void faTabStrip1_TabStripItemSelectionChanged(FarsiLibrary.Win.TabStripItemChangedEventArgs e)
        {
            try {
            documentMap1.Target = CurrentTB;
            if (CurrentTB != null)
            {
                toolStripStatusLabel1.Text = "Syntax: " + CurrentTB.Language.ToString();
                string text = CurrentTB.Text;

            } 
            }catch (Exception ex2){
            }

        }

and CurrentTB, taken directly from the demo:

FastColoredTextBoxNS.FastColoredTextBox CurrentTB
        {
            get
            {
                if (faTabStrip1.SelectedItem != null && faTabStrip1.SelectedItem.Controls.Count > 0)
                {
                    return (faTabStrip1.SelectedItem.Controls[0] as FastColoredTextBoxNS.FastColoredTextBox);
                }

                return null; // Nessun controllo presente o nessuna scheda selezionata
            }

            set
            {
                if (value != null)
                {
                    FarsiLibrary.Win.FATabStripItem tabItem = value.Parent as FarsiLibrary.Win.FATabStripItem;
                    if (tabItem != null)
                    {
                        faTabStrip1.SelectedItem = tabItem;
                        value.Focus();
                    }
                }
            }
        }

and here is the stack track: Data: {System.Collections.ListDictionaryInternal} StackTrace:

"   in System.Drawing.Graphics.CheckErrorStatus(Int32 status)\r\n   in System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)\r\n   in FastColoredTextBoxNS.FastColoredTextBox.OnPaint(PaintEventArgs e)\r\n   in System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)\r\n   in System.Windows.Forms.Control.WmPaint(Message& m)\r\n   in System.Windows.Forms.Control.WndProc(Message& m)\r\n   in System.Windows.Forms.ScrollableControl.WndProc(Message& m)\r\n   in System.Windows.Forms.ContainerControl.WndProc(Message& m)\r\n   in System.Windows.Forms.UserControl.WndProc(Message& m)\r\n   in FastColoredTextBoxNS.FastColoredTextBox.WndProc(Message& m)\r\n   in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)\r\n   in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\r\n   in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)"