terça-feira, 22 de junho de 2021

C# - pesquisa de string em matriz 2D highlighter


Para representar dinamicamente um painel
com conteúdo composto por linhas e colunas,
O controle TableLayoutPanel é perfeito para isto.
O conteúdo de um TableLayoutPanel é organizado em uma grade,
e o seu layout é executado em tempo de design ou de execução.
Para criar este programa, arrastamos para o Form,
quatro controles, e adicionamos eventos para o form
e para o botão, e acoplamos no TableLayoutPanel
um label de duas dimensões.
O programa permite uma precisa pesquisa,
com destaque em highlighter, numa matriz
bidimensional de string, que é imprimida
pelo label criado manualmente.
Como a matriz é de 10 x 5, o label criado
também é, e evidentemente o TableLayoutPanel
possui as mesmas características para
linhas e colunas.
Este programa teve sua versão original
criada por nós mesmo no C++ Builder,
e achei muito justo recriá-lo em C#.
Poderíamos por exemplo, fazer subir
um arquivo com centenas de números
em extenso, para ser carregado
por uma lista, e aplicado para a impressão
no TableLayoutPanel, com sua propriedade
AutoScroll definida como verdadeiro;
Mas o programa é didático, e não há
a menor necessidade disto.
Confira no vídeo seu perfeito funcionamento.





        /*============================================================*/
        protected override void OnPaint ( PaintEventArgs e ) {
            Paint_Imagem ( e );
            this.Size = new System.Drawing.Size ( 615337 );
            this.Text = "C# - PESQUISA STRING EM MATRIZ 2D HIGHLIGHTER";
            this.BackColor = Color.White;
            Graphics dc = e.Graphics;
            Font myFont = new System.Drawing.Font ( "Consolas"12FontStyle.Italic );
            Brush myBrush_1 = new SolidBrush ( Color.Red );
            dc.DrawString ( "C# - PESQUISA STRING EM MATRIZ 2D HIGHLIGHTER",
                myFontmyBrush_110015 );
        }
        /*============================================================*/
        void Label_1 ( int Xint Yint Wint Hstring st ) {
            this.label1.Font = new System.Drawing.Font ( "Microsoft Sans Serif",
               9.75FSystem.Drawing.FontStyle.ItalicSystem.Drawing.GraphicsUnit.Point, ( ( byte ) ( 0 ) ) );
            this.label1.ForeColor = System.Drawing.Color.Blue;
            this.label1.Location = new System.Drawing.Point ( XY );
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size ( WH );
            this.label1.TabIndex = 3;
            this.label1.Text += st;
        }
        /*============================================================*/
        void TableLayoutPanel1_1 ( int Xint Yint Wint Hint Lint C ) {
            this.tableLayoutPanel1.AutoScroll = true;
            this.tableLayoutPanel1.ColumnCount = C;
            this.tableLayoutPanel1.ColumnStyles.Add ( new System.Windows.Forms.ColumnStyle ( System.Windows.Forms.SizeType.Percent30F ) );
            this.tableLayoutPanel1.ColumnStyles.Add ( new System.Windows.Forms.ColumnStyle ( System.Windows.Forms.SizeType.Percent30F ) );
            this.tableLayoutPanel1.Location = new System.Drawing.Point ( XY );
            this.tableLayoutPanel1.AutoSize = true;
            this.tableLayoutPanel1.Name = "tableLayoutPanel1";
            this.tableLayoutPanel1.RowCount = L;
            this.tableLayoutPanel1.RowStyles.Add ( new System.Windows.Forms.RowStyle ( System.Windows.Forms.SizeType.Percent30F ) );
            this.tableLayoutPanel1.RowStyles.Add ( new System.Windows.Forms.RowStyle ( System.Windows.Forms.SizeType.Percent30F ) );
            this.tableLayoutPanel1.Size = new System.Drawing.Size ( WH );
            this.tableLayoutPanel1.TabIndex = 4;
        }
        /*============================================================*/

Nenhum comentário:

Postar um comentário