making a line?

Easiest and quickest way is to add a label control to your form, set its height to 1 or 2 pixels and then the width to however long you want it. By setting the borderstyle to 3D (but change it until you see the desired effect) you can have a line that looks just like that.

Alternatively create a custom control which you could then use to apply different line effects such as dashes, dotted lines etc..
 
stustarz said:
Easiest and quickest way is to add a label control to your form, set its height to 1 or 2 pixels and then the width to however long you want it. By setting the borderstyle to 3D (but change it until you see the desired effect) you can have a line that looks just like that.
I like this solution. :p
 
here's a quick and dirty line control I wrote a long time ago. feel free to use it.

Code:
/*
 * Copyright © 2003 NullFX Software
 * By: Steve Whitley
 * 
 * $Log: Line.cs,v $
 * 
 * */

namespace NullFX.Controls {
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Windows.Forms;
    [Designer(typeof(Line.LineDesigner))]
    public class Line : System.Windows.Forms.Control {
        internal class LineDesigner : System.Windows.Forms.Design.ControlDesigner {
            public override System.Windows.Forms.Design.SelectionRules SelectionRules {
                get {
                    return System.Windows.Forms.Design.SelectionRules.LeftSizeable |
                        System.Windows.Forms.Design.SelectionRules.RightSizeable |
                        System.Windows.Forms.Design.SelectionRules.Visible |
                        System.Windows.Forms.Design.SelectionRules.Moveable;
                }
            }

        }
        private System.Windows.Forms.FlatStyle _flatStyle;
        private Pen _systemPen;
        private System.ComponentModel.Container components = null;
        [Category("Appearance"), Description("Determines the display of the control when the users move the mouse over the control and click")]
        public System.Windows.Forms.FlatStyle FlatStyle {
            get{return _flatStyle;}
            set{
                _flatStyle = value;
                Invalidate();
            }
        }
        public Line() {
            _flatStyle = FlatStyle.Standard;
            _systemPen = new Pen(SystemColors.ControlDark, 2);
            SetStyle(ControlStyles.AllPaintingInWmPaint |
                ControlStyles.DoubleBuffer|
                ControlStyles.ResizeRedraw|
                ControlStyles.UserPaint, true);
        }
		 
        protected override void Dispose( bool disposing ) {
            if( disposing ) {
                if( components != null ) {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        protected override Size DefaultSize {
            get {
                return new System.Drawing.Size(32, 2);
            }
        } 
        protected override void OnPaint(PaintEventArgs pe) {
            switch(_flatStyle) { 
                case System.Windows.Forms.FlatStyle.Flat:
                case System.Windows.Forms.FlatStyle.Popup:
                case System.Windows.Forms.FlatStyle.Standard: {
                    pe.Graphics.FillRectangle(SystemBrushes.ControlLightLight, 0, 0, Width, 2);
                    pe.Graphics.FillRectangle(SystemBrushes.ControlDark, 0, 0, Width - 1, Height / 2); 
                }break;
                case System.Windows.Forms.FlatStyle.System: {
                    pe.Graphics.DrawLine(_systemPen, 0, 1, Width, 1);
                }break;
                default:
                    goto case System.Windows.Forms.FlatStyle.Standard; 
            }
        }
    }
}
 
ThienZ said:
can i make a line like this?

thx :)

The lines are from a groupbox inside another control (a panel or another groupbox). The location left setting is less than the container control and the size width is greater than the width of the container control.
 

Attachments

Back
Top