Delphi Tips - Forms with "Background"

zhaozj2021-02-11  240

Many web pages have background patterns, which makes the page look more eye-catching. But in Delphi, you can also design this type of form. One way you think about this is to use the image component, then specify a picture. This is of course feasible, but a BMP map that can be filled with the entire form, it is necessary to take a lot of memory space, which will not come. The best way is to download only a small BMP map and paste it into the entire form.

 There I didn't use the IMAGE component here, but used a Bitmap component, with it to download a small bitmap. The first is to join the variable definition in the PUBLIC section of the form: Bitmap: Tbitmap; then generate this object in the form's oncreate event, the code is as follows:

Procedure TFORM1.FormCreate (Sender: TOBJECT);

Begin Bitmap: = Tbitmap.create;

Bitmap.LoadFormfile ('1.BMP'); // Figure file 1.BMP only 1kb size

END;

The third step is to paste the pattern of the bitmap into the entire form in the ONPAINT event of the form. Add code as follows: in Procedure TForm1.FormPaint (Sender: TOBJECT) VAR X, Y: Inteder; Begin Y: = 0; While Y

Do Begin x: = 0;

While x

Do Begin Cancas.draw (X, Y, Bitmap);

X: = x bitmap.width;

END;

Y: = y bitmap.heigth;

End; End;   Last don't forget to release Bitmap objects in the onDestory event in the form. Specific code: Bitmap.Free; Ok, so that the form is displayed as a background like a web page, and does not account for how much memory space.

转载请注明原文地址:https://www.9cbs.com/read-3919.html

New Post(0)