PDA

View Full Version : DotNet Tab Color


MerlinEl
12-11-2009, 11:43 PM
Hi

Im trying to colorize tabs in dotNetObject "tabcontrol" like in the C# example below

http://en.csharp-online.net/images/d/d3/526-51.jpg

--Add an event handler for the DrawItem event and add the following code.

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));
}


--here is my try

fn netDrColor clr = ((dotNetClass "Drawing.Color").fromArgb clr.r clr.g clr.b)
fo = dotnetObject "form"
tc= dotNetObject "TabControl"
t1= dotNetObject "TabPage" "Actions"
tc.controls.add t1
--Get the item from the collection.
TabPage = tc.TabPages.item 0
--Get the real bounds for the tab rectangle.
TabBounds = tc.GetTabRect 0
--Draw a different background color
gr= dotnetclass "Drawing.Graphics"
Brush = dotnetobject "System.Drawing.SolidBrush" (netDrColor yellow)
Rect = dotnetobject "System.Drawing.Rectangle" 0 0 TabBounds.Width TabBounds.Height
gr.FillRectangle Brush Rect
fo.show()


must be something wrong in my version...
--translated from cz language
-- Runtime error: dotNet runtime exception: for method which is not static ned a target

MerlinEl
12-12-2009, 07:24 AM
here is thre diferent ways,
this time with no errors, but result is the same....


Global testTabForm
(
try testTabForm.close() catch()
--net fn
fn netDrColor clr = ((dotNetClass "Drawing.Color").fromArgb clr.r clr.g clr.b)
fn netDrRect pos size = (dotnetObject "Drawing.Rectangle" pos.x pos.y size.x size.y)
fn netDrSize size = (dotNetObject "Drawing.Size" size.x size.y)
fn onPaint1 s a =
(
Brush = dotnetobject "System.Drawing.SolidBrush" (netDrColor red)
format "tab size:%\n" [s.width, s.height]
Rect = dotnetobject "System.Drawing.Rectangle" 0 0 40 20
a.Graphics.FillRectangle Brush Rect --s.bounds
)
fn onPaint2 s a =
(
Brush = dotnetobject "System.Drawing.SolidBrush" (netDrColor yellow)
b = (dotNetObject "Drawing.Bitmap" 20 10) --Create new bitmap object
gr = (dotNetClass "Drawing.Graphics").fromImage b --Create new Graphics object
gr.FillRectangle Brush s.bounds
)
--interface
fo = dotnetObject "form"
tc= dotNetObject "TabControl"
t1= dotNetObject "TabPage" "Actions1"
t2= dotNetObject "TabPage" "Actions2"
--settings
fo.bounds = netDrRect [200,100] [500,200]

--tc.AccessibleRole = tc.AccessibleRole.Graphic
tc.AutoSize = true
tc.BackColor = netDrColor blue --1)do nothing
tc.ForeColor = netDrColor green --1)do nothing
tc.Appearance=tc.Appearance.FlatButtons
tc.Dock = tc.Dock.Left

tc.Alignment = tc.Alignment.right
tc.SizeMode=tc.SizeMode.Fixed
tc.DrawMode=tc.DrawMode.OwnerDrawFixed
tc.bounds = netDrRect [2,2] [fo.width, fo.height]
tc.controls.addRange #(t1,t2)
tc.ItemSize = netDrSize [25,100]
tc.SizeMode = tc.SizeMode.normal
--tc.IsAccessible = true

t2.BackColor = netDrColor yellow
t2.ForeColor = netDrColor white

dotNet.addeventhandler t1 "Paint" onPaint1 --2)do something else
dotNet.addeventhandler tc "click" onPaint2 --3)do nothing
fo.controls.add tc

testTabForm = fo
testTabForm.show()
)

CGGD
12-12-2009, 07:30 AM
fn netDrColor clr = ((dotNetClass "Drawing.Color").fromArgb clr.r clr.g clr.b)
fo = dotnetObject "form"
tc= dotNetObject "TabControl"
t1= dotNetObject "TabPage" "Actions"
tc.controls.add t1
fo.controls.add tc
TabPage = tc.TabPages.item 0
TabBounds = tc.GetTabRect 0
gr= dotnetclass "Drawing.Graphics"
Brush = dotnetobject "System.Drawing.SolidBrush" (netDrColor blue)
Rect = dotnetobject "System.Drawing.Rectangle" 0 0 TabBounds.Width TabBounds.Height
fo.topmost = true
fo.show()
(t1.CreateGraphics()).FillRectangle Brush Rect

MerlinEl
12-12-2009, 07:38 AM
fn netDrColor clr = ((dotNetClass "Drawing.Color").fromArgb clr.r clr.g clr.b)
fo = dotnetObject "form"
tc= dotNetObject "TabControl"
t1= dotNetObject "TabPage" "Actions"
tc.controls.add t1
fo.controls.add tc
TabPage = tc.TabPages.item 0
TabBounds = tc.GetTabRect 0
gr= dotnetclass "Drawing.Graphics"
Brush = dotnetobject "System.Drawing.SolidBrush" (netDrColor blue)
Rect = dotnetobject "System.Drawing.Rectangle" 0 0 TabBounds.Width TabBounds.Height
fo.topmost = true
fo.show()
(t1.CreateGraphics()).FillRectangle Brush Rect



Hi ShanDong

this line is good (t1.CreateGraphics()).FillRectangle Brush Rect :thumbsup:

but how to do this now..... (http://en.csharp-online.net/TabControl)

http://img257.imageshack.us/img257/1097/tabcolor.jpg

cyfer
12-12-2009, 09:50 AM
theForm = dotnetobject "System.Windows.Forms.Form"
thetab = dotnetobject "System.Windows.Forms.TabControl"
theAlignment = dotnetclass"System.Windows.Forms.TabAlignment"
theSize = dotnetobject "System.Drawing.Size" 25 100

theDrawMode = dotnetclass "System.Windows.Forms.TabDrawMode"
theSizeMode = dotnetclass"System.Windows.Forms.TabSizeMode"
theDockStyle = dotnetclass"System.Windows.Forms.DockStyle"


thetabPage_1 = dotnetobject "System.Windows.Forms.TabPage" "Controls"
thetabPage_2 = dotnetobject "System.Windows.Forms.TabPage" "Shapes"
thetabPage_3= dotnetobject "System.Windows.Forms.TabPage" "Geometry"
thetabPage_4 = dotnetobject "System.Windows.Forms.TabPage" "Helpers"


thetab.TabPages.Add(thetabPage_1)
thetab.TabPages.Add(thetabPage_2)
thetab.TabPages.Add(thetabPage_3)
thetab.TabPages.Add(thetabPage_4)


thetab.itemSize= theSize


thetab.Alignment = theAlignment.Right
thetab.Drawmode = theDrawMode.OwnerDrawFixed
thetab.SizeMode = theSizeMode.Fixed
thetab.Dock = theDockStyle.fill

theForm.Controls.add(thetab)
theForm.show()

CGGD
12-12-2009, 10:49 AM
Hi ShanDong

this line is good (t1.CreateGraphics()).FillRectangle Brush Rect :thumbsup:

but how to do this now..... (http://en.csharp-online.net/TabControl)

http://img257.imageshack.us/img257/1097/tabcolor.jpg
you can build it to dll with c# and Visual studio
after
dotNet.loadAssembly "this dll file"
ok,you can use this dll methods and class,with dotnetclass cotnetobject

MerlinEl
12-12-2009, 12:56 PM
Obviously it does not go through this "system.windows.forms.tabcontrol"
to change all interface colors.

With C# will teake me, much time to do this. (first of all, I must learn this language, but maybe not in this life :D)

Maybe it will be better way to use clasic dotnet "buttons" as tabs
and a "TableLayoutPanel" where can be added some controls for each button ;)

Thanks anyway for you Answers guys :beer:

MerlinEl
12-12-2009, 01:08 PM
I think it looks little better now or not?

http://img264.imageshack.us/img264/8743/tabs2j.jpg

MerlinEl
12-12-2009, 01:53 PM
and now with the icons:

http://img205.imageshack.us/img205/5121/tabs3.jpg

I like the dotNet Customization
cheers

oh my bad english . I must edit 100 times.... to correct my sentences

LoneRobot
12-14-2009, 10:32 AM
that's looking good rene,

Another option is to use the dotnet radiobutton with the appearance set to button, It means you can create the appearance of a flat tabcontrol with minimal effort, and have one state showing at a particular time, like a tab panel.

http://www.lonerobot.com/images/sdklight.jpg

MerlinEl
12-14-2009, 01:00 PM
that's looking good rene,

Another option is to use the dotnet radiobutton with the appearance set to button, It means you can create the appearance of a flat tabcontrol with minimal effort, and have one state showing at a particular time, like a tab panel.

http://www.lonerobot.com/images/sdklight.jpg


Hi Pete , using radiobutton is a good idea I will try this. Thank you :-)

CGTalk Moderation
12-14-2009, 01:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.