Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 选项卡控件,具有垂直对齐文本的垂直对齐选项卡_C#_Winforms_Visual Studio 2008 - Fatal编程技术网

C# 选项卡控件,具有垂直对齐文本的垂直对齐选项卡

C# 选项卡控件,具有垂直对齐文本的垂直对齐选项卡,c#,winforms,visual-studio-2008,C#,Winforms,Visual Studio 2008,我想使用一个选项卡控件,将选项卡显示在左侧,而不是顶部。我已经将对齐设置为左侧,选项卡显示在那里。但是,如何使文本垂直显示在选项卡上?我看过msdn,它给出了一个左对齐选项卡控件的示例,但是选项卡标签仍然水平显示 另一件事,有人知道如何使用标签控件与左对齐的默认布局的标签,使它看起来更好吗 请不要使用第三方应用程序,除非它们是免费的,是的,我已经看过代码项目了 谢谢,R.这是本机Windows选项卡控件的视觉样式渲染器中的一个古老错误。它只支持顶部的标签,我猜,负责它的微软程序员在完成工作之前被

我想使用一个选项卡控件,将选项卡显示在左侧,而不是顶部。我已经将对齐设置为左侧,选项卡显示在那里。但是,如何使文本垂直显示在选项卡上?我看过msdn,它给出了一个左对齐选项卡控件的示例,但是选项卡标签仍然水平显示

另一件事,有人知道如何使用标签控件与左对齐的默认布局的标签,使它看起来更好吗

请不要使用第三方应用程序,除非它们是免费的,是的,我已经看过代码项目了


谢谢,R.

这是本机Windows选项卡控件的视觉样式渲染器中的一个古老错误。它只支持顶部的标签,我猜,负责它的微软程序员在完成工作之前被一辆公共汽车碾过了

唯一可以做的就是有选择地关闭控件的视觉样式。向项目中添加一个新类并粘贴如下所示的代码。编译。将工具箱顶部的新控件放到窗体上,替换原来的控件

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

public class FixedTabControl : TabControl {
    [DllImportAttribute("uxtheme.dll")]
    private static extern int SetWindowTheme(IntPtr hWnd, string appname, string idlist);

    protected override void OnHandleCreated(EventArgs e) {
        SetWindowTheme(this.Handle, "", "");
        base.OnHandleCreated(e);
    }
}

如果创建自己的DrawItem事件,则可以手动写入选项卡标题。您可以使用以下过程:

1) 设置TabControl的以下属性:

 Property  |  Value
 ----------|----------------
 Alignment |  Right (or left, depending on what you want)
 SizeMode  |  Fixed
 DrawMode  |  OwnerDrawFixed
2) 将ItemSize.Width属性设置为25,将ItemSize.Height属性设置为100。根据需要调整这些值,但请记住,基本上,宽度就是高度,反之亦然

3) 为DrawItem事件添加事件处理程序并添加以下代码:

private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
  Graphics g = e.Graphics;
  Brush _TextBrush;

  // Get the item from the collection.
  TabPage _TabPage = tabControl1.TabPages[e.Index];

  // Get the real bounds for the tab rectangle.
  Rectangle _TabBounds = tabControl1.GetTabRect(e.Index);

  if(e.State == DrawItemState.Selected)
  {
    // Draw a different background color, and don't paint a focus rectangle.
    _TextBrush = new SolidBrush(Color.Red);
    g.FillRectangle(Brushes.Gray, e.Bounds);
  }
  else
  {
    _TextBrush = new System.Drawing.SolidBrush(e.ForeColor);
    e.DrawBackground();
  }

  // Use our own font. Because we CAN.
  Font _TabFont = new Font("Arial", 10, FontStyle.Bold, GraphicsUnit.Pixel);

  // Draw string. Center the text.
  StringFormat _StringFlags = new StringFormat();
  _StringFlags.Alignment = StringAlignment.Center;
  _StringFlags.LineAlignment = StringAlignment.Center;
  g.DrawString(_TabPage.Text, _TabFont, _TextBrush, 
               _TabBounds, new StringFormat(_StringFlags));
}
4) 利润


(原始资料来源:)

太棒了。现在我只需要重新设计它的样式…:)汉斯,你能帮个忙,告诉我怎么重新设计它吗?我想让它看起来像默认的选项卡控件。任何有帮助的建议都将不胜感激,因为这些东西都是新的,我觉得我就像是在兜圈子,或者说是谷歌圈子。。。