无法将tabPage图像设置为tabControl C#

时间:2018-01-25 10:07:17

标签: c# winforms tabcontrol tabpage

我在ImageList

中有TabControl个项目
private System.Windows.Forms.ImageList tabControlMain_ilMain;
this.TabControlMain.ImageList = this.tabControlMain_ilMain;

this.tabControlMain_ilMain.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("tabControlMain_ilMain.ImageStream")));
this.tabControlMain_ilMain.TransparentColor = System.Drawing.Color.Silver;
this.tabControlMain_ilMain.Images.SetKeyName(0, "");   

我将此图片设置为特定的TabPage

this.tabControlMain_tp17.ImageIndex = 0;

我可以在设计器中看到附加到TabPage的图像,但是当我运行应用程序时,我看不到图像,它只是TabPage名称附近的空白区域。

有谁知道可能是什么问题?

谢谢!

P.S。我所看到的是,如果我没有选择ImageIndexTabPage标题的长度会变短,所以我猜图像占用空间,但在运行时无法看到它。

1 个答案:

答案 0 :(得分:0)

所以我认为没有什么不同于你的想法。但我的工作正在进行中 也许删除并读取控件。

private void InitializeComponent()
{
  this.components = new System.ComponentModel.Container();
  System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
  this.TabControlMain = new System.Windows.Forms.TabControl();
  this.tabControlMain_tp17 = new System.Windows.Forms.TabPage();
  this.tabControlMain_ilMain = new System.Windows.Forms.ImageList(this.components);
  this.TabControlMain.SuspendLayout();
  this.SuspendLayout();
  // 
  // TabControlMain
  // 
  this.TabControlMain.Controls.Add(this.tabControlMain_tp17);
  this.TabControlMain.ImageList = this.tabControlMain_ilMain;
  this.TabControlMain.Location = new System.Drawing.Point(44, 42);
  this.TabControlMain.Size = new System.Drawing.Size(192, 191);
  // 
  // tabControlMain_tp17
  // 
  this.tabControlMain_tp17.ImageIndex = 0;
  this.tabControlMain_tp17.Location = new System.Drawing.Point(4, 23);
  this.tabControlMain_tp17.Text = "tabControlMain_tp17";
  // 
  // tabControlMain_ilMain
  // 
  this.tabControlMain_ilMain.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("tabControlMain_ilMain.ImageStream")));
  this.tabControlMain_ilMain.TransparentColor = System.Drawing.Color.Transparent;
  this.tabControlMain_ilMain.Images.SetKeyName(0, "");
  // 
  // Form1
  // 
  this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  this.ClientSize = new System.Drawing.Size(284, 261);
  this.Controls.Add(this.TabControlMain);
  this.TabControlMain.ResumeLayout(false);
  this.ResumeLayout(false);

}

private System.Windows.Forms.TabControl TabControlMain;
private System.Windows.Forms.TabPage tabControlMain_tp17;
private System.Windows.Forms.ImageList tabControlMain_ilMain;