Alsing.Windows.Forms.SyntaxBox.Painter.NativePainter.InitGraphics C# (CSharp) Method

InitGraphics() public method

Implementation of the IPainter InitGraphics method. Initializes GDI32 backbuffers and brushes.
public InitGraphics ( ) : void
return void
        public void InitGraphics()
        {
            try
            {
                if (GFX.BackgroundBrush != null)
                    GFX.BackgroundBrush.Dispose();

                if (GFX.GutterMarginBrush != null)
                    GFX.GutterMarginBrush.Dispose();

                if (GFX.LineNumberMarginBrush != null)
                    GFX.LineNumberMarginBrush.Dispose();

                if (GFX.HighLightLineBrush != null)
                    GFX.HighLightLineBrush.Dispose();

                if (GFX.LineNumberMarginBorderBrush != null)
                    GFX.LineNumberMarginBorderBrush.Dispose();

                if (GFX.GutterMarginBorderBrush != null)
                    GFX.GutterMarginBorderBrush.Dispose();

                if (GFX.OutlineBrush != null)
                    GFX.OutlineBrush.Dispose();


                GFX.BackgroundBrush = new GDIBrush(Control.BackColor);
                GFX.GutterMarginBrush = new GDIBrush(Control.GutterMarginColor);
                GFX.LineNumberMarginBrush = new GDIBrush(Control.LineNumberBackColor);
                GFX.HighLightLineBrush = new GDIBrush(Control.HighLightedLineColor);
                GFX.LineNumberMarginBorderBrush = new GDIBrush(Control.LineNumberBorderColor);
                GFX.GutterMarginBorderBrush = new GDIBrush(Control.GutterMarginBorderColor);
                GFX.OutlineBrush = new GDIBrush(Control.OutlineColor);


                if (GFX.FontNormal != null)
                    GFX.FontNormal.Dispose();

                if (GFX.FontBold != null)
                    GFX.FontBold.Dispose();

                if (GFX.FontItalic != null)
                    GFX.FontItalic.Dispose();

                if (GFX.FontBoldItalic != null)
                    GFX.FontBoldItalic.Dispose();

                if (GFX.FontUnderline != null)
                    GFX.FontUnderline.Dispose();

                if (GFX.FontBoldUnderline != null)
                    GFX.FontBoldUnderline.Dispose();

                if (GFX.FontItalicUnderline != null)
                    GFX.FontItalicUnderline.Dispose();

                if (GFX.FontBoldItalicUnderline != null)
                    GFX.FontBoldItalicUnderline.Dispose();


                //	string font="courier new";
                string font = Control.FontName;
                float fontsize = Control.FontSize;
                GFX.FontNormal = new GDIFont(font, fontsize, false, false, false, false);
                GFX.FontBold = new GDIFont(font, fontsize, true, false, false, false);
                GFX.FontItalic = new GDIFont(font, fontsize, false, true, false, false);
                GFX.FontBoldItalic = new GDIFont(font, fontsize, true, true, false, false);
                GFX.FontUnderline = new GDIFont(font, fontsize, false, false, true, false);
                GFX.FontBoldUnderline = new GDIFont(font, fontsize, true, false, true, false);
                GFX.FontItalicUnderline = new GDIFont(font, fontsize, false, true, true, false);
                GFX.FontBoldItalicUnderline = new GDIFont(font, fontsize, true, true, true, false);

                InitIMEWindow();
            }
            catch (Exception) {}

            if (Control != null)
            {
                if (Control.IsHandleCreated)
                {
                    if (GFX.StringBuffer != null)
                        GFX.StringBuffer.Dispose();

                    if (GFX.SelectionBuffer != null)
                        GFX.SelectionBuffer.Dispose();

                    if (GFX.BackBuffer != null)
                        GFX.BackBuffer.Dispose();

                    GFX.StringBuffer = new GDISurface(1, 1, Control, true) {Font = GFX.FontNormal};
                    int h = GFX.StringBuffer.MeasureTabbedString("ABC", 0).Height + Control._SyntaxBox.RowPadding;
                    GFX.BackBuffer = new GDISurface(Control.ClientWidth, h, Control, true) {Font = GFX.FontNormal};

                    GFX.SelectionBuffer = new GDISurface(Control.ClientWidth, h, Control, true) {Font = GFX.FontNormal};

                    Control.View.RowHeight = GFX.BackBuffer.MeasureTabbedString("ABC", 0).Height + Control._SyntaxBox.RowPadding;
                    Control.View.CharWidth = GFX.BackBuffer.MeasureTabbedString(" ", 0).Width;
                }
            }
        }