コード例 #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (target == null)
            {
                return;
            }

            Point car = PointToClient(target.PointToScreen(target.PlaceToPoint(target.Selection.Start)));

            Size fontSize = TextRenderer.MeasureText("W", Font);

            int column = 0;

            e.Graphics.FillRectangle(new LinearGradientBrush(new Rectangle(0, 0, Width, Height), BackColor, BackColor2, 270), new Rectangle(0, 0, Width, Height));

            float columnWidth = target.CharWidth;
            var   sf          = new StringFormat();

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Near;

            var zeroPoint = target.PositionToPoint(0);

            zeroPoint = PointToClient(target.PointToScreen(zeroPoint));

            using (var pen = new Pen(TickColor))
                using (var textBrush = new SolidBrush(ForeColor))
                {
                    for (float x = zeroPoint.X; x < Right; x += columnWidth, ++column)
                    {
                        if (column % 10 == 0)
                        {
                            e.Graphics.DrawString(column.ToString(), Font, textBrush, x, 0f, sf);
                        }

                        e.Graphics.DrawLine(pen, (int)x, fontSize.Height + (column % 5 == 0 ? 1 : 3), (int)x, Height - 4);
                    }
                }

            using (var pen = new Pen(TickColor))
            {
                e.Graphics.DrawLine(pen, new Point(car.X - 3, Height - 3), new Point(car.X + 3, Height - 3));
            }

            using (var pen = new Pen(CaretTickColor))
            {
                e.Graphics.DrawLine(pen, new Point(car.X - 2, fontSize.Height + 3), new Point(car.X - 2, Height - 4));
                e.Graphics.DrawLine(pen, new Point(car.X, fontSize.Height + 1), new Point(car.X, Height - 4));
                e.Graphics.DrawLine(pen, new Point(car.X + 2, fontSize.Height + 3), new Point(car.X + 2, Height - 4));
            }
        }
コード例 #2
0
 private void UpdateLocation()
 {
     if (null != tb)
     {
         int x = tb.Width - this.Width - 20;
         this.Location = tb.PointToScreen(new Point(x, 0));
     }
 }
コード例 #3
0
        internal void DoAutocomplete(bool forced)
        {
            if (!Menu.Enabled)
            {
                Menu.Close();
                return;
            }

            visibleItems.Clear();
            FocussedItemIndex    = 0;
            VerticalScroll.Value = 0;
            //some magic for update scrolls
            AutoScrollMinSize += new Size(1, 0);
            AutoScrollMinSize -= new Size(1, 0);
            //get fragment around caret
            Range  fragment = tb.Selection.GetFragment(Menu.SearchPattern);
            string text     = fragment.Text;
            //calc screen point for popup menu
            Point point  = tb.PlaceToPoint(fragment.End);
            Point offset = tb.PointToScreen(point);

            point = AutocompleteParent.PointToClient(offset);
            point.Offset(2, tb.CharHeight);
            //
            bool foundSelected = false;

            if (forced || (text.Length >= Menu.MinFragmentLength &&
                           tb.Selection.IsEmpty && /*pops up only if selected range is empty*/
                           (tb.Selection.Start > fragment.Start || text.Length == 0 /*pops up only if caret is after first letter*/)))
            {
                Menu.Fragment = fragment;
                //build popup menu
                foreach (var item in sourceItems)
                {
                    item.Parent = Menu;
                    CompareResult res = item.Compare(text);
                    if (res != CompareResult.Hidden)
                    {
                        visibleItems.Add(item);
                    }
                    if (res == CompareResult.VisibleAndSelected && !foundSelected)
                    {
                        foundSelected     = true;
                        FocussedItemIndex = visibleItems.Count - 1;
                    }
                }
            }

            //show popup menu
            if (Count > 0)
            {
                CancelEventArgs args = new CancelEventArgs();
                Menu.OnOpening(args);
                if (!args.Cancel)
                {
                    Menu.Location = point;
                    Menu.Parent   = AutocompleteParent;

                    if (foundSelected)
                    {
                        AdjustScroll();
                        DoSelectedVisible();
                    }

                    Menu.Show();
                    Menu.BringToFront();
                }
                Menu.Invalidate();
                Invalidate();
            }
            else
            {
                Menu.Close();
            }
        }