Exemple #1
0
        private void FormRegularNode_Load(object sender, EventArgs e)
        {
            comboBox1.DataSource = new RegularNodeTypeItem[]
            {
                RegularNodeTypeItem.Bool,
                RegularNodeTypeItem.Byte,
                RegularNodeTypeItem.Int16,
                RegularNodeTypeItem.UInt16,
                RegularNodeTypeItem.Int32,
                RegularNodeTypeItem.UInt32,
                RegularNodeTypeItem.Int64,
                RegularNodeTypeItem.UInt64,
                RegularNodeTypeItem.Float,
                RegularNodeTypeItem.Double,
                RegularNodeTypeItem.StringAscii,
                RegularNodeTypeItem.StringUnicode,
                RegularNodeTypeItem.StringUtf8,
            };

            if (RegularNode != null)
            {
                textBox1.Text          = RegularNode.Name;
                textBox2.Text          = RegularNode.Description;
                textBox3.Text          = RegularNode.Index.ToString( );
                comboBox1.SelectedItem = RegularNodeTypeItem.GetDataPraseItemByCode(RegularNode.RegularCode);
                textBox5.Text          = RegularNode.TypeLength.ToString( );
            }
        }
        private Bitmap GetRenderInfo(List <RegularNode> regulars, string selectedRegular)
        {
            regulars.Sort( );
            int max_byte          = regulars.Count == 0 ? 0 : regulars.Max(m => m.GetLengthByte( ));
            int every_byte_occupy = EveryByteWidth + 4;
            int every_line_count  = (panel1.Width - 19 - 90) / every_byte_occupy;
            int line_count        = GetNumberByUplimit(max_byte, every_line_count);


            Bitmap bitmap = new Bitmap(panel1.Width - 19, line_count * 50 + 5);

            if (max_byte == 0)
            {
                return(bitmap);
            }
            Graphics g = Graphics.FromImage(bitmap);

            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            StringFormat stringFormat = new StringFormat( );

            stringFormat.LineAlignment = StringAlignment.Center;
            stringFormat.Alignment     = StringAlignment.Center;
            Font font_7 = new Font("宋体", 7f);

            g.Clear(Color.AliceBlue);


            int paint_x = 85;
            int paint_y = 2;
            int count   = 0;

            g.DrawLine(Pens.Gray, paint_x - 5, 0, paint_x - 5, bitmap.Height);

            for (int i = 0; i < line_count; i++)
            {
                g.DrawString($"[{count.ToString( "D3" )} - {(count + Math.Min( max_byte - count - 1, every_line_count - 1 )).ToString( "D3" )}]", Font, Brushes.DimGray, new Point(2, paint_y + EveryByteWidth));

                for (int j = 0; j < every_line_count; j++)
                {
                    Rectangle rec = new Rectangle(paint_x + j * (EveryByteWidth + 4), paint_y + 17, EveryByteWidth, EveryByteWidth);
                    g.DrawRectangle(Pens.Gray, rec);
                    g.DrawString(count.ToString( ), font_7, Brushes.Black, new Rectangle(paint_x + j * every_byte_occupy - every_byte_occupy, paint_y + 17, 56, EveryByteWidth), stringFormat);
                    count++;

                    if (count >= max_byte)
                    {
                        break;
                    }
                }

                paint_y += 50;
            }

            paint_y = 2;

            for (int i = 0; i < regulars.Count; i++)
            {
                RegularNodeTypeItem regularNodeTypeItem = RegularNodeTypeItem.GetDataPraseItemByCode(regulars[i].RegularCode);

                int start  = regulars[i].GetStartedByteIndex( );
                int length = regulars[i].GetLengthByte( ) - regulars[i].GetStartedByteIndex( );

                int rowStart = GetNumberByUplimit(start, every_line_count);
                int rowEnd   = GetNumberByUplimit(start + length, every_line_count);


                // 同行的情况
                PaintLineAuxiliary(g, paint_x, paint_y, every_line_count, start, length, true, regulars[i].Name, Font, stringFormat, regulars[i]);

                // 绘制上面的数据
                if (regularNodeTypeItem.Length != 0)
                {
                    int tmp = start;
                    for (int j = 0; j < length / regularNodeTypeItem.Length; j++)
                    {
                        PaintLineAuxiliary(g, paint_x, paint_y, every_line_count, tmp, regularNodeTypeItem.Length, false, regularNodeTypeItem.Text, Font, stringFormat, regulars[i]);
                        tmp += regularNodeTypeItem.Length;
                    }
                }
                else
                {
                    PaintLineAuxiliary(g, paint_x, paint_y, every_line_count, start, length, false, regularNodeTypeItem.Text, Font, stringFormat, regulars[i]);
                }


                for (int j = 0; j < length; j++)
                {
                    int paint_x_tmp = paint_x + (start + j) % every_line_count * every_byte_occupy;
                    int paint_y_tmp = paint_y + 17 + (start + j) / every_line_count * 50;

                    Rectangle rec = new Rectangle(paint_x_tmp, paint_y_tmp, 16, 16);
                    g.FillRectangle(regularNodeTypeItem.BackColor, rec);
                    g.DrawRectangle(Pens.DimGray, rec);
                    g.DrawString((regulars[i].GetStartedByteIndex( ) + j).ToString( ), font_7, Brushes.Black, new Rectangle(paint_x_tmp - 20, paint_y_tmp, 56, 16), stringFormat);
                }
            }



            stringFormat.Dispose( );
            font_7.Dispose( );
            return(bitmap);
        }