水平對齊我按照在MSDN網站上的說明: https://msdn.microsoft.com/en-us/library/vstudio/ms404305%28v=vs.100%29.aspx 來顯示選項卡控制,如下圖:C#標籤控制左與圖象
而這是代碼:
private void tcMain_DrawItem(Object sender, DrawItemEventArgs e)
{
Graphics g = e.Graphics;
Brush _textBrush;
TabPage _tabPage = tcMain.TabPages[e.Index];
Rectangle _tabBounds = tcMain.GetTabRect(e.Index);
if (e.State == DrawItemState.Selected)
{
_textBrush = new SolidBrush(Color.Red);
g.FillRectangle(Brushes.Gray, e.Bounds);
}
else
{
_textBrush = new System.Drawing.SolidBrush(e.ForeColor);
e.DrawBackground();
}
Font _tabFont = new Font("Times New Roman", (float)22, FontStyle.Regular, GraphicsUnit.Pixel);
StringFormat _stringFlags = new StringFormat();
_stringFlags.Alignment = StringAlignment.Near;
_stringFlags.LineAlignment = StringAlignment.Center;
g.DrawString(_tabPage.Text, _tabFont, _textBrush, _tabBounds, new StringFormat(_stringFlags));
}
現在我想添加一個圖片到選項卡控制按鈕的左側?我的意思是,如何在單詞Book的左側顯示圖片,例如?
從下面嘗試一些答案後,我結束了與代碼:
private void tcMain_DrawItem(Object sender, DrawItemEventArgs e)
{
Graphics g = e.Graphics;
Brush _textBrush;
TabPage _tabPage = tcMain.TabPages[e.Index];
Rectangle _tabBounds = tcMain.GetTabRect(e.Index);
if (e.State == DrawItemState.Selected)
{
_textBrush = new SolidBrush(Color.Red);
g.FillRectangle(Brushes.Gray, e.Bounds);
}
else
{
_textBrush = new System.Drawing.SolidBrush(e.ForeColor);
e.DrawBackground();
}
tcMain.ImageList = imgList;
tcMain.TabPages[0].ImageIndex = 1;
tcMain.TabPages[1].ImageIndex = 0;
tcMain.TabPages[2].ImageIndex = 3;
tcMain.TabPages[3].ImageIndex = 2;
Rectangle tabImage = tcMain.GetTabRect(e.Index);
tabImage.Size = new Size(40, 40);
g.DrawImage(tcMain.ImageList.Images[_tabPage.ImageIndex], tabImage);
Font _tabFont = new Font("Times New Roman", (float)22, FontStyle.Regular, GraphicsUnit.Pixel);
StringFormat _stringFlags = new StringFormat();
_stringFlags.Alignment = StringAlignment.Center;
_stringFlags.LineAlignment = StringAlignment.Center;
g.DrawString(_tabPage.Text, _tabFont, _textBrush, _tabBounds, new StringFormat(_stringFlags));
}
刷新所有的時間
您已經處理繪製自己。使用'圖形'對象繪製你喜歡的任何圖片,無論你喜歡什麼。 –
你能否做一些編碼?我應該把它放在哪裏? –
你爲什麼不嘗試自己寫一些代碼?顯然,您將DrawImage與DrawString一起使用。 – TaW