如何使一些图像作为背景的用户控件? [英] How to make a user control with some images as background?

查看:65
本文介绍了如何使一些图像作为背景的用户控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用户控件(例如面板或文本框)具有9张图像作为背景.
图像的格式为Targa Image.
我使用下面链接中的dll在Winform中加载TGA图像.
.NET Targa图像阅读器 [

I want to make a user control like a panel or a textbox with 9 images as the background.
And the format of the images are Targa Image.
I use the dll in the link below to load TGA Images in the Winform.
.NET Targa Image Reader[^]

I want the images are assigned into this format:

top left corner , top center , top right corner ,

center left , center center , center right ,

bottom left corner , bottom center , bottom right corner ,


The images in the 4 corners are fixed in size while the other 5 images will change its size with the height and width of the control. Also the position of the images will change along the size of the control. I perfer to use Graphic to make it but not picture boxes because I do not want to create 9 boxes for each control.

At least, I hope someone can show me the method and the code of how to make it with the first 3 images. Hope this will not be too difficult to make.

推荐答案

处理Paint事件,并使用分别为已加载的9个图像调用Graphics.DrawImage方法.提供的e.Graphics参数.

每个调用都可以指定目标位置和矩形,因此不要太困难.问题是要决定如何固定四个角图像并拉伸其他图像,如果您想对每个图像保持相同的长宽比.
Handle the Paint event, and call the Graphics.DrawImage method for each of the 9 Images you have loaded, using the e.Graphics parameter supplied.

Each call can specify the destination location and rectangle, so it shouldn''t be too difficult. The problem is going to be deciding how to fix the four corner images and stretch the others, if you want to keep the same aspect ratio to each image.


这篇关于如何使一些图像作为背景的用户控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆