Create strings as windows with visual studio 2010?

I wonder if it is possible to add a line to the design in the form of a window? I can not find the tool for this in the toolbar? Or is there another way to do this in visual studio or in code?

+4
source share
2 answers

There is no built-in control for WinForms. You can use the GroupBox control, but set the Text property to an empty string and set the height to 2 . This will simulate an embossed line. Otherwise, you need to create your own control and draw a line yourself.

For a user control, an example is given here.

 using System.ComponentModel; using System.Drawing; using System.Windows.Forms; namespace WindowsFormsApplication12 { public partial class Line : Control { public Line() { InitializeComponent(); } private Color m_LineColor = Color.Black; /// <summary> /// Gets or sets the color of the divider line /// </summary> [Category("Appearance")] [Description("Gets or sets the color of the divider line")] public Color LineColor { get { return m_LineColor; } set { m_LineColor = value; Invalidate(); } } protected override void OnPaint(PaintEventArgs pe) { using (SolidBrush brush = new SolidBrush(LineColor)) { pe.Graphics.FillRectangle(brush, pe.ClipRectangle); } } } } 

It simply fills the ClientRectangle specified LineColor , so the height and width of the line is the control itself. Set accordingly.

+11
source
 public void DrawLShapeLine(System.Drawing.Graphics g, int intMarginLeft, int intMarginTop, int intWidth, int intHeight) { Pen myPen = new Pen(Color.Black); myPen.Width = 2; // Create array of points that define lines to draw. int marginleft = intMarginLeft; int marginTop = intMarginTop; int width = intWidth; int height = intHeight; int arrowSize = 3; Point[] points = { new Point(marginleft, marginTop), new Point(marginleft, height + marginTop), new Point(marginleft + width, marginTop + height), // Arrow new Point(marginleft + width - arrowSize, marginTop + height - arrowSize), new Point(marginleft + width - arrowSize, marginTop + height + arrowSize), new Point(marginleft + width, marginTop + height) }; g.DrawLines(myPen, points); } private void Form1_Paint(object sender, PaintEventArgs e) { DrawLShapeLine(e.Graphics, 10, 10, 20, 40); } 

See the following link for more information. Drawing a string in Winforms

0
source

All Articles