C#的tabcontrol控件 选项卡在左侧,显示图标和名称:
1、 新增imageList1,将图片导入;
2、 设置tabcontrol的imageList属性为imageList1;
3、 依次设置个选项卡的图标
最终显示的选项卡名称在图标上面,与预期的效果不一致。
网上有很多博客都是要增加事件操作,需要先解决文字竖排的问题,在解决图标与文字位置关系的问题。想着不用这么麻烦,只要将名称与图标事先处理好就行了。
使用python批量处理一下图片就行的,程序如下:
# -*- coding: utf-8 -*-
from PIL import Image, ImageDraw, ImageFont
import os.path
resize_w = 100
resize_h = 100
set_w = 140
set_h = 140
font_s = 35
src = "../ico_name/"
d = "../new/"
ft = ImageFont.truetype("C:\\WINDOWS\\Fonts\\msyhbd.ttc", font_s) #微软雅黑
# 一个汉字的宽度
wid, h = ft.getsize("藤")
for filename in os.listdir(src):
print(filename)
image = Image.open(src + filename)
image = image.resize((resize_w, resize_h))
filename2 = filename.split('.')[0]
w, h = ft.getsize(filename2)
img = Image.new('RGBA', (set_w, set_h), (255, 255, 255, 0))
draw = ImageDraw.Draw(img)
draw.text((set_w/2 - w / 2, set_h - h), filename2, (0, 0, 0, 255), font=ft)
x = (int)((set_w-resize_w)/2)
y = 0
img.paste(image, (x, y, image.width + x, image.height + y))
img.save(d + filename)
运行前需要将图片的名字改成相应的名称。
最后,将C#的tabcontrol控件 选项卡的TEXT设为空;加上照片效果如下:
1、 选项卡在left:
2、 选项卡在top:
原创内容,谢绝转载!