Page 1 of 1

TabControl close button

Posted: Sat Apr 28, 2012 11:41 am
by M1z23R
Lets get started....
First add class and name it xTabControl. And inherit it to Tabcontrol
Code: Select all
Public class xTabControl
inherits tabcontrol

end class

now, on controls paint event add this code that paints X button
Code: Select all
for i as integer= 0 to tabcount-1
e.graphics.drawline(gettabrect(i).right-10,5,gettabrect(i).right - 4,11)
e.graphics.drawline(gettabrect(i).right-4,5,gettabrect(i).right - 10,11)
next

that will draw two lines that looks like X.
Now add mouse move event and add this code.
Code: Select all
for i as integer 0 to tabcount -1
dim r as rectangle.equals(gettabrect(i))
dim r2 as new rectangle(r.righ-10,5,6,6)
if r2.contains(e.location) then
dim g as graphics=creategraphics
G.drawrectangle(new pen(color.fromaqgb(0,0,0),r2)
else
invalidate(r2)
end if
next

this will add highliht animatoin.
Now just add mouse down and mouse click event.
In mouse down event add this.
Code: Select all
for i as integer 0 to tabcount -1
dim r as rectangle.equals(gettabrect(i))
dim r2 as new rectangle(r.righ-10,5,6,6)
if r2.contains(e.location) then
dim g as graphics=creategraphics
G.fillrectangle(new solidbrush(color.red),r2)
else
invalidate(r2)
end if
next

And one more thing for actual tab close. On mouseclick add
Code: Select all
for I as integer= 0 to tabcount -1
dim r as rectangle.equals(gettabrect(i))
dim r2 as new rectangle(r.righ-10,5,6,6)
if r2.contains(e.location) then
Tabpages.removeat(i)
Exit sub
End if
next
The code is not tested I typed it up at school while I was borred.

Re: TabControl close button

Posted: Sat Apr 28, 2012 4:44 pm
by MrAksel
Code: Select all
dim r as rectangle.equals(gettabrect(i))
Is wrong. Replace ".equals" with " = "

Re: TabControl close button

Posted: Sat Apr 28, 2012 5:59 pm
by comathi
I've tried this before, but my problem has always been to detect when the tab page has been closed, so that I could run code based on that event. Any ideas?

Re: TabControl close button

Posted: Sun Apr 29, 2012 12:01 am
by M1z23R
Well, you could do something before the tabpages.removeat(i)
like if msgbox(quit,yesno) = ok then tabpages.removeat(i)

Re: TabControl close button

Posted: Sun Jul 01, 2012 7:47 pm
by MrAlicard
This will be good for the my browser.

Thanks everybody. :D