如何在C#中调整按钮背景图像?
答
BackgroundImageLayout将有助于...如果不是的话, 1)采取面板(PANEL1)。 2)你绑定按钮事件到面板(PANEL1) 3)添加另一个面板(是Panel2)到PANEL1在上面要设置背景图像和BackgroundImageLayout属性为ImageLayout.Stretch 4)然后调整的是Panel2 这会调整图片大小 希望这有助于
+0
发布是关于Winforms的 – TaW 2014-11-08 10:14:24
答
我不会比这更简单的的WinForms:
private void yourbutton_Paint(object sender, PaintEventArgs e)
{
// base.OnPaint(e); optional
Rectangle rc = yourButton.ClientRectangle;
Rectangle ri = new Rectangle(Point.Empty, yourButton.BackgroundImage.Size);
// e.Graphics.FillRectangle(SystemBrushes.Control, rc); optional
e.Graphics.DrawImage(yourButton.BackgroundImage, rc, ri, GraphicsUnit.Pixel);
e.Graphics.DrawString(yourButton.Text, yourButton.Font,
SystemBrushes.ControlText, Point.Empty); // if needed
}
如果你看一下代码,你会看到,它有效地真的只是一条线,或两个如果你有按钮上的文字..
你使用哪个框架? WPF/WinForms/ASP .NET /别的东西? – 2014-11-08 07:13:26
你有没有尝试类似[那](http://stackoverflow.com/questions/3707562/position-of-backgroundimage-in-windows-form)? – 2014-11-08 07:17:36
寻找简单的东西 – Yuvi 2014-11-08 07:21:43