private void LayoutHint(Hint hint) { if (hint.Inline) { if (hint.Range.Start.iLine < tb.LineInfos.Count - 1) { hint.HostPanel.Top = tb.LineInfos[hint.Range.Start.iLine + 1].startY - hint.TopPadding - hint.HostPanel.Height - tb.VerticalScroll.Value; } else { hint.HostPanel.Top = tb.TextHeight + tb.Paddings.Top - hint.HostPanel.Height - tb.VerticalScroll.Value; } } else { if (hint.Range.Start.iLine > tb.LinesCount - 1) { return; } if (hint.Range.Start.iLine == tb.LinesCount - 1) { var y = tb.LineInfos[hint.Range.Start.iLine].startY - tb.VerticalScroll.Value + tb.CharHeight; if (y + hint.HostPanel.Height + 1 > tb.ClientRectangle.Bottom) { hint.HostPanel.Top = Math.Max(0, tb.LineInfos[hint.Range.Start.iLine].startY - tb.VerticalScroll.Value - hint.HostPanel.Height); } else { hint.HostPanel.Top = y; } } else { hint.HostPanel.Top = tb.LineInfos[hint.Range.Start.iLine + 1].startY - tb.VerticalScroll.Value; if (hint.HostPanel.Bottom > tb.ClientRectangle.Bottom) { hint.HostPanel.Top = tb.LineInfos[hint.Range.Start.iLine + 1].startY - tb.CharHeight - hint.TopPadding - hint.HostPanel.Height - tb.VerticalScroll.Value; } } } if (hint.Dock == DockStyle.Fill) { hint.Width = tb.ClientSize.Width - tb.LeftIndent - 2; hint.HostPanel.Left = tb.LeftIndent; } else { var p1 = tb.PlaceToPoint(hint.Range.Start); var p2 = tb.PlaceToPoint(hint.Range.End); var cx = (p1.X + p2.X) / 2; var x = cx - hint.HostPanel.Width / 2; hint.HostPanel.Left = Math.Max(tb.LeftIndent, x); if (hint.HostPanel.Right > tb.ClientSize.Width) { hint.HostPanel.Left = Math.Max(tb.LeftIndent, x - (hint.HostPanel.Right - tb.ClientSize.Width)); } } }
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)); } }
protected override void OnPaint(PaintEventArgs e) { if (target == null) { return; } var zoom = this.Scale * 100 / target.Zoom; if (zoom <= float.Epsilon) { return; } //calc startPlace var r = target.VisibleRange; if (startPlace.iLine > r.Start.iLine) { startPlace.iLine = r.Start.iLine; } else { var endP = target.PlaceToPoint(r.End); endP.Offset(0, -(int)(ClientSize.Height / zoom) + target.CharHeight); var pp = target.PointToPlace(endP); if (pp.iLine > startPlace.iLine) { startPlace.iLine = pp.iLine; } } startPlace.iChar = 0; //calc scroll pos var linesCount = target.Lines.Count; var sp1 = (float)r.Start.iLine / linesCount; var sp2 = (float)r.End.iLine / linesCount; //scale graphics e.Graphics.ScaleTransform(zoom, zoom); //draw text var size = new SizeF(ClientSize.Width / zoom, ClientSize.Height / zoom); target.DrawText(e.Graphics, startPlace, size.ToSize()); //draw visible rect var p0 = target.PlaceToPoint(startPlace); var p1 = target.PlaceToPoint(r.Start); var p2 = target.PlaceToPoint(r.End); var y1 = p1.Y - p0.Y; var y2 = p2.Y + target.CharHeight - p0.Y; e.Graphics.SmoothingMode = SmoothingMode.HighQuality; using (var brush = new SolidBrush(Color.FromArgb(50, ForeColor))) using (var pen = new Pen(brush, 1 / zoom)) { var rect = new Rectangle(0, y1, (int)((ClientSize.Width - 1) / zoom), y2 - y1); e.Graphics.FillRectangle(brush, rect); e.Graphics.DrawRectangle(pen, rect); } //draw scrollbar if (scrollbarVisible) { e.Graphics.ResetTransform(); e.Graphics.SmoothingMode = SmoothingMode.None; using (var brush = new SolidBrush(Color.FromArgb(200, ForeColor))) { var rect = new RectangleF(ClientSize.Width - 3, ClientSize.Height * sp1, 2, ClientSize.Height * (sp2 - sp1)); e.Graphics.FillRectangle(brush, rect); } } needRepaint = false; }
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(2, tb.CharHeight); // 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; bool foundSelected = false; //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; } } if (foundSelected) { AdjustScroll(); DoSelectedVisible(); } } //show popup menu if (Count > 0) { if (!Menu.Visible) { CancelEventArgs args = new CancelEventArgs(); Menu.OnOpening(args); if (!args.Cancel) { Menu.Show(tb, point); } } DoSelectedVisible(); Invalidate(); } else { Menu.Close(); } }