C# 控件绘制

绘制方法:

1.在控件的paint事件中绘制

2.绘制成图片,然后作为背景图或图片贴到工作区。

Bitmap bmp = new Bitmap(IWidth, this.Height);
Graphics g = Graphics.FromImage(bmp);

....

最后调用即可

this.BackgroundImage = I_Paint();

 

添加功能:

1.绘制时,添加相应的坐标区域,放到全局字典中,字典中包含区域、热点名称等。

2.在整个组件上添加MouseMove事件,鼠标经过时判断字典中是否包含该区域

....

3.可以添加相应的委托

...

 

文本位置:

StringFormat sFormat = new StringFormat();
sFormat.Alignment = StringAlignment.Far;
sFormat.LineAlignment = StringAlignment.Center;

g.DrawString(strText, drawFont,_Brush , drawRectangle, sFormat);

 

取消锯齿:

g.SmoothingMode = SmoothingMode.AntiAlias; //使绘图质量最高,即消除锯齿
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.CompositingQuality = CompositingQuality.HighQuality;

 

边框绘制:

ControlPaint.DrawBorder(this.CreateGraphics(), this.ClientRectangle,
ColorTranslator.FromHtml("#D1D4D4"), 0, ButtonBorderStyle.Solid, //左边
ColorTranslator.FromHtml("#D1D4D4"), 1, ButtonBorderStyle.Solid, //上边
ColorTranslator.FromHtml("#D1D4D4"), 1, ButtonBorderStyle.Solid, //右边
ColorTranslator.FromHtml("#D1D4D4"), 1, ButtonBorderStyle.Solid);//底边

属性:

private string typeName = string.Empty;
[Browsable(true)]//是否在设计器中显示此属性
[Description("分类名称")]
public string TypeName
{
get { return typeName; }
set
{
typeName = value;
this.lblTypeName.Text = typeName;
}
}

 

闪烁

this.GestationTable.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
.SetValue(GestationTable, true, null);

posted @ 2016-02-02 13:40  sy2015  阅读(2518)  评论(0)    收藏  举报