Exemplo n.º 1
0
        void update_line_numbers()
        {
            if (LineNumberPixBox.Image == null || (LineNumberPixBox.Width != LineNumberPixBox.Image.Width || LineNumberPixBox.Height != LineNumberPixBox.Image.Height))
            {
                if (LineNumberPixBox.Image != null)
                {
                    LineNumberPixBox.Image.Dispose();
                }

                Bitmap pbox_bmp = new Bitmap(LineNumberPixBox.Width, LineNumberPixBox.Height, PixelFormat.Format32bppPArgb);
                LineNumberPixBox.Image = pbox_bmp;

                m_gfx = Graphics.FromImage(pbox_bmp);
            }

            m_gfx.Clear(Color.White);

            if (ScriptTextBox.Lines.Length > 0 && m_line_height > 0)
            {
                update_line_number_pixbox_width();

                int pix_offset = (ScriptTextBox.GetPositionFromCharIndex(0).Y % m_line_height);

                m_tmp_pos.X = m_tmp_pos.Y = 0;
                int first_ind  = ScriptTextBox.GetCharIndexFromPosition(m_tmp_pos);
                int first_line = ScriptTextBox.GetLineFromCharIndex(first_ind);

                m_tmp_pos.X = ClientRectangle.Width;
                m_tmp_pos.Y = ClientRectangle.Height;
                int last_ind  = ScriptTextBox.GetCharIndexFromPosition(m_tmp_pos);
                int last_line = ScriptTextBox.GetLineFromCharIndex(last_ind);

                int line_offset;
                int y_step;

                for (int i = 0; i <= last_line - first_line; i++)
                {
                    line_offset = first_line + i;
                    y_step      = pix_offset + (i * m_line_height);

                    m_gfx.FillRectangle(((line_offset & 0x01) == 0x01) ? m_brush_white:m_brush_gray, 0, y_step, LineNumberScriptFieldSplitContainer.SplitterDistance, m_line_height);
                    m_gfx.DrawString((line_offset + 1).ToString(), ScriptTextBox.Font, m_brush_dark_gray, 0, y_step);
                }
            }

            LineNumberPixBox.Invalidate();
        }