Esempio n. 1
0
        protected override void OnPaintAdornments(PaintEventArgs pe)
        {
            base.OnPaintAdornments(pe);

            if (Control != null)
            {
                FieldContextControl ctl = Control as FieldContextControl;
                if (ctl != null)
                {
                    string str;
                    Brush  brsh = Brushes.Red;

                    if (ctl.AttachToField != null)
                    {
                        str = "->Field(" + ctl.AttachToField.FieldName + ")";
                    }
                    else
                    {
                        if (ctl.Record != null)
                        {
                            str = ctl.Record.RecordName;
                        }
                        else
                        {
                            str = "?";
                        }

                        str += ".[\"" + ctl.AttachToFieldName + "\"]";

                        if (ctl.AttachToParentRecord)
                        {
                            brsh = Brushes.Navy;
                            str  = "≈>" + str;
                        }
                    }


                    using (Font f = new Font("Tahoma", 6, FontStyle.Bold))
                        using (Brush backBrush =
                                   new LinearGradientBrush(new Rectangle(0, 0, 100, 14),
                                                           Color.FromArgb(0x80, Color.White),
                                                           Color.FromArgb(10, Color.Orange), 90))
                            Utils.DrawStringWithBackground(pe.Graphics, str, f, brsh, backBrush, 0, 0);
                }//context!=null
            }
        }
Esempio n. 2
0
 private void doComponentRemoving(object sender, ComponentEventArgs e)
 {
     if (e.Component is ModelBase)
     {
         FieldContextControl ctl = Control as FieldContextControl;
         if (ctl != null)
         {
             if (e.Component == ctl.AttachToRecord)
             {
                 ctl.AttachToRecord = null;
             }
             else
             if (e.Component == ctl.AttachToField)
             {
                 ctl.AttachToField = null;
             }
         }
     }
 }
Esempio n. 3
0
        public override object EditValue(ITypeDescriptorContext context,
                                         IServiceProvider provider, object value)
        {
            editorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;

            if (editorService == null)
            {
                return(value);
            }

            FieldContextControl control = context.Instance as FieldContextControl;


            ListBox aListBox = new ListBox();


            IEnumerable <string> fieldNames = null;



            if (control != null)
            {
                if (control.Record != null)
                {
                    fieldNames = control.Record.Fields.Select <Field, string>(item => item.FieldName);
                }
                else
                if (control.AttachToRecord != null)
                {
                    fieldNames = control.AttachToRecord.Fields.Select <Field, string>(item => item.FieldName);
                }
                else
                {
                    Record rec = Utils.FindParentRecord(control); //try to get from parent

                    if (rec == null)                              //try to create surrogate
                    {
                        string typeName = Utils.FindParentRecordSurrogateTypeName(control);

                        if (typeName != null)
                        {
                            using (DesignerRecordBinding b = new DesignerRecordBinding(control))
                                try
                                {
                                    b.AttachDesignTimeSurrogateRecord(typeName);
                                    if (b.Record == null)
                                    {
                                        throw new WFormsException("Could not create surrogate record class");
                                    }
                                    fieldNames = b.Record.Fields.Select <Field, string>(item => item.FieldName);
                                }
                                catch (Exception error)
                                {
                                    MessageBox.Show(
                                        string.Format(string.Format(StringConsts.SURROGATE_CREATE_ERROR, typeName, error.Message),
                                                      "Field Lookup Designer"
                                                      ));
                                }
                        }
                    }
                    else
                    {
                        fieldNames = rec.Fields.Select <Field, string>(item => item.FieldName);
                    }
                }
            }

            int itemIdx = 0;

            if (fieldNames != null)
            {
                foreach (string s in fieldNames)
                {
                    aListBox.Items.Add(s);
                    if ((control != null) && (control.AttachToFieldName == s))
                    {
                        aListBox.SelectedIndex = itemIdx;
                    }

                    itemIdx++;
                }
            }
            else
            {
                aListBox.Items.Add(string.Empty);
                aListBox.SelectedIndex = 0;
            }



            aListBox.SelectedIndexChanged +=
                new EventHandler(ItemSelected);

            editorService.DropDownControl(aListBox);


            if (aListBox.SelectedItem != null)
            {
                return(aListBox.SelectedItem.ToString());
            }
            else
            {
                return(string.Empty);
            }
        }