C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,648 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I want to display a vertical ControlTab with horizontal text. I have found the following C# code. Please help me to translate this for using with C++/CLI Windows Forms.
using System;
using System.Drawing;
using System.Windows.Forms;
class VerticalTabControl : TabControl {
public VerticalTabControl() {
this.Alignment = TabAlignment.Right;
this.DrawMode = TabDrawMode.OwnerDrawFixed;
this.SizeMode = TabSizeMode.Fixed;
this.ItemSize = new Size(this.Font.Height * 3 / 2, 75);
}
public override Font Font {
get { return base.Font; }
set {
base.Font = value;
this.ItemSize = new Size(value.Height * 3 / 2, base.ItemSize.Height);
}
}
protected override void OnDrawItem(DrawItemEventArgs e) {
using (var _textBrush = new SolidBrush(this.ForeColor)) {
TabPage _tabPage = this.TabPages[e.Index];
Rectangle _tabBounds = this.GetTabRect(e.Index);
if (e.State != DrawItemState.Selected) e.DrawBackground();
else {
using (var brush = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, Color.White, Color.LightGray, 90f)) {
e.Graphics.FillRectangle(brush, e.Bounds);
}
}
StringFormat _stringFlags = new StringFormat();
_stringFlags.Alignment = StringAlignment.Center;
_stringFlags.LineAlignment = StringAlignment.Center;
e.Graphics.DrawString(_tabPage.Text, this.Font, _textBrush, _tabBounds, new StringFormat(_stringFlags));
}
}
}
Check this class:
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
namespace MyNamespace
{
public ref class VerticalTabControl : public TabControl
{
using base = TabControl;
public:
VerticalTabControl( )
{
this->Alignment = TabAlignment::Right;
this->DrawMode = TabDrawMode::OwnerDrawFixed;
this->SizeMode = TabSizeMode::Fixed;
this->ItemSize = System::Drawing::Size( this->Font->Height * 3 / 2, 75 );
}
property System::Drawing::Font^ Font
{
virtual System::Drawing::Font^ get( ) override
{
return base::Font;
}
virtual void set( System::Drawing::Font^ value ) override
{
base::Font = value;
this->ItemSize = System::Drawing::Size( value->Height * 3 / 2, base::ItemSize.Height );
}
}
protected:
virtual void OnDrawItem( DrawItemEventArgs^ e ) override
{
SolidBrush _textBrush( ForeColor );
TabPage^ _tabPage = TabPages[e->Index];
Rectangle _tabBounds = GetTabRect( e->Index );
if( e->State != DrawItemState::Selected )
{
e->DrawBackground( );
}
else
{
Drawing2D::LinearGradientBrush brush( e->Bounds, Color::White, Color::LightGray, 90.0 );
e->Graphics->FillRectangle( % brush, e->Bounds );
}
StringFormat _stringFlags;
_stringFlags.Alignment = StringAlignment::Center;
_stringFlags.LineAlignment = StringAlignment::Center;
e->Graphics->DrawString( _tabPage->Text, Font, % _textBrush, _tabBounds, gcnew StringFormat( % _stringFlags ) );
}
};
}
I started with:
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
ref class VerticalTabControl: public System::Windows::Forms::TabControl {
public: VerticalTabControl() {
this->Alignment = TabAlignment::Right;
this->DrawMode = TabDrawMode::OwnerDrawFixed;
this->SizeMode = TabSizeMode::Fixed;
this->ItemSize = System::Drawing::Size(this->Font->Height*3/2, 75);
}
};
But next I couldn't understand.