コード例 #1
0
        /// <summary>
        /// Adds a <see cref="HelpIcon"/> on the right of the control with the pvorided help text
        /// </summary>
        /// <param name="c">The control you want the help to appear beside</param>
        /// <param name="title">The textual header you want shown</param>
        /// <param name="body">The text you want displayed on hover (under the title)</param>
        /// <param name="anchor">Explicit anchor style to apply to help icon.  If you pass None (default) then anchor will
        ///  be chosen based on the control <paramref name="c"/></param>
        public void AddHelpString(Control c, string title, string body, AnchorStyles anchor = AnchorStyles.None)
        {
            //don't add help to the control more than once
            if (_helpAdded.Contains(c))
            {
                return;
            }

            _helpAdded.Add(c);

            var help = new HelpIcon();

            help.SetHelpText(title, body);

            help.Location = new Point(c.Right + 3, c.Top);

            if (anchor == AnchorStyles.None)
            {
                if (c.Anchor.HasFlag(AnchorStyles.Right) && c.Anchor.HasFlag(AnchorStyles.Top))
                {
                    help.Anchor = AnchorStyles.Right | AnchorStyles.Top;
                }
                else if (c.Anchor.HasFlag(AnchorStyles.Right) && c.Anchor.HasFlag(AnchorStyles.Bottom))
                {
                    help.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
                }
            }
            else
            {
                help.Anchor = anchor;
            }

            c.Parent.Controls.Add(help);
        }
コード例 #2
0
        /// <summary>
        /// Adds a <see cref="HelpIcon"/> to the task bar at the top of the control
        /// </summary>
        /// <param name="title"></param>
        /// <param name="body"></param>
        public void AddHelpStringToToolStrip(string title, string body)
        {
            var help = new HelpIcon();

            help.SetHelpText(title, body);
            Add(new ToolStripControlHost(help));
        }
コード例 #3
0
ファイル: HelpIconTests.cs プロジェクト: HicServices/RDMP
        public void TestNullInputs_HelpIcon()
        {
            var hi = new HelpIcon();

            hi.SetHelpText(null, null);
            hi.SetHelpText("", "");
            Assert.IsNull(hi.HoverText);
        }
コード例 #4
0
ファイル: HelpIconTests.cs プロジェクト: HicServices/RDMP
        public void TestLongInputs_HelpIcon()
        {
            var hi = new HelpIcon();

            //length is over 150 characters
            string testLongString = "kdsfldsfjsdafdfjsdafldsafadsfksdafjdfjdsfasdjfdsjfsdfldsjfkdsfkdsfksdafjdfsdaf;sdafsdafadsflsdafksdfjadslfjdsflsdjfldsfksadkfadkfasdfadsjfasdsdfladsfjsdjfkdflsdfksdfkadsfladsfj";

            hi.SetHelpText(null, testLongString);
            Assert.AreEqual(HelpIcon.MaxHoverTextLength, hi.HoverText.Length);
        }
コード例 #5
0
        private void CreateLine(IArgumentHost parent, IArgument argument, RequiredPropertyInfo required, float maxArgNameWidth)
        {
            Label name = new Label();

            HelpIcon helpIcon = new HelpIcon();

            helpIcon.SetHelpText(GetSystemTypeName(argument.GetSystemType()) ?? "Unrecognised Type:" + argument.Type, required.Demand.Description);
            helpIcon.Dock = DockStyle.Right;

            string spaceSeparatedArgumentName = UsefulStuff.PascalCaseStringToHumanReadable(argument.Name);

            name.Height    = helpIcon.Height;
            name.Text      = spaceSeparatedArgumentName;
            name.TextAlign = ContentAlignment.MiddleLeft;
            name.Dock      = DockStyle.Left;
            name.Width     = (int)maxArgNameWidth + 3 /*padding*/;

            RAGSmiley ragSmiley = new RAGSmiley();

            if (required.Demand.Mandatory && string.IsNullOrWhiteSpace(argument.Value))
            {
                ragSmiley.Fatal(new Exception("Property " + argument.Name + " is Mandatory"));
            }

            var args = new ArgumentValueUIArgs();

            args.Parent      = parent;
            args.Type        = argument.GetSystemType();
            args.ContextText = required.Demand.ContextText;

            try
            {
                args.InitialValue = argument.GetValueAsSystemType();
            }
            catch (Exception e)
            {
                //add the text value value and report the error
                if (_valueUisFactory.CanHandleInvalidStringData(args.Type))
                {
                    args.InitialValue = argument.Value;
                }
                else
                {
                    args.InitialValue = null;
                }

                ragSmiley.Fatal(e);
            }


            args.Required            = required;
            args.CatalogueRepository = (ICatalogueRepository)argument.Repository;
            args.Setter = (v) =>
            {
                ragSmiley.Reset();

                try
                {
                    argument.SetValue(v);
                    argument.SaveToDatabase();

                    argument.GetValueAsSystemType();

                    if (required.Demand.Mandatory && (v == null || string.IsNullOrWhiteSpace(v.ToString())))
                    {
                        ragSmiley.Fatal(new Exception("Property " + argument.Name + " is Mandatory"));
                    }
                }
                catch (Exception ex)
                {
                    ragSmiley.OnCheckPerformed(new CheckEventArgs("Failed to set property properly", CheckResult.Fail, ex));
                }
            };
            args.Fatal = ragSmiley.Fatal;

            var valueui = (Control)_valueUisFactory.Create(_activator, args);

            valueui.Dock = DockStyle.Fill;

            Panel p = new Panel();

            p.Height = Math.Max(Math.Max(lblClassName.Height, helpIcon.Height), valueui.Height);
            p.Dock   = DockStyle.Top;

            name.Location = new Point(0, 0);
            p.Controls.Add(name);

            helpIcon.Left = name.Right;
            p.Controls.Add(helpIcon);

            ragSmiley.Dock = DockStyle.Right;
            p.Controls.Add(ragSmiley);
            p.Controls.Add(valueui);

            name.Height = p.Height;

            Label hr = new Label();

            hr.AutoSize    = false;
            hr.BorderStyle = BorderStyle.FixedSingle;
            hr.Height      = 1;
            hr.Dock        = DockStyle.Bottom;
            p.Controls.Add(hr);

            valueui.BringToFront();
            pArguments.Controls.Add(p);
        }
コード例 #6
0
ファイル: ArgumentCollectionUI.cs プロジェクト: rkm/RDMP
        private void CreateLine(IArgumentHost parent, IArgument argument, RequiredPropertyInfo required)
        {
            Label name = new Label();

            HelpIcon helpIcon = new HelpIcon();

            helpIcon.SetHelpText(GetSystemTypeName(argument.GetSystemType()) ?? "Unrecognised Type:" + argument.Type, required.Demand.Description);
            helpIcon.Anchor = AnchorStyles.Top | AnchorStyles.Left;

            string spaceSeparatedArgumentName = UsefulStuff.PascalCaseStringToHumanReadable(argument.Name);

            name.Height    = helpIcon.Height;
            name.Text      = spaceSeparatedArgumentName;
            name.TextAlign = ContentAlignment.MiddleLeft;
            name.AutoSize  = true;
            name.Anchor    = AnchorStyles.Top | AnchorStyles.Left;

            RAGSmiley ragSmiley = new RAGSmiley();

            if (required.Demand.Mandatory && string.IsNullOrWhiteSpace(argument.Value))
            {
                ragSmiley.Fatal(new Exception("Property " + argument.Name + " is Mandatory"));
            }

            var args = new ArgumentValueUIArgs();

            args.Parent = parent;
            args.Type   = argument.GetSystemType();

            try
            {
                args.InitialValue = argument.GetValueAsSystemType();
            }
            catch (Exception e)
            {
                //add the text value value and report the error
                if (_valueUisFactory.CanHandleInvalidStringData(args.Type))
                {
                    args.InitialValue = argument.Value;
                }
                else
                {
                    args.InitialValue = null;
                }

                ragSmiley.Fatal(e);
            }


            args.Required            = required;
            args.CatalogueRepository = (ICatalogueRepository)argument.Repository;
            args.Setter = (v) =>
            {
                ragSmiley.Reset();

                try
                {
                    argument.SetValue(v);
                    argument.SaveToDatabase();

                    argument.GetValueAsSystemType();

                    if (required.Demand.Mandatory && (v == null || string.IsNullOrWhiteSpace(v.ToString())))
                    {
                        ragSmiley.Fatal(new Exception("Property " + argument.Name + " is Mandatory"));
                    }
                }
                catch (Exception ex)
                {
                    ragSmiley.OnCheckPerformed(new CheckEventArgs("Failed to set property properly", CheckResult.Fail, ex));
                }
            };
            args.Fatal = ragSmiley.Fatal;

            var valueui = (Control)_valueUisFactory.Create(args);

            valueui.Anchor = name.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            _valueUIs.Add(valueui);

            Panel p = new Panel();

            p.Height      = Math.Max(Math.Max(lblClassName.Height, helpIcon.Height), valueui.Height);
            p.Width       = pArguments.ClientRectangle.Width;
            p.Anchor      = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            p.BorderStyle = BorderStyle.FixedSingle;
            p.Location    = new Point(0, _currentY);
            _currentY    += p.Height;

            name.Location = new Point(0, 0);
            p.Controls.Add(name);

            helpIcon.Left = name.Right;
            p.Controls.Add(helpIcon);

            ragSmiley.Left   = p.Width - ragSmiley.Width;
            ragSmiley.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            p.Controls.Add(ragSmiley);

            valueui.Left    = helpIcon.Right;
            valueui.Width   = p.Width - (helpIcon.Right + ragSmiley.Left);
            _maxValueUILeft = Math.Max(_maxValueUILeft, valueui.Left);
            p.Controls.Add(valueui);
            p.MinimumSize = new Size(ragSmiley.Right, p.Height);

            name.Height = p.Height;

            pArguments.Controls.Add(p);
        }