C # Analysis of Development and Application Instances of draw line controls

Source: Internet
Author: User

Before introducing the application example of the C # Draw line control, we need to understand that there is no draw Line Control in C #. Here we have written one for you to share. There are two controls that draw a horizontal line and a vertical line respectively. You can share with us about how to draw a diagonal line.

C # horizontal line of the draw Line Control

Using system;

Using system. collections;

Using system. componentmodel;

Using system. drawing;

Using system. Data;

Using system. Windows. forms;

 

Namespace Jiashi. wincontrols

{

///

/// LinEx

///

Public class LinEx: system. Windows. Forms. usercontrol

{

 

# Region attribute Definition

Private system. Drawing. Color linecolor;

Private int linewidth;

///

/// Color attribute of the line

///

Public System. Drawing. Color linecolor

{

Set

{

This. linecolor = value;

System. Windows. Forms. painteventargs Ep =

New painteventargs (this. creategraphics (),

This. clientrectangle );

This. linex_paint (this, EP );

}

Get {return this. linecolor ;}

}

///

/// Line width

///

Public int linewidth

{

Set

{

This. linewidth = value;

System. Windows. Forms. painteventargs Ep =

New painteventargs (this. creategraphics (),

This. clientrectangle );

This. linex_paint (this, EP );

}

Get {return this. linewidth ;}

}

# Endregion

Private system. componentmodel. Container components = NULL;

 

///

/// The initial color and line width of the constructor

///

Public LinEx ()

{

Initializecomponent ();

This. linecolor = This. forecolor;

This. linewidth = 1;

 

}

 

///

/// Clear all resources in use.

///

Protected override void dispose (bool disposing)

{

If (disposing)

{

If (components! = NULL)

{

Components. Dispose ();

}

}

Base. Dispose (disposing );

}

 

# Code generated by the region component designer

///

/// The designer supports the required methods-do not use the code editor

/// Modify the content of this method.

///

Private void initializecomponent ()

{

//

// LinEx

//

This. Name = "LinEx ";

This. Resize + = new system. eventhandler (this. linex_resize );

This. Paint + =

New system. Windows. Forms. painteventhandler (this. linex_paint );

 

}

# Endregion

 

Private void linex_paint (Object sender,

System. Windows. Forms. painteventargs E)

{

Graphics G = E. graphics;

Pen mypen = new pen (this. linecolor );

Mypen. width = This. linewidth * 2;

This. Height = This. linewidth;

G. drawline (mypen, 0, 0, E. cliprectangle. Right, 0 );

}

 

Private void linex_resize (Object sender, system. eventargs E)

{

This. Height = This. linewidth;

}

}

}

C # vertical line of the draw Line Control

Using system;

Using system. collections;

Using system. componentmodel;

Using system. drawing;

Using system. Data;

Using system. Windows. forms;

 

Namespace Jiashi. wincontrols

{

///

/// Liney draws a vertical bar Control

///

Public class Liney: system. Windows. Forms. usercontrol

{

 

# Region attribute Definition

Private system. Drawing. Color linecolor;

Private int linewidth;

///

/// Color attribute of the line

///

Public System. Drawing. Color linecolor

{

Set

{

This. linecolor = value;

System. Windows. Forms. painteventargs Ep =

New painteventargs (this. creategraphics (),

This. clientrectangle );

This. liney_paint (this, EP );

}

Get {return this. linecolor ;}

}

///

/// Line width

///

Public int linewidth

{

Set

{

This. linewidth = value;

System. Windows. Forms. painteventargs Ep =

New painteventargs (this. creategraphics (),

This. clientrectangle );

This. liney_paint (this, EP );

}

Get {return this. linewidth ;}

}

# Endregion

Private system. componentmodel. Container components = NULL;

 

///

/// The initial color and line width of the constructor

///

Public Liney ()

{

Initializecomponent ();

This. linecolor = This. forecolor;

This. linewidth = 1;

 

}

 

///

/// Clear all resources in use.

///

Protected override void dispose (bool disposing)

{

If (disposing)

{

If (components! = NULL)

{

Components. Dispose ();

}

}

Base. Dispose (disposing );

}

 

# Code generated by the region component designer

///

/// The designer supports the required methods-do not use the code editor

/// Modify the content of this method.

///

Private void initializecomponent ()

{

//

// Liney

//

This. Name = "Liney ";

This. Resize + =

New system. eventhandler (this. liney_resize );

This. Paint + =

New system. Windows. Forms. painteventhandler (this. liney_paint );

 

}

# Endregion

 

Private void liney_paint (

Object sender, system. Windows. Forms. painteventargs E)

{

Graphics G = E. graphics;

Pen mypen = new pen (this. linecolor );

Mypen. width = This. linewidth * 2;

This. width = This. linewidth;

G. drawline (mypen, 0, 0, 0, E. cliprectangle. Bottom );

}

 

Private void liney_resize (

Object sender, system. eventargs E)

{

This. width = This. linewidth;

}

}

}

The development of the C # Draw line control will introduce you here, hoping to help you understand and learn the C # Draw line control.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.