...
Rectangle r = GetTextBounds(textBox1, 2, 10);
Panel panel = new Panel
{
Bounds = r,
BorderStyle = BorderStyle.FixedSingle,
};
this.Controls.Add(panel);
panel.Show();
panel.BringToFront();
...
private Rectangle GetTextBounds(TextBox textBox, int startPosition, int length)
{
using (Graphics g = textBox.CreateGraphics())
{
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
CharacterRange[] characterRanges = { new CharacterRange(startPosition, length) };
StringFormat stringFormat = new StringFormat(StringFormat.GenericTypographic);
stringFormat.SetMeasurableCharacterRanges(characterRanges);
Region region = g.MeasureCharacterRanges(textBox.Text, textBox.Font,
textBox.Bounds, stringFormat)[0];
Rectangle bounds = Rectangle.Round(region.GetBounds(g));
Point textOffset = textBox.GetPositionFromCharIndex(0);
return new Rectangle(textBox.Margin.Left + bounds.Left + textOffset.X,
textBox.Margin.Top + textBox.Location.Y + textOffset.Y,
bounds.Width, bounds.Height);
}
}
Code Example |
---|
Csharp :: population of the world |
Csharp :: git set origin url |
Html :: trademark symbol |
Html :: html space |
Html :: how to use unsplash images in html |
Html :: how to link css to html |
Html :: enter key vue |
Html :: how open link in new tab |
Html :: starting html |
Html :: font awesome linkedin |
Html :: html input not editable |
Html :: Add Random Image from Web in html |
Html :: editable div |
Html :: meta colors html |
Html :: where to use .target command in html |
Html :: add favicon to html |
Html :: button open link in new tab |
Html :: submit form on change |
Html :: input datetime |
Html :: icons burger css font awesome |
Html :: how to create a page break html |
Html :: textarea placeholder |
Html :: make a basic html page |
Html :: bootstrap table hover |
Html :: min length input html |
Html :: Insert fav icon to head tag |
Html :: how to put autoplay music in the background of the page html |
Html :: vue js focus ref |
Html :: bootstrap href button |
Html :: how to hide display in bootstrap |