问题上的TabControl图像对齐 [英] Problem With Alignment of Image on TabControl

查看:201
本文介绍了问题上的TabControl图像对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是C#的winform 的TabControl 。我创建了一个的ImageList ,用的TabControl 相关联,并与一些图像填充它。问题是,当我设置的ImageIndex ImageKey 特定标签图像中显示的选项卡上,但它覆盖了一个选项卡上的文字。添加到我的困惑,有一个的TabPage 特别呈现在正确的位置的图像(图像后面的文本)。有在正确的位置的图像的页面是什么的TabPage 我设置了的ImageIndex 财产上的第一...

I'm using a c# winform TabControl. I've created an ImageList, associated it with the TabControl and populated it with a few images. The problem is, when I set the ImageIndex or ImageKey for a particular tab the image shows up on the tab, but it covers the text that is on the tab. To add to my confusion, one TabPage in particular renders the image in the correct location (image followed by text). The page that has the image in the correct location is whatever TabPage I set the ImageIndex property on first...

我周围的一派,发现那里有人描述了这个问题,每个人都表示,他们无法重现问题的另一个论坛上一个帖子。任何想法问题可能是什么?我真的不知道什么尝试。

I've googled around and found a post on another forum where someone described this problem and everyone said they couldn't recreate the problem. Any ideas what the problem could be? I really don't know what to try.

修改

抱歉混乱。我有一个的TabControl 对象,它与一个的ImageList 的ImageList 属性C>有两个图像。当我设置一个的TabPage 的TabControl 的ImageIndex 属性>(从我读),它应该作为图像后跟文字呈现在的TabControl 实际的标签。这是当我设置的图像会发生什么在第一 的TabPage 在我的的TabControl ,但将与图像覆盖是标签上的文字呈现每一个选项卡下面。所以文字显示的图像后面。我用一个for循环来设置图像的每个设置页

Sorry for the confusion. I have a TabControl object with it's ImageList property associated with an ImageList that has two images. When I set the ImageIndex property on a TabPage in the TabControl (from what I read) it is supposed to render the actual tab on the TabControl as image followed by text. This is what happens when I set the image for the first TabPage in my TabControl but every tab following that will be rendered with the image covering the text that is on the tab. So the text appears behind the image. I use a for loop to set the image for each Tab:

for (int i = 0; i < tabControl.TabPages.Count; i++) {
    tabControl.TabPages[i].ImageIndex = SOME_IMG_INDEX;
}



的TabPage 在在 TabControl.TabPages 收藏指数0看起来正常(图像后面的文本)。其他人将有图像在文字之上。即使我开始为循环迭代索引2,索引2将正确地呈现,但任何经过,将有在文本上的形象。我希望这有助于使问题更加清晰。

The TabPage at index 0 of the TabControl.TabPages collection will look normal (image followed by text). The others will have the image over top of the text. Even if I were to start the for loop iteration at index 2, index 2 would render correctly but any after that would have the image over the text. I hope this helped make the question clearer.

推荐答案

我发现重新您的问题是,当我改变的唯一方法 SizeMode 的TabControl

The only way I've found to recreate your issue was when I changed the SizeMode property on the TabControl.

当我改变它固定,图像和文本进行混合。更改回'正常'再次呈现一切正常。

When I changed it to Fixed, the images and text were commingled. Changing it back to `Normal' rendered everything correctly again.

这的答案有关删除选项卡和添加他们回来作为解决此问题,张贴在MSDN工作的黑客会谈。我尝试了黑客和它的工作。

This answer talks about removing the tabs and adding them back in as a hack that works around this issue, posted at MSDN. I tried the hack and it worked.

更新:

由于Steve_Overflow指出出来,这是一个简单的解决方法正确地更新标签:

As Steve_Overflow pointed out, this is a simple work-around to update the tabs correctly:

tabControl1.SizeMode = TabSizeMode.Fixed;

for (int i = 0; i < tabControl1.TabPages.Count; i++)
  tabControl1.TabPages[i].ImageIndex = SOME_IMG_INDEX;

tabControl1.ItemSize = tabControl1.ItemSize;

这篇关于问题上的TabControl图像对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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