Esempio n. 1
0
        protected override void OnLayout(LayoutEventArgs levent)
        {
            base.OnLayout(levent);

            if (ClientRectangle.Width > 0 && ClientRectangle.Height > 0)
            {
                int offset = BorderColor.IsFullyTransparent() ? 0 : 2;
                int height = ClientRectangle.Height - offset * 2;
                checkbox.Visible  = ShowCheckBox;
                checkbox.Location = new Point(offset + 2, offset);
                checkbox.Size     = new Size(height, height);

                updown.Visible  = ShowUpDown;
                updown.Location = new Point(ClientRectangle.Width - ClientRectangle.Height - offset, offset);
                updown.Size     = new Size(height, height);

                calendaricon.Image = ExtendedControls.Properties.Resources.Calendar;
                //calendaricon.Image = DialogTest.Properties.Resources.Calendar;
                calendaricon.Location = new Point(ClientRectangle.Width - offset - calendaricon.Image.Width - 4, ClientRectangle.Height / 2 - calendaricon.Image.Height / 2);
                calendaricon.Size     = calendaricon.Image.Size;
                calendaricon.Visible  = !ShowUpDown;
                calendaricon.SizeMode = PictureBoxSizeMode.CenterImage;

                xstart = (showcheckbox ? (checkbox.Right + 2) : 2) + (BorderColor.IsFullyTransparent() ? 2 : 0);

                Recalc();   // cause anything might have changed, like fonts
            }
        }
Esempio n. 2
0
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            if (m.Msg == WM.PAINT)          // Stupid control does not have a OnPaint
            {
                if (!BorderColor.IsFullyTransparent())
                {
                    Graphics g = Parent.CreateGraphics();

                    Rectangle clientborder = new Rectangle(Location.X - BorderOffset, Location.Y - BorderOffset, ClientRectangle.Width + BorderOffset * 2, ClientRectangle.Height + BorderOffset * 2);

                    Color color1 = BorderColor;
                    Color color2 = BorderColor.Multiply(BorderColorScaling);

                    GraphicsPath g1 = RectCutCorners(clientborder.X + 1, clientborder.Y + 1, clientborder.Width - 2, clientborder.Height - 1, 1, 1);
                    using (Pen pc1 = new Pen(color1, 1.0F))
                        g.DrawPath(pc1, g1);

                    GraphicsPath g2 = RectCutCorners(clientborder.X, clientborder.Y, clientborder.Width, clientborder.Height - 1, 2, 2);
                    using (Pen pc2 = new Pen(color2, 1.0F))
                        g.DrawPath(pc2, g2);

                    g.Dispose();
                }
            }
        }
        protected override void OnLayout(LayoutEventArgs levent)
        {
            base.OnLayout(levent);

            if (ClientRectangle.Width > 0 && ClientRectangle.Height > 0)
            {
                int borderoffset = BorderColor.IsFullyTransparent() ? 0 : 2;
                int height       = ClientRectangle.Height - borderoffset * 2;
                checkbox.Visible  = ShowCheckBox;
                checkbox.Location = new Point(borderoffset + 2, borderoffset);
                checkbox.Size     = new Size(height, height);

                updown.Visible  = ShowUpDown;
                updown.Location = new Point(ClientRectangle.Width - ClientRectangle.Height - borderoffset, borderoffset);
                updown.Size     = new Size(height, height);

                Image ci = calendaricon.Image = ExtendedControls.Properties.Resources.Calendar;

                int caliconh = height - 4;
                int caliconw = (int)((float)caliconh / (float)ci.Height * ci.Width);

                calendaricon.Size     = new Size(caliconw, caliconh);
                calendaricon.Image    = ci;
                calendaricon.Location = new Point(ClientRectangle.Width - borderoffset - caliconw - 4, ClientRectangle.Height / 2 - caliconh / 2);
                calendaricon.SizeMode = PictureBoxSizeMode.StretchImage;
                calendaricon.Visible  = !ShowUpDown;

                xstart = (showcheckbox ? (checkbox.Right + 2) : 2) + (BorderColor.IsFullyTransparent() ? 2 : 0);

                Recalc();   // cause anything might have changed, like fonts
            }
        }
Esempio n. 4
0
        protected override void OnLayout(LayoutEventArgs levent)
        {
            base.OnLayout(levent);

            int bordersize = (!BorderColor.IsFullyTransparent()) ? 3 : 0;

            int treeviewclienth = ClientRectangle.Height - bordersize * 2;

            TreeView.Height = treeviewclienth;       // Set TreeView height so we can use VisibleCount

            SetScrollBarParameters();

            visibleonlayout = ScrollBar.IsScrollBarOn || DesignMode || !HideScrollBar;  // Hide must be on, or in design mode, or scroll bar is on due to values

            TreeView.Location = new Point(bordersize, bordersize);
            TreeView.Size     = new Size(ClientRectangle.Width - bordersize * 2, treeviewclienth);

            ScrollBar.Location = new Point(ClientRectangle.Width - ScrollBarWidth - bordersize, bordersize);
            ScrollBar.Size     = new Size(ScrollBarWidth, treeviewclienth);
            // we're letting the TreeView scroll itself, just hiding the default scroll bar under the themeable custom one when it's needed
            if (visibleonlayout)
            {
                ScrollBar.BringToFront();
            }
            else
            {
                TreeView.BringToFront();
            }
        }
        private void EstimateLines()
        {
            if (foundlineheight > 0)      // already done
            {
                return;
            }

            int bordersize     = (!BorderColor.IsFullyTransparent()) ? 3 : 0;
            int textboxclienth = ClientRectangle.Height - bordersize * 2;           // account for border

            if (Text.HasChars() && Text.Contains("\n"))                             // we need text to sense it
            {
                int sl = TextBox.GetCharIndexFromPosition(new Point(0, 0));
                sl = TextBox.GetLineFromCharIndex(sl);
                for (int i = 1; i < ClientRectangle.Height; i++)
                {
                    int nl = TextBox.GetCharIndexFromPosition(new Point(0, i));     // look to see when line changes.. it may not if only one line
                    nl = TextBox.GetLineFromCharIndex(nl);
                    if (sl != nl)
                    {
                        foundlineheight = i;
                        visiblelines    = textboxclienth / i;                       // gotcha..
                        //System.Diagnostics.Debug.WriteLine("Found line h " + i + " giving " + visiblelines + " " + ((float)textboxclienth / i));
                        return;
                    }
                }
            }

            visiblelines = textboxclienth / (int)(Font.GetHeight() + 1);            // basic estimate
        }
Esempio n. 6
0
        protected override void OnLayout(LayoutEventArgs levent)
        {
            base.OnLayout(levent);

            int bordersize = (!BorderColor.IsFullyTransparent()) ? 3 : 0;

            int textboxclienth = ClientRectangle.Height - bordersize * 2;       // border is within Client area
            int linesinbox     = EstimateLinesInBox(textboxclienth);

            int firstVisibleLine = unchecked ((int)(long)TextBox.SendMessage(EM.GETFIRSTVISIBLELINE, IntPtr.Zero, IntPtr.Zero));

            ScrollBar.SetValueMaximumLargeChange(firstVisibleLine, LineCount - 1, linesinbox);

            visibleonlayout = ScrollBar.IsScrollBarOn || DesignMode || !HideScrollBar;  // Hide must be on, or in design mode, or scroll bar is on due to values

            TextBox.Location = new Point(bordersize, bordersize);
            TextBox.Size     = new Size(ClientRectangle.Width - (visibleonlayout ? ScrollBarWidth : 0) - bordersize * 2, textboxclienth);

            //System.Diagnostics.Debug.WriteLine("text box size " + textboxclienth + " Lines " + linesinbox );

            ScrollBar.Location = new Point(ClientRectangle.Width - ScrollBarWidth - bordersize, bordersize);
            ScrollBar.Size     = new Size(ScrollBarWidth, textboxclienth);

            //System.Diagnostics.Debug.WriteLine("layout Scroll State Lines: " + LineCount + " FVL: " + firstVisibleLine + " textlines " + textboxlinesestimate);
        }
        // NOT IN USE
        #region Icon Replacement
        public void ReplaceIconsNOTINUSE(Func <string, Image> getIcon)
        {
            calendaricon.Image = getIcon("CalendarIcon");
            int offset = BorderColor.IsFullyTransparent() ? 0 : 2;

            calendaricon.Location = new Point(ClientRectangle.Width - offset - calendaricon.Image.Width - 4, ClientRectangle.Height / 2 - calendaricon.Image.Height / 2);
            calendaricon.Size     = calendaricon.Image.Size;
        }
        public int EstimateVerticalSizeFromText()
        {
            int lastselpos   = this.Text.Length;
            int numberlines  = (lastselpos >= 0) ? (TextBox.GetLineFromCharIndex(lastselpos) + 1) : 0;
            int bordersize   = (!BorderColor.IsFullyTransparent()) ? 3 : 0;
            int neededpixels = (int)(FontPixels() * numberlines) + bordersize * 2 + 4;      // 4 extra for border area of this (bounds-client rect)

            return(neededpixels);
        }
Esempio n. 9
0
        public int EstimateVerticalSizeFromText()
        {
            int    numberlines = TextBox.Lines.Count();
            int    bordersize  = (!BorderColor.IsFullyTransparent()) ? 3 : 0;
            double fonth       = GetRealFontHeight();
            int    pixels      = (int)(fonth * numberlines) + bordersize * 2 + 4; // 4 extra for border area of this (bounds-client rect)

            //System.Diagnostics.Debug.WriteLine("Est Box " + numberlines + " " + bordersize + " " + fonth + " " + pixels + " " );
            return(pixels);
        }
Esempio n. 10
0
        public int CalcVisibleLines(int height)
        {
            int   bordersize     = (!BorderColor.IsFullyTransparent()) ? 3 : 0;
            int   textboxclienth = height - bordersize * 2;
            float fh             = FontPixels();
            float fvs            = (float)textboxclienth / fh;

            //System.Diagnostics.Debug.WriteLine("Visible lines " + ((int)fvs) + " h " + textboxclienth + " fract " + fvs);
            return((int)fvs);
        }
Esempio n. 11
0
        public int EstimateVerticalSizeFromText()
        {
            int lastselpos   = this.Text.Length;
            int numberlines  = (lastselpos >= 0) ? (TextBox.GetLineFromCharIndex(lastselpos) + 1) : 0;
            int bordersize   = (!BorderColor.IsFullyTransparent()) ? 3 : 0;
            int lineh        = foundlineheight > 0 ? foundlineheight : (int)(Font.GetHeight() + 2); // if we have an estimate, use it, else use Font Height
            int neededpixels = (int)(lineh * numberlines) + bordersize * 2 + 4;                     // 4 extra for border area of this (bounds-client rect)

            return(neededpixels);
        }
Esempio n. 12
0
        private void CalculateLayout()
        {
            bordersize = 0;

            if (FlatStyle != FlatStyle.System && !BorderColor.IsFullyTransparent())
            {
                bordersize = 2;
            }

            int items = (Items != null) ? Items.Count() : 0;

            itemslayoutestimatedon = items;

            fontusedforestimate = Font;

            itemheight       = (int)Font.GetHeight() + 2;
            lbsys.ItemHeight = itemheight;

            displayableitems = (ClientRectangle.Height - bordersize * 2) / itemheight;            // number of items to display

            if (items > 0 && displayableitems > items)
            {
                displayableitems = items;
            }

            mainarea = new Rectangle(bordersize, bordersize,
                                     ClientRectangle.Width - bordersize * 2,
                                     (FitToItemsHeight) ? (displayableitems * itemheight) : (ClientRectangle.Height - bordersize * 2));
            borderrect = mainarea;
            borderrect.Inflate(bordersize, bordersize);
            borderrect.Width--; borderrect.Height--;        // adjust to rect not area.

            //System.Diagnostics.Debug.WriteLine("List box" + mainarea + " " + items + "  " + displayableitems);

            if (items > displayableitems)
            {
                vScrollBar.Location  = new Point(mainarea.Right - ScrollBarWidth, mainarea.Y);
                mainarea.Width      -= ScrollBarWidth;
                vScrollBar.Size      = new Size(ScrollBarWidth, mainarea.Height);
                vScrollBar.Minimum   = 0;
                vScrollBar.Maximum   = Items.Count - displayableitems;
                vScrollBar.Visible   = true;
                vScrollBar.FlatStyle = FlatStyle;

                vScrollBar.SliderColor             = ScrollBarColor;
                vScrollBar.BackColor               = ScrollBarColor;
                vScrollBar.BorderColor             = vScrollBar.ThumbBorderColor = vScrollBar.ArrowBorderColor = BorderColor;
                vScrollBar.ArrowButtonColor        = vScrollBar.ThumbButtonColor = ScrollBarButtonColor;
                vScrollBar.MouseOverButtonColor    = ScrollBarButtonColor.Multiply(1.4F);
                vScrollBar.MousePressedButtonColor = ScrollBarButtonColor.Multiply(1.5F);
                vScrollBar.ForeColor               = ScrollBarButtonColor.Multiply(0.25F);
            }
        }
Esempio n. 13
0
        protected override void OnLayout(LayoutEventArgs levent)
        {
            base.OnLayout(levent);

            int bordersize     = (!BorderColor.IsFullyTransparent()) ? 3 : 0;
            int textboxclienth = ClientRectangle.Height - bordersize * 2;

            scrollbarvisibleonlayout = ScrollBar.IsScrollBarOn || DesignMode || !HideScrollBar;  // Hide must be on, or in design mode, or scroll bar is on due to values

            TextBox.Location = new Point(bordersize, bordersize);
            TextBox.Size     = new Size(ClientRectangle.Width - (scrollbarvisibleonlayout ? ScrollBarWidth : 0) - bordersize * 2, textboxclienth);

            ScrollBar.Location = new Point(ClientRectangle.Width - ScrollBarWidth - bordersize, bordersize);
            ScrollBar.Size     = new Size(ScrollBarWidth, textboxclienth);
        }
Esempio n. 14
0
        protected override void OnLayout(LayoutEventArgs levent)
        {
            base.OnLayout(levent);

            tb.AutoSize = autosize;

            if (ClientRectangle.Width > 0 && ClientRectangle.Height > 0)
            {
                int bordersize = (!BorderColor.IsFullyTransparent()) ? 3 : 0;

                tb.Location = new Point(bordersize, bordersize);
                tb.Size     = new Size(ClientRectangle.Width - SpinnerSize - bordersize * 2, ClientRectangle.Height - bordersize * 2);

                updown.Location = new Point(ClientRectangle.Width - SpinnerSize - bordersize, bordersize);
                updown.Size     = new Size(SpinnerSize, tb.Height);
            }
        }
Esempio n. 15
0
        private void UpdateScrollBar()            // from the richtext, set the scroll bar
        {
            int bordersize     = (!BorderColor.IsFullyTransparent()) ? 3 : 0;
            int textboxclienth = ClientRectangle.Height - bordersize * 2;
            int linesinbox     = EstimateLinesInBox(textboxclienth);

            int firstVisibleLine = unchecked ((int)(long)TextBox.SendMessage(EM.GETFIRSTVISIBLELINE, IntPtr.Zero, IntPtr.Zero));

            //System.Diagnostics.Debug.WriteLine("Scroll State Lines: " + LineCount+ " FVL: " + firstVisibleLine + " textlines " + textboxlinesestimate);

            ScrollBar.SetValueMaximumLargeChange(firstVisibleLine, LineCount - 1, linesinbox);

            if (ScrollBar.IsScrollBarOn != visibleonlayout)     // need to relayout if scroll bars pop on
            {
                PerformLayout();
            }
        }
Esempio n. 16
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle drawarea = ClientRectangle;

            if (!BorderColor.IsFullyTransparent())
            {
                e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;

                Color color1 = BorderColor;
                Color color2 = BorderColor.Multiply(BorderColorScaling);

                using (GraphicsPath g1 = ControlHelpersStaticFunc.RectCutCorners(1, 1, ClientRectangle.Width - 2, ClientRectangle.Height - 1, 1, 1))
                    using (Pen pc1 = new Pen(color1, 1.0F))
                        e.Graphics.DrawPath(pc1, g1);

                using (GraphicsPath g2 = ControlHelpersStaticFunc.RectCutCorners(0, 0, ClientRectangle.Width, ClientRectangle.Height - 1, 2, 2))
                    using (Pen pc2 = new Pen(color2, 1.0F))
                        e.Graphics.DrawPath(pc2, g2);

                drawarea.Inflate(-2, -2);
            }

            using (Brush br = new SolidBrush(this.TextBackColor))
                e.Graphics.FillRectangle(br, drawarea);

            using (Brush textb = new SolidBrush(this.ForeColor))
            {
                for (int i = 0; i < partlist.Count; i++)
                {
                    Parts p = partlist[i];

                    string t = (p.ptype == PartsTypes.Text) ? p.maxstring : datetimevalue.ToString(p.format);

                    if (i == selectedpart)
                    {
                        using (Brush br = new SolidBrush(this.SelectedColor))
                            e.Graphics.FillRectangle(br, new Rectangle(p.xpos + xstart, drawarea.Y, p.endx - p.xpos, drawarea.Height));
                    }

                    e.Graphics.DrawString(t, this.Font, textb, new Point(p.xpos + xstart, drawarea.Y + 2));
                }
            }
        }
Esempio n. 17
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (!BorderColor.IsFullyTransparent())
            {
                e.Graphics.SmoothingMode = SmoothingMode.Default;

                Color color1 = BorderColor;
                Color color2 = BorderColor.Multiply(BorderColorScaling);

                GraphicsPath g1 = ControlHelpersStaticFunc.RectCutCorners(1, 1, ClientRectangle.Width - 2, ClientRectangle.Height - 1, 1, 1);
                using (Pen pc1 = new Pen(color1, 1.0F))
                    e.Graphics.DrawPath(pc1, g1);

                GraphicsPath g2 = ControlHelpersStaticFunc.RectCutCorners(0, 0, ClientRectangle.Width, ClientRectangle.Height - 1, 2, 2);
                using (Pen pc2 = new Pen(color2, 1.0F))
                    e.Graphics.DrawPath(pc2, g2);
            }
        }
Esempio n. 18
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (!BorderColor.IsFullyTransparent())
            {
                e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;

                Color color1 = BorderColor;
                Color color2 = BorderColor.Multiply(BorderColorScaling);

                int hg = tb.Height + 6;
                using (GraphicsPath g1 = RectCutCorners(1, 1, ClientRectangle.Width - 2, hg - 1, 1, 1))
                    using (Pen pc1 = new Pen(color1, 1.0F))
                        e.Graphics.DrawPath(pc1, g1);

                using (GraphicsPath g2 = RectCutCorners(0, 0, ClientRectangle.Width, hg - 1, 2, 2))
                    using (Pen pc2 = new Pen(color2, 1.0F))
                        e.Graphics.DrawPath(pc2, g2);
            }
        }
Esempio n. 19
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (FlatStyle == FlatStyle.System || FlatStyle == FlatStyle.Standard)
            {
                base.OnPaint(e);
            }
            else if (DisplayRectangle.Width > 0 && DisplayRectangle.Height > 0)   // Popup and Flat are ours, as long as its got size
            {
                int topline = DisplayRectangle.Y / 2;

                Color colorback = BackColor;

                if (!colorback.IsFullyTransparent())
                {
                    Color color2 = (FlatStyle == FlatStyle.Popup) ? colorback.Multiply(BackColorScaling) : BackColor;

                    Rectangle borderrect = ClientRectangle;

                    using (Brush b = new System.Drawing.Drawing2D.LinearGradientBrush(borderrect, colorback, color2, 90))
                        e.Graphics.FillRectangle(b, borderrect);
                }

                if (!BorderColor.IsFullyTransparent())
                {
                    Color color1 = BorderColor;
                    Color color2 = BorderColor.Multiply(BorderColorScaling);

                    int textlength = 0;
                    if (this.Text != "")
                    {           // +1 for rounding down..
                        textlength = (int)e.Graphics.MeasureString(this.Text, this.Font).Width + TextPadding * 2 + 1;
                    }

                    int textstart = TextStartPosition;
                    if (textstart == 0)                                          // auto centre
                    {
                        textstart = ClientRectangle.Width / 2 - textlength / 2;  // centre
                    }
                    else if (textstart == -1)                                    // left
                    {
                        textstart = 15;
                    }
                    else if (textstart == 1)                                          // right
                    {
                        textstart = ClientRectangle.Width - 15 - textlength;
                    }

                    if (textstart < 4)                                          // need 4 pixels
                    {
                        textstart = 4;
                    }

                    e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;

                    using (GraphicsPath g1 = ControlHelpersStaticFunc.RectCutCorners(1, topline + 1, ClientRectangle.Width - 2, ClientRectangle.Height - topline - 1, 1, 1, textstart - 1, textlength))
                        using (Pen pc1 = new Pen(color1, 1.0F))
                            e.Graphics.DrawPath(pc1, g1);

                    using (GraphicsPath g2 = ControlHelpersStaticFunc.RectCutCorners(0, topline, ClientRectangle.Width, ClientRectangle.Height - topline - 1, 2, 2, textstart, textlength))
                        using (Pen pc2 = new Pen(color2, 1.0F))
                            e.Graphics.DrawPath(pc2, g2);

                    if (textlength > 0)
                    {
                        e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

                        int twidth = ClientRectangle.Width - textstart - 4;            // What size have we left..
                        twidth = (textlength < twidth) ? textlength: twidth;           // clip
                        Rectangle textarea = new Rectangle(textstart, 0, twidth, DisplayRectangle.Y);

                        using (Brush textb = new SolidBrush(this.ForeColor))
                            using (StringFormat fmt = new StringFormat()
                            {
                                Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                            })
                            {
                                e.Graphics.DrawString(this.Text, this.Font, textb, textarea, fmt);
                            }

                        e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
                    }
                }
            }
        }