Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

TabPage Image + DrawItem

sonu_1984sonu_1984 Member Posts: 6
hi frnds, I want to add cross button image on the right hand side of tabPage...I m creating tabpages at Runtime....
Mine code is added image to the Right along with the text at the left...

I want to just ask that is that possible to write the code the image...so dat i m able to close tab when i click on the image
PLZ help me on this matter
Mine code below that is adding tab at runtime along with image-

[code]
Public Class Form2
Dim TabPageIndex As Integer
Dim tab As TabPage = New TabPage("SONIA SARDANA")
Public Sub New()
InitializeComponent()
TabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed
End Sub

Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs)
Try


Dim img As Image = ImgIcons.Images(0)

Dim _imageLocation As Point = New Point(15, 5)
Dim _imgHitArea As Point = New Point(13, 2)


Dim r As Rectangle = e.Bounds
r = Me.TabControl1.GetTabRect(e.Index)
r.Offset(2, 2)

Dim TitleBrush As Brush = New SolidBrush(Color.Black)
Dim f As Font = Me.Font

Dim title As String = Me.TabControl1.TabPages(e.Index).Text
e.Graphics.DrawString(title, f, TitleBrush, New PointF(r.X, r.Y))
e.Graphics.DrawImage(img, New Point(r.X + (Me.TabControl1.GetTabRect(e.Index).Width - _imageLocation.X), _imageLocation.Y))

Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Static lTabIndex As Integer
lTabIndex = lTabIndex + 1
tab.Name = "Tab" & lTabIndex
TabControl1.TabPages.Add(tab)
TabPageIndex = TabControl1.TabPages.Count - 1
AddHandler TabControl1.DrawItem, AddressOf TabControl1_DrawItem

Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
[/code]
Sign In or Register to comment.