Forex_Strategy_Builder.Strategy_Layout.PnlProperties_Paint C# (CSharp) Method

PnlProperties_Paint() public method

Panel properties Paint
public PnlProperties_Paint ( object sender, PaintEventArgs e ) : void
sender object
e PaintEventArgs
return void
        void PnlProperties_Paint(object sender, PaintEventArgs e)
        {
            Panel pnl = (Panel)sender;
            Graphics g = e.Graphics;
            int width = pnl.ClientSize.Width;

            Color colorCaptionBack = LayoutColors.ColorSlotCaptionBackAveraging;
            Color colorCaptionText = LayoutColors.ColorSlotCaptionText;
            Color colorBackground  = LayoutColors.ColorSlotBackground;
            Color colorLogicText   = LayoutColors.ColorSlotLogicText;
            Color colorDash        = LayoutColors.ColorSlotDash;

            // Caption
            string stringCaptionText = Language.T("Strategy Properties");
            Font   fontCaptionText   = new Font(Font.FontFamily, 9);
            float  captionHeight     = (float)Math.Max(fontCaptionText.Height, 18);
            float  captionWidth      = width;
            Brush  brushCaptionText  = new SolidBrush(colorCaptionText);
            StringFormat stringFormatCaption  = new StringFormat();
            stringFormatCaption.LineAlignment = StringAlignment.Center;
            stringFormatCaption.Trimming      = StringTrimming.EllipsisCharacter;
            stringFormatCaption.FormatFlags   = StringFormatFlags.NoWrap;
            stringFormatCaption.Alignment     = StringAlignment.Center;

            RectangleF rectfCaption = new RectangleF(0, 0, captionWidth, captionHeight);
            Data.GradientPaint(g, rectfCaption, colorCaptionBack, LayoutColors.DepthCaption);
            g.DrawString(stringCaptionText, fontCaptionText, brushCaptionText, rectfCaption, stringFormatCaption);

            // Border
            Pen penBorder = new Pen(Data.GetGradientColor(colorCaptionBack, -LayoutColors.DepthCaption), border);
            g.DrawLine(penBorder, 1, captionHeight, 1, pnl.Height);
            g.DrawLine(penBorder, pnl.Width - border + 1, captionHeight, pnl.Width - border + 1, pnl.Height);
            g.DrawLine(penBorder, 0, pnl.Height - border + 1, pnl.Width, pnl.Height - border + 1);

            // Paint the panel's background
            RectangleF rectfPanel = new RectangleF(border, captionHeight, pnl.Width - 2 * border, pnl.Height - captionHeight - border);
            Data.GradientPaint(g, rectfPanel, colorBackground, LayoutColors.DepthControl);

            int vPosition = (int)captionHeight + 2;

            // Padlock image
            if (showPadlockImg)
            {
                if (strategy.PropertiesStatus == StrategySlotStatus.Locked)
                    g.DrawImage(Properties.Resources.padlock_img, 1, 1, 16, 16);
                else if (strategy.PropertiesStatus == StrategySlotStatus.Open)
                    g.DrawImage(Properties.Resources.open_padlock, 1, 1, 16, 16);
                else if (strategy.PropertiesStatus == StrategySlotStatus.Linked)
                    g.DrawImage(Properties.Resources.linked, 1, 1, 16, 16);
            }

            StringFormat stringFormat = new StringFormat();
            stringFormat.Trimming     = StringTrimming.EllipsisCharacter;
            stringFormat.FormatFlags  = StringFormatFlags.NoWrap;

            Font  fontParam  = new Font(Font.FontFamily, 9f, FontStyle.Regular);
            Font  fontValue  = new Font(Font.FontFamily, 9f, FontStyle.Regular);
            Brush brushParam = new SolidBrush(colorLogicText);
            Brush brushValue = new SolidBrush(colorLogicText);
            Pen   penDash    = new Pen(colorDash);

            string strPermaSL = strategy.UsePermanentSL ? (Data.Strategy.PermanentSLType == PermanentProtectionType.Absolute ? "(Abs) " : "") + strategy.PermanentSL.ToString() : Language.T("None");
            string strPermaTP = strategy.UsePermanentTP ? (Data.Strategy.PermanentTPType == PermanentProtectionType.Absolute ? "(Abs) " : "") + strategy.PermanentTP.ToString() : Language.T("None");
            string strBreakEven = strategy.UseBreakEven ? strategy.BreakEven.ToString() : Language.T("None");

            if (slotMinMidMax == SlotSizeMinMidMax.min)
            {
                string param = Language.T(strategy.SameSignalAction.ToString()) + "; " +
                               Language.T(strategy.OppSignalAction.ToString())  + "; " +
                               "SL-" + strPermaSL + "; " +
                               "TP-" + strPermaTP;// +"; " + "BE-" + strBreakEven;

                SizeF sizeParam      = g.MeasureString(param, fontParam);
                float maxParamWidth = sizeParam.Width;

                // Padding Param Padding Dash Padding Value Padding
                float padding        = space;
                float necessaryWidth = 2 * padding + maxParamWidth;

                if (width > necessaryWidth)
                {   // Padding Param Padding
                    padding = (float)Math.Max((pnl.ClientSize.Width - maxParamWidth) / 2, padding);
                }
                else
                {
                    padding = 2;
                }

                float tabParam = padding;

                PointF pointParam = new PointF(tabParam, vPosition);
                g.DrawString(param, fontParam, brushParam, pointParam);

            }
            else
            {
                // Find Maximum width of the strings
                string [] asParams = new string [5]
                {
                    Language.T("Same direction signal"),
                    Language.T("Opposite direction signal"),
                    Language.T("Permanent Stop Loss"),
                    Language.T("Permanent Take Profit"),
                    Language.T("Break Even")
                };

                string [] asValues = new string [5] {
                    Language.T(strategy.SameSignalAction.ToString()),
                    Language.T(strategy.OppSignalAction.ToString()),
                    strPermaSL,
                    strPermaTP,
                    strBreakEven
                };

                float maxParamWidth = 0;
                foreach (string param in asParams)
                {
                    if (g.MeasureString(param, fontParam).Width > maxParamWidth)
                        maxParamWidth = g.MeasureString(param, fontParam).Width;
                }

                float maxValueWidth = 0;
                foreach (string value in asValues)
                {
                    if (g.MeasureString(value, fontParam).Width > maxValueWidth)
                        maxValueWidth = g.MeasureString(value, fontParam).Width;
                }

                // Padding Param Padding Dash Padding Value Padding
                float padding   = space;
                float dashWidth = 5;
                float necessaryWidth = 4 * padding + maxParamWidth + maxValueWidth + dashWidth;

                if (width > necessaryWidth)
                {   // 2*Padding Param Padding Dash Padding Value 2*Padding
                    padding = (float)Math.Max((pnl.ClientSize.Width - maxParamWidth - maxValueWidth - dashWidth) / 6, padding);
                }
                else
                {
                    padding = 2;
                }

                float tabParam = 2 * padding;
                float tabDash  = tabParam + maxParamWidth + padding;
                float tabValue = tabDash  + dashWidth     + padding;

                // Same direction
                string sParam = Language.T("Same direction signal");
                string sValue = Language.T(strategy.SameSignalAction.ToString());
                PointF pointParam = new PointF(tabParam, vPosition);
                PointF pointDash1 = new PointF(tabDash, vPosition + fontParam.Height / 2 + 2);
                PointF pointDash2 = new PointF(tabDash + dashWidth, vPosition + fontParam.Height / 2 + 2);
                PointF pointValue = new PointF(tabValue, vPosition);
                SizeF  sizefValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
                RectangleF rectfValue = new RectangleF(pointValue, sizefValue);
                g.DrawString(sParam, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat);
                vPosition += fontValue.Height + 2;

                // Opposite direction
                sParam = Language.T("Opposite direction signal");
                sValue = Language.T(strategy.OppSignalAction.ToString());
                pointParam = new PointF(tabParam, vPosition);
                pointDash1 = new PointF(tabDash, vPosition + fontParam.Height / 2 + 2);
                pointDash2 = new PointF(tabDash + dashWidth, vPosition + fontParam.Height / 2 + 2);
                pointValue = new PointF(tabValue, vPosition);
                sizefValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
                rectfValue = new RectangleF(pointValue, sizefValue);
                g.DrawString(sParam, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat);
                vPosition += fontValue.Height + 2;

                // Permanent Stop Loss
                sParam = Language.T("Permanent Stop Loss");
                sValue = strPermaSL;
                pointParam = new PointF(tabParam, vPosition);
                pointDash1 = new PointF(tabDash, vPosition + fontParam.Height / 2 + 2);
                pointDash2 = new PointF(tabDash + dashWidth, vPosition + fontParam.Height / 2 + 2);
                pointValue = new PointF(tabValue, vPosition);
                sizefValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
                rectfValue = new RectangleF(pointValue, sizefValue);
                g.DrawString(sParam, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat);
                vPosition += fontValue.Height + 2;

                // Permanent Take Profit
                sParam = Language.T("Permanent Take Profit");
                sValue = strPermaTP;
                pointParam = new PointF(tabParam, vPosition);
                pointDash1 = new PointF(tabDash, vPosition + fontParam.Height / 2 + 2);
                pointDash2 = new PointF(tabDash + dashWidth, vPosition + fontParam.Height / 2 + 2);
                pointValue = new PointF(tabValue, vPosition);
                sizefValue = new SizeF(Math.Max(width - tabValue, 0), fontValue.Height + 2);
                rectfValue = new RectangleF(pointValue, sizefValue);
                g.DrawString(sParam, fontParam, brushParam, pointParam);
                g.DrawLine(penDash, pointDash1, pointDash2);
                g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat);
                vPosition += fontValue.Height;

                //// Break Even
                //sParam = Language.T("Break Even");
                //sValue = strBreakEven;
                //pointParam = new PointF(fTabParam, iVPosition);
                //pointDash1 = new PointF(fTabDash, iVPosition + fontParam.Height / 2 + 2);
                //pointDash2 = new PointF(fTabDash + fDashWidth, iVPosition + fontParam.Height / 2 + 2);
                //pointValue = new PointF(fTabValue, iVPosition);
                //sizefValue = new SizeF(Math.Max(width - fTabValue, 0), fontValue.Height + 2);
                //rectfValue = new RectangleF(pointValue, sizefValue);
                //g.DrawString(sParam, fontParam, brushParam, pointParam);
                //g.DrawLine(penDash, pointDash1, pointDash2);
                //g.DrawString(sValue, fontValue, brushValue, rectfValue, stringFormat);
                //iVPosition += fontValue.Height + 2;
            }

            return;
        }