How to stretch a background image of a windows form
来源:互联网 发布:楠木梁知txt书包网 编辑:程序博客网 时间:2024/06/04 17:59
Hello,
I write a windows form using C# with a background image on it. When it's
running on US English Windows, everything is fine. When it's running on
Chinese Windows, the background image tiled up. How can I stretch the
background image to fit this form?
TIA,
Arthur
Reply to this message... Herfried K. Wagner Hello,
"Arthur Hsu" <Click here to reveal e-mail address> schrieb:
[Original message clipped]
In VB .NET:
///
Private m_bi As Bitmap
Private Sub Form1_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles MyBase.Load
m_bi = Image.FromFile("C:/WINDOWS/Angler.bmp")
End Sub
Private Sub Form1_Resize( _
ByVal sender As Object, _
ByVal e As System.EventArgs _
) Handles MyBase.Resize
Me.CreateGraphics().DrawImage( _
m_bi, 0, 0, m_bi.Width, m_bi.Height _
)
End Sub
Private Sub Form1_Paint( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs _
) Handles MyBase.Paint
e.Graphics.DrawImage(m_bi, 0, 0, m_bi.Width,
m_bi.Height)
End Sub
///
Regards,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Reply to this message... Arthur Hsu Hello,
I got the answers from Google and it works well.
The C# solution
protected override void OnPaintBackground(PaintEventArgs pevent)
{
if (this.BackgroundImage != null)
{
pevent.Graphics.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.Low;
//pevent.Graphics.Clear(this.BackColor);
pevent.Graphics.DrawImage(this.BackgroundImage, 0, 0,
this.ClientRectangle.Width, this.ClientRectangle.Height);
}
else
{
base.OnPaintBackground(pevent);
}
}
The pevent.Graphics.Clear(this.BackColor); is commented out because I use a
background image with alpha channel. If you don't, you'd better add it
back.
Regards,
Arthur
I write a windows form using C# with a background image on it. When it's
running on US English Windows, everything is fine. When it's running on
Chinese Windows, the background image tiled up. How can I stretch the
background image to fit this form?
TIA,
Arthur
Reply to this message... Herfried K. Wagner Hello,
"Arthur Hsu" <Click here to reveal e-mail address> schrieb:
[Original message clipped]
In VB .NET:
///
Private m_bi As Bitmap
Private Sub Form1_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles MyBase.Load
m_bi = Image.FromFile("C:/WINDOWS/Angler.bmp")
End Sub
Private Sub Form1_Resize( _
ByVal sender As Object, _
ByVal e As System.EventArgs _
) Handles MyBase.Resize
Me.CreateGraphics().DrawImage( _
m_bi, 0, 0, m_bi.Width, m_bi.Height _
)
End Sub
Private Sub Form1_Paint( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs _
) Handles MyBase.Paint
e.Graphics.DrawImage(m_bi, 0, 0, m_bi.Width,
m_bi.Height)
End Sub
///
Regards,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Reply to this message... Arthur Hsu Hello,
I got the answers from Google and it works well.
The C# solution
protected override void OnPaintBackground(PaintEventArgs pevent)
{
if (this.BackgroundImage != null)
{
pevent.Graphics.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.Low;
//pevent.Graphics.Clear(this.BackColor);
pevent.Graphics.DrawImage(this.BackgroundImage, 0, 0,
this.ClientRectangle.Width, this.ClientRectangle.Height);
}
else
{
base.OnPaintBackground(pevent);
}
}
The pevent.Graphics.Clear(this.BackColor); is commented out because I use a
background image with alpha channel. If you don't, you'd better add it
back.
Regards,
Arthur
- How to stretch a background image of a windows form
- How to set background image of a component in GWTEXT
- How to remove background of a picture?
- How to tile a background image in Android
- how to select a transparent background image in ms paint.
- How To Change the Background Color of a Tab Control
- How to customize the background color of a UITableViewCell?
- How to list all tags of a docker image
- How to write a controller?( SDK Background)
- Android - How to have a tiled background
- How can I remove a background-image attribute?
- How to customize the background color of a UITableViewCell? 修改UITableViewCell背景色
- 如何修改Screen背景?How to - Change the background color of a screen
- Resizing a Form to Fit an Image
- How to Make a Bochs Disk Image
- How to mount a xen image ?
- How to Submit a Form Using JavaScript
- Using Alpha Channel to Blend Image on a Background Smoothly
- 深入浅出Win32多线程程序设计--之线程通信
- AntiKanalV2.90 反-算法检测工具KryptoAnalyzerV2.90
- xmms安装配置工作记录
- ubuntu安装
- ubuntu新手入门
- How to stretch a background image of a windows form
- Linux自启动设置详解
- 正则表达式使用详解
- 深入浅出Win32多线程程序设计--之MFC的多线程
- Java 的反射机制(2)
- WEB2.0优势与发展前景(1)
- 禁用c$等共享
- DB2控制中心菜单正常,显示表中的记录时乱码
- 深入浅出Win32多线程程序设计--之综合实例