Winform自定义控件基础

Posted imstrive

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Winform自定义控件基础相关的知识,希望对你有一定的参考价值。

1.设置图像和文字以抗锯齿的方式呈现

1     g.SmoothingMode = SmoothingMode.AntiAlias;
2     g.TextRenderingHint = TextRenderingHint.AntiAlias;

 

2.指定区域绘图(常见于OnPaint函数中:g.DrawImage(...)

1     // 参数: 
2     //   image:
3     //     要绘制的 System.Drawing.Image。
4     //
5     //   rect:
6     //     System.Drawing.Rectangle 结构,它指定所绘制图像的位置和大小。
7     public void DrawImage(Image image, Rectangle rect);

 1    // 参数: 
 2    //   image:
 3    //     要绘制的 System.Drawing.Image。
 4    //   destRect:
 5    //     System.Drawing.Rectangle 结构,它指定所绘制图像的位置和大小。 将图像进行缩放以适合该矩形。
 6    //   srcRect:
 7    //     System.Drawing.Rectangle 结构,它指定 image 对象中要绘制的部分。
 8    //   srcUnit:
 9    //     System.Drawing.GraphicsUnit 枚举的成员,它指定 srcRect 参数所用的度量单位。
10    public void DrawImage(Image image, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit);

 

3.指定区域绘制文本:

1     TextRenderer.DrawText(....)

或者

1     g.DrawString(....)

 

4.程序效果只在运行时显示

1     if (!this.DesignMode)
2     {
3         //代码
4     }

 

以上是关于Winform自定义控件基础的主要内容,如果未能解决你的问题,请参考以下文章