Esempio n. 1
0
        /// <summary>
        /// calling the type tag.
        /// </summary>
        /// <param name="il">The <see cref="ILGenerator"/></param>
        /// <param name="tag">The <see cref="ITypeTag"/></param>
        /// <returns></returns>
        public static Type CallTypeTag(this ILGenerator il, ITypeTag tag)
        {
            switch (tag.GetType().Name)
            {
            case "BooleanTag":
                il.Emit(OpCodes.Ldc_I4, (tag as BooleanTag).Value ? 1 : 0);
                return(typeof(bool));

            case "NumberTag":
                switch (tag.Value.GetType().Name)
                {
                case "Int32":
                    il.Emit(OpCodes.Ldc_I4, (int)tag.Value);
                    return(typeof(int));

                case "Int64":
                    il.Emit(OpCodes.Ldc_I8, (long)tag.Value);
                    return(typeof(long));

                case "Single":
                    il.Emit(OpCodes.Ldc_R4, (float)tag.Value);
                    return(typeof(float));

                case "Double":
                    il.Emit(OpCodes.Ldc_R8, (double)tag.Value);
                    return(typeof(double));

                case "Int16":
                    il.Emit(OpCodes.Ldc_I4, (short)tag.Value);
                    return(typeof(short));

                default:
                    throw new NotSupportedException($"[NumberTag] : [{tag.Value}] is not supported");
                }

            case "OperatorTag":
            case "StringTag":
            default:
                il.Emit(OpCodes.Ldstr, tag.Value?.ToString() ?? string.Empty);
                return(typeof(string));
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 更新控件
 /// </summary>
 private void UpdateControl()
 {
     if (count == 0 || childControlType == null)
     {
         if (this.Size.Width != 100 || this.Size.Height != 100)
         {
             this.Size = new Size(100, 100);
         }
     }
     else
     {
         while (FlowLayoutPanel_Main.Controls.Count > count)
         {
             FlowLayoutPanel_Main.Controls.RemoveAt(FlowLayoutPanel_Main.Controls.Count - 1);
         }
         while (FlowLayoutPanel_Main.Controls.Count < count)
         {
             object   createObj     = Activator.CreateInstance(childControlType);
             Control  createControl = createObj as Control;
             ITypeTag iTypeTag      = createObj as ITypeTag;
             if (createControl != null)
             {
                 FlowLayoutPanel_Main.Controls.Add(createControl);
             }
             if (iTypeTag != null)
             {
                 iTypeTag.TypeTag = typeTag;
             }
             else
             {
                 return;
             }
         }
         int width  = FlowLayoutPanel_Main.Size.Width - Margin.Left * 2;
         int height = (FlowLayoutPanel_Main.Size.Height - Margin.Top * count * 2) / count;
         for (int i = 0; i < count; i++)
         {
             FlowLayoutPanel_Main.Controls[i].Size = new Size(width, height);
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 更新Item
        /// </summary>
        /// <param name="mustUpdateData">必须更新数据</param>
        public void UpdateItems(bool mustUpdateData = false)
        {
            Panel[] panels    = FlowLayoutPanel_Release_Other.Controls.OfType <Panel>().ToArray();
            int     outHeight = panels.Length * 3 * 2;

            foreach (Panel panel in panels)
            {
                ItemStruct itemStruct = panel.Tag as ItemStruct;
                if (itemStruct == null)
                {
                    FlowLayoutPanel_Release_Other.Controls.Remove(panel);
                }
                else
                {
                    //判断条件
                    if (itemStruct.ControlType != null && !string.IsNullOrEmpty(itemStruct.Label))
                    {
                        int maxHeight = 1;
                        //设置控件的说明
                        Label tempLabelControl = panel.Controls.OfType <Label>().Where(temp => string.Equals(temp.Name, "Label_Show")).FirstOrDefault();
                        if (tempLabelControl == null)
                        {
                            tempLabelControl = new Label();
                            panel.Controls.Add(tempLabelControl);
                            tempLabelControl.Name        = "Label_Show";
                            tempLabelControl.Text        = itemStruct.Label;
                            tempLabelControl.AutoSize    = true;
                            tempLabelControl.MaximumSize = new Size(150, 0);
                            //tempLabelControl.Width = panel.Size.Width / 2;
                            tempLabelControl.Location = new Point(3, 3);
                        }
                        else
                        {
                            tempLabelControl.Text = itemStruct.Label;
                        }
                        maxHeight = tempLabelControl.Height;
                        //设置控件的子控件
                        Control control       = panel.Controls.Find("ItemControl", false).FirstOrDefault();
                        int     controlHeight = 30;
                        if (control == null && itemStruct.ControlType.IsSubclassOf(typeof(Control)))
                        {
                            control = Activator.CreateInstance(itemStruct.ControlType) as Control;
                            panel.Controls.Add(control);
                            control.Name     = "ItemControl";
                            control.Location = new Point(9 + tempLabelControl.Width, 3);
                        }
                        if (control != null)
                        {
                            control.Tag = itemStruct.Tag;
                            ITypeTag iTypeTag = control as ITypeTag;
                            if (iTypeTag != null)
                            {
                                if (!string.Equals(iTypeTag.TypeTag, itemStruct.TypeTag) || mustUpdateData)
                                {
                                    iTypeTag.TypeTag = itemStruct.TypeTag;
                                    //是否不是数组
                                    if (!itemStruct.IsArray)
                                    {
                                        ITextValue iTextValue = control as ITextValue;
                                        if (skillAnalysisData != null && this.Tag != null)
                                        {
                                            string tempValue = skillAnalysisData.GetValue <string>(this.Tag.ToString(), itemStruct.Tag);
                                            if (iTextValue != null)
                                            {
                                                iTextValue.TextValue = tempValue;
                                            }
                                            else
                                            {
                                                control.Text = tempValue;
                                            }
                                            mustUpdateData = false;
                                        }
                                    }
                                }
                            }
                            IChildControlType iChildControlType = control as IChildControlType;
                            if (iChildControlType != null)
                            {
                                controlHeight *= itemStruct.ChildCount;
                                if (!string.Equals(iChildControlType.ChildControlType, itemStruct.ChildControlType) || mustUpdateData)
                                {
                                    iChildControlType.TextValues       = new string[itemStruct.ChildCount];
                                    iChildControlType.ChildControlType = itemStruct.ChildControlType;
                                    //是否是数组
                                    if (itemStruct.IsArray)
                                    {
                                        if (skillAnalysisData != null && this.Tag != null)
                                        {
                                            string[] tempValues = skillAnalysisData.GetValues <string>(this.Tag.ToString(), itemStruct.Tag);
                                            if (tempValues == null)
                                            {
                                                tempValues = new string[0];
                                            }
                                            string[] resultValues = new string[itemStruct.ChildCount];
                                            int      index        = 0;
                                            while (index < tempValues.Length && index < resultValues.Length)
                                            {
                                                resultValues[index] = tempValues[index];
                                                index++;
                                            }
                                            iChildControlType.TextValues = resultValues;
                                            mustUpdateData = false;
                                        }
                                    }
                                }
                                else if (iChildControlType.TextValues.Length != itemStruct.ChildCount || mustUpdateData)
                                {
                                    string[] tempValues = null;
                                    if (this.Tag != null)
                                    {
                                        tempValues = skillAnalysisData.GetValues <string>(this.Tag.ToString(), itemStruct.Tag);
                                    }
                                    if (tempValues == null)
                                    {
                                        tempValues = new string[0];
                                    }
                                    string[] resultValues = new string[itemStruct.ChildCount];
                                    string[] nowValues    = iChildControlType.TextValues;
                                    for (int i = 0; i < itemStruct.ChildCount; i++)
                                    {
                                        if (i < nowValues.Length)
                                        {
                                            resultValues[i] = nowValues[i];
                                            continue;
                                        }
                                        if (i < tempValues.Length)
                                        {
                                            resultValues[i] = tempValues[i];
                                        }
                                    }
                                    iChildControlType.TextValues = resultValues;
                                    mustUpdateData = false;
                                }
                            }
                            maxHeight = maxHeight > controlHeight ? maxHeight : controlHeight;
                        }

                        //设置父控件大小
                        panel.Size = new Size(FlowLayoutPanel_Release_Other.Width - 7, maxHeight + 6);
                        outHeight += maxHeight + 6;
                        //设置自身控件的大小
                        control.Size = new Size(panel.Size.Width - (12 + tempLabelControl.Width), controlHeight);
                    }
                    else
                    {
                        panel.Controls.Clear();
                        panel.Size = new Size(1, 1);
                    }
                }
            }
            FlowLayoutPanel_Release_Other.Size = new Size(FlowLayoutPanel_Release_Other.Size.Width, outHeight);
        }