TabControl close button

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
5 posts Page 1 of 1
Contributors
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

TabControl close button
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.
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: TabControl close button
MrAksel
Code: Select all
dim r as rectangle.equals(gettabrect(i))
Is wrong. Replace ".equals" with " = "
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Re: TabControl close button
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?
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

Re: TabControl close button
M1z23R
Well, you could do something before the tabpages.removeat(i)
like if msgbox(quit,yesno) = ok then tabpages.removeat(i)
User avatar
MrAlicard
VIP - Donator
VIP - Donator
Posts: 54
Joined: Thu Aug 05, 2010 4:08 pm

Re: TabControl close button
MrAlicard
This will be good for the my browser.

Thanks everybody. :D
5 posts Page 1 of 1
Return to “Tutorials”