各位好:
我在练习卢严写的关于《可伸缩的自定义窗口》时碰到以下问题:
在用FillRectangle方法绘制图片边框时,若第三个参数不是图片height的倍数,就会
以填充图片错误(实际上不报错,就是在绘制时绘制错了),以下是出错代码:
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
//手工画窗体的各个部分
DrawTop_Left(g);//画标题栏左边
DrawTop_Middle(g);//画标题栏中间
DrawTop_Right(g);//画标题栏右边
DrawBottom_Left(g);//画左下角,这行调试的结果是错误的图片显示
}
下面是调用的方法
private void DrawBottom_Left(Graphics g)
{
Brush brush = new TextureBrush (bottom_left,new Rectangle(0,0,bottom_left.Width,bottom_left.Height));
g.FillRectangle(brush,0,this.Height - bottom_left.Height,bottom_left.Width,bottom_left.Height);
}
若this.Height - bottom_left.Height这个参数不是这个bottom_left图片的height倍数就会
错误填充,设成0也能正常显示。请问 这个问题该如何解决
我在练习卢严写的关于《可伸缩的自定义窗口》时碰到以下问题:
在用FillRectangle方法绘制图片边框时,若第三个参数不是图片height的倍数,就会
以填充图片错误(实际上不报错,就是在绘制时绘制错了),以下是出错代码:
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
//手工画窗体的各个部分
DrawTop_Left(g);//画标题栏左边
DrawTop_Middle(g);//画标题栏中间
DrawTop_Right(g);//画标题栏右边
DrawBottom_Left(g);//画左下角,这行调试的结果是错误的图片显示
}
下面是调用的方法
private void DrawBottom_Left(Graphics g)
{
Brush brush = new TextureBrush (bottom_left,new Rectangle(0,0,bottom_left.Width,bottom_left.Height));
g.FillRectangle(brush,0,this.Height - bottom_left.Height,bottom_left.Width,bottom_left.Height);
}
若this.Height - bottom_left.Height这个参数不是这个bottom_left图片的height倍数就会
错误填充,设成0也能正常显示。请问 这个问题该如何解决
若把 Brush brush = new TextureBrush (bottom_left,new Rectangle(0,0,bottom_left.Width,bottom_left.Height));
代码 改成:
Brush brush = new TextureBrush (bottom_left,new Rectangle(0,1,bottom_left.Width,bottom_left.Height));
就会报错。。这个为什么
br.WrapMode=WrapMode.Tile;
g.FillRectangle(br,TitleLeft.Width,0,this.Width-TitleRight.Width-TitleLeft.Width,TitleMiddle.Height);用TextUreBrush即可。
但是有个问题,就是宽度大小如果不是2的倍次方的时候,填充会移位。
如果采用DrawImage直接重绘,位置倒是相当准确,但是绘制中间填充段的时候,会出现渐变。已困扰我两天,无法解决。