Notifications
Clear all

[Closed] DotNet Tab Color

Hi

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

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

–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;
    
     [i]// Get the item from the collection.[/i]
     TabPage _TabPage = tabControl1.TabPages[e.Index];
    
     [i]// Get the real bounds for the tab rectangle.[/i]
     Rectangle _TabBounds = tabControl1.GetTabRect(e.Index);
    
     if(e.State == DrawItemState.Selected)
     {
       [i]// Draw a different background color, and don't paint a focus rectangle.[/i]
       _TextBrush = new SolidBrush(Color.Red);
       g.FillRectangle(Brushes.Gray, e.Bounds);
     }
     else
     {
       _TextBrush = new System.Drawing.SolidBrush(e.ForeColor);
       e.DrawBackground();
     }
    
     [i]// Use our own font. Because we CAN.[/i]
     Font _TabFont = new Font("Arial", 10, FontStyle.Bold, GraphicsUnit.Pixel);
    
     [i]// Draw string. Center the text.[/i]
     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

10 Replies

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:%
" [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()
   )
 


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

1 Reply
(@merlinel)
Joined: 11 months ago

Posts: 0

Hi ShanDong

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

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


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()

you can build it to dll with c# and Visual studio
after
dot[font=‘Courier New’]Net.loadAssembly “this dll file”[/font]
ok,you can use this dll methods and class,with dotnetclass cotnetobject

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

I think it looks little better now or not?

and now with the icons:

  [img] http://img205.imageshack.us/img205/5121/tabs3.jpg [/img]
  
  I like the dotNet Customization
  cheers

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

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.

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