c# Onpaint事件
下面是我做的一个控件,在控件调试时,如果改变backcolor值时老是显示属性值无效。就是找不到原因,请问问题出在哪里?谢谢usingSystem;usingSystem...
下面是我做的一个控件,在控件调试时,如果改变backcolor值时老是显示属性值无效。就是找不到原因,请问问题出在哪里?谢谢
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ControlLib
{
public partial class Line : UserControl
{
private float penWidth;
private Color penColor;
public Line()
{
InitializeComponent();
penWidth = 1;
penColor = Color.Black;
}
//public float lineWidth
//{
// get
// {
// return penWidth;
// }
// set
// {
// penWidth=value;
// }
//}
//public Color lineColor
//{
// get
// {
// return penColor;
// }
// set
// {
// penColor=value;
// }
//}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen colorPen = new Pen(this.BackColor, penWidth);
g.DrawLine(colorPen, new Point(0, 0), new Point(this.Width, this.Height));
}
private void Line_Resize(object sender, EventArgs e)
{
OnPaint(null);
}
private void Line_BackColorChanged_1(object sender, EventArgs e)
{
OnPaint(null);
}
}
} 展开
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ControlLib
{
public partial class Line : UserControl
{
private float penWidth;
private Color penColor;
public Line()
{
InitializeComponent();
penWidth = 1;
penColor = Color.Black;
}
//public float lineWidth
//{
// get
// {
// return penWidth;
// }
// set
// {
// penWidth=value;
// }
//}
//public Color lineColor
//{
// get
// {
// return penColor;
// }
// set
// {
// penColor=value;
// }
//}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen colorPen = new Pen(this.BackColor, penWidth);
g.DrawLine(colorPen, new Point(0, 0), new Point(this.Width, this.Height));
}
private void Line_Resize(object sender, EventArgs e)
{
OnPaint(null);
}
private void Line_BackColorChanged_1(object sender, EventArgs e)
{
OnPaint(null);
}
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询