当前位置:编程学习 > C#/ASP.NET >>

C# 按钮图片 背景 分段 显示



我想实现  点击后 显示第三段  正常为第一段?
是C#WindowsForms  非.aspx --------------------编程问答-------------------- 我想实现  点击后 显示第三段  正常为第一段?
LZ想表达的是什么意思 --------------------编程问答-------------------- 楼主是想用css定位啊
要先设定好宽和高,然后用class开控制按钮的样式
backgroud:url(你图片的路径)no-repeat x轴坐标 y轴坐标; --------------------编程问答--------------------

public class MyButton : Button
{
    private Rectangle srcRect;
    public MyButton()
    {
       srcRect = new Rectangle(0, 0, 98, 34);
    }

    protected override void OnPaint(PaintEventArgs pevent)
    {
       base.OnPaint(pevent);

       Graphics g = pevent.Graphics;
       g.DrawImage(Properties.Resources._1378704733_149751, 0, 0, srcRect, GraphicsUnit.Pixel);
    }

    protected override void OnMouseDown(MouseEventArgs mevent)
    {
        base.OnMouseDown(mevent);
        SetSourceRectangle(new Rectangle(196, 2, 98, 34));
    }

    protected override void OnMouseUp(MouseEventArgs mevent)
    {
        base.OnMouseUp(mevent);
        SetSourceRectangle(new Rectangle(0, 2, 98, 34));
    }

    private void SetSourceRectangle(Rectangle rect)
    {
        srcRect = rect;
        this.Invalidate();
    }
}
--------------------编程问答--------------------

  protected override void OnPaint(PaintEventArgs pevent)
    {
        去掉这句就不绘制系统的按钮了
       //base.OnPaint(pevent);
 
       Graphics g = pevent.Graphics;
       g.DrawImage(Properties.Resources._1378704733_149751, 0, 0, srcRect, GraphicsUnit.Pixel);
    }
--------------------编程问答-------------------- 背景图片切换就可以实现 --------------------编程问答--------------------
引用 4 楼 hwenycocodq520 的回复:

  protected override void OnPaint(PaintEventArgs pevent)
    {
        去掉这句就不绘制系统的按钮了
       //base.OnPaint(pevent);
 
       Graphics g = pevent.Graphics;
       g.DrawImage(Properties.Resources._1378704733_149751, 0, 0, srcRect, GraphicsUnit.Pixel);
    }


请问这个参数 是什么?srcRect --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 除 --------------------编程问答--------------------
引用 6 楼 u010361979 的回复:
Quote: 引用 4 楼 hwenycocodq520 的回复:


  protected override void OnPaint(PaintEventArgs pevent)
    {
        去掉这句就不绘制系统的按钮了
       //base.OnPaint(pevent);
 
       Graphics g = pevent.Graphics;
       g.DrawImage(Properties.Resources._1378704733_149751, 0, 0, srcRect, GraphicsUnit.Pixel);
    }


请问这个参数 是什么?srcRect

图片的部分区域,看上面把它定义为一个字段
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,