Ejemplo n.º 1
0
        private void Create()
        {
            Destroy();

            if (Columns == null || Columns.Count == 0)
            {
                throw new Exception("This menu contains no columns");
            }

            if (Rows == null || Rows.Count == 0)
            {
                throw new Exception("This menu contains no rows");
            }

            Id = Internal.CreateMenu(Title, Columns.Count, Position.X, Position.Y,
                                     Columns[0].Width, Columns.Count == 2 ? Columns[1].Width : 0);

            if (Id == InvalidId)
            {
                return;
            }

            for (var i = 0; i < Math.Min(Columns.Count, 2); i++)
            {
                if (Columns[i].Caption != null)
                {
                    Internal.SetMenuColumnHeader(Id, i, Columns[i].Caption);
                }
            }

            for (var i = 0; i < Rows.Count; i++)
            {
                Internal.AddMenuItem(Id, 0, Rows[i].Column1Text ?? string.Empty);
                if (!string.IsNullOrEmpty(Rows[i].Column2Text))
                {
                    Internal.AddMenuItem(Id, 1, Rows[i].Column2Text);
                }

                if (Rows[i].Disabled)
                {
                    Internal.DisableMenuRow(Id, i);
                }
            }
        }