📄 位图背景4-1.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Delphi</title>
<style type="text/css"><!--
.font { font-size: 9pt ; line-height:13pt;
}
A:link {color: rgb(0,0,160); font-style: normal; text-decoration: none; cursor: hand}
A:visited {color: rgb(0,0,160); font-style: normal; text-decoration: none}
A:active {color: rgb(255,0,0); font-style: normal; text-decoration: none}
A:hover {color: rgb(51,102,255); font-style:bold; text-decoration: underline}
-->
</style>
</head>
<body background="../images/hu.gif">
<!--webbot bot="Include" U-Include="../top.htm" TAG="BODY" startspan --><strong>[top.htm]</strong><!--webbot bot="Include" endspan i-checksum="11293" -->
<table border="0" width="79%" height="860">
<tr>
<td width="100%" height="46" bgcolor="#AFE4EB"><p align="center"><font face="幼圆" color="#FF0000"><big><big><big><strong>DELPHI 学 习 园 地</strong></big></big></big></font></td>
</tr>
<tr>
<td width="100%" height="44" bgcolor="#EEF49D"><big><big><big><font face="幼圆" color="#0000FF"><strong><p align="center">DELPHI中绘制窗体的位图背景</strong></font></big></big></big></td>
</tr>
<tr>
<td width="100%" bgcolor="#A5CCED" height="719"><font color="#000000" face="宋体" size="3"><span class="font"> 在Delphi中窗体的背景在缺省状况下是灰色的,如果我们想使窗体背景变得醒目有各种方法。最简单的方法是在窗体上添加Image或PaintBox等图象控件,设置控件的图象属性,使其指向某张图片;另一种方法是利用TBitmap对象来载入图片,然后在窗体的FormPaint方法中绘制图片。下面分别比较一下两种方法的效果。</span></font><p><font color="#000000" face="宋体" size="3"><span class="font">
首先介绍利用TBitmap对象来载入图片,然后在窗体的FormPaint方法中绘制图片的方法。</span></font></p>
<p><font color="#000000" face="宋体" size="3"><span class="font"><strong>unit</strong>
Unit1;<br>
<strong>interface</strong><br>
<strong>uses</strong> SysUtils, WinTypes, WinProcs, Messages, Classes,
Graphics, Controls,<br>
Forms, Dialogs;<br>
<strong>type</strong><br>
TForm1 = class(TForm)<br>
<strong>procedure</strong> FormCreate(Sender: TObject);<br>
<strong>procedure</strong> FormPaint(Sender: TObject);<br>
<strong>private</strong><br>
{ Private declarations }<br>
<strong>public</strong><br>
{ Public declarations }<br>
<strong>end;</strong><br>
<strong>var</strong><br>
Form1: TForm1;<br>
Bitmap: TBitmap;//声明一个Tbitmap类型的变量<br>
<strong>implementation</strong><br>
{$R *.DFM}<br>
<strong>procedure</strong> TForm1.FormCreate(Sender: TObject);<br>
<strong>begin//在窗体创建的事件中创建TBitmap对象,并装入相应的图片</strong><br>
Bitmap := TBitmap.Create;<br>
Bitmap.LoadFromFile('C:\WINDOWS\cars.BMP');<br>
<strong>end;</strong><br>
<strong>procedure</strong> TForm1.FormPaint(Sender: TObject);//在窗体绘制事件中绘制图片<br>
<strong>var</strong><br>
X, Y, W, H: LongInt;//X指绘制图象的横坐标;Y指绘制图象的纵坐标;W指绘制图象的宽度;H指绘制图象的高度<br>
<strong>begin</strong><br>
<strong> with</strong> Bitmap <strong>do begin</strong><br>
W := Width;//这里的Width是图片的宽度;<br>
H := Height;//这里的Height是图片的高度;<br>
<strong> end;</strong><br>
Y := 0;<br>
<strong> while</strong> Y < Height<strong> do begin//在下面的二重循环中绘制图片</strong><br>
X := 0;<br>
<strong> while</strong> X < Width <strong>do
begin</strong><br>
Canvas.Draw(X, Y,
Bitmap);<br>
Inc(X, W);<br>
<strong> end;</strong><br>
Inc(Y, H);<br>
<strong> end;<br>
end;<br>
end.</span></font><font size="3" color="#000080"><br>
</font><font size="3" color="#FF0000">效果图:</font></strong></p>
<blockquote>
<blockquote>
<p align="center"><font size="3" color="#FF0000"><strong>正常情况
</strong></font></p>
</blockquote>
</blockquote>
<p align="center"><img src="de_image/deff1.jpg" alt="deff1.jpg (11151 bytes)" WIDTH="300" HEIGHT="206">
</p>
<p align="center"><font size="3" color="#FF0000"><strong>最大化情况</strong></font></p>
<p align="center"><img src="de_image/deff2.jpg" width="300" height="204" alt="deff2.jpg (13233 bytes)"></td>
</tr>
<tr>
<td width="100%" bgcolor="#A5CCED" height="39"><p align="right"><a href="delphi4-2.htm"><img src="../images/goto.gif" alt="goto.gif (1211 bytes)" WIDTH="49" HEIGHT="23"><strong>下一页</strong></a></td>
</tr>
</table>
<!--webbot bot="Include" U-Include="../wei1.htm" TAG="BODY" startspan --><strong>[wei1.htm]</strong><!--webbot bot="Include" endspan i-checksum="9818" -->
<p>
</p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -