日期:2014-05-17  浏览次数:20746 次

point窗体绘制按钮,怎么实现鼠标移动上去变换按钮
写了一个类。
C# code
messageGDI
{
        PaintEventArgs p;
        Image Button_Default = Image.FromFile(Application.StartupPath + @"\skin_default\message\ico.png");;
//一个button函数(主要是实现按钮绘制)
public void button(string st,int x, int y)
        {
            Rectangle rect = new Rectangle(x,y,69,22);
            p.Graphics.DrawImage(Button_Default, rect);
            rect = new Rectangle(x + 20, y + 5, 69 , 22);
            p.Graphics.DrawString(st, new Font("宋体", 10), Brushes.Black, rect);
}

}

之后我在
message窗体的point事件中写入:
C# code
 private void message_Paint(object sender, PaintEventArgs e)
{
 messageGDI MessageForm = new messageGDI();
 MessageForm._PainEventArgs = e;//我直接将paintEventArgs传进去。
 MessageForm.button("确定",100,100);//重绘窗体,添加一个类似的按钮。
}


现在要解决的问题是:
我使用事件mouseMove,当移动到窗体上的按钮位置时,我可以实现,按钮经过的样式。

尝试使用强制刷新,结果一直闪烁。。。

各位帮我下吧,谢谢了!应该能看懂问题吧?虽然我这个逻辑表达不是很好,~

------解决方案--------------------
不要频繁创建messageGDI ,试试用一个全局的
------解决方案--------------------
现在不说你这个代码,如果按一般做法,要么在OnPaint中直接绘制,move中调用invalidate重绘,要么封装一个类,传入e.Graphics
------解决方案--------------------
MouseEnter()
Button1.BackGroundImage="c:\1.jpg"

MouseLeave
Button1.BackGroundImage="c:\2.jpg"

应尽量避免使用Paint,Paint将使你的窗体闪烁,并且造成用户交互的延迟。
------解决方案--------------------
MouseHover和MouseLeave事件