Public Class Form1
Dim MyTabControl As New TabControl
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With MyTabControl
.DrawMode = TabDrawMode.OwnerDrawFixed
.Dock = DockStyle.Fill
.SizeMode = TabSizeMode.Fixed
.ItemSize = New Size(200, 30)
.Controls.Add(New TabPage("Page1"))
.Controls.Add(New TabPage("Page2"))
.Controls.Add(New TabPage("Page3"))
AddHandler .DrawItem, AddressOf MyTabcontrol_DrawItem
AddHandler .MouseClick, AddressOf MyTabcontrol_MouseClick
End With
Me.Controls.Add(MyTabControl)
End Sub
Public Sub MyTabcontrol_DrawItem(ByVal sender As System.Object, ByVal e As DrawItemEventArgs)
Dim TC As TabControl = CType(sender, TabControl)
Dim TabRec As Rectangle = TC.GetTabRect(e.Index)
Dim Clr As Color = If(e.State = DrawItemState.Selected, Color.White, Color.LightGray)
e.Graphics.FillRectangle(New SolidBrush(Clr), TabRec)
Dim sf As New StringFormat
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
sf.FormatFlags = StringFormatFlags.NoWrap
If e.State = DrawItemState.Selected Then
Dim BTNRec As New Rectangle(TabRec.X + TabRec.Width - 30, 8, 18, 18)
e.Graphics.FillRectangle(Brushes.Red, BTNRec)
e.Graphics.DrawRectangle(Pens.DarkRed, BTNRec)
e.Graphics.DrawString("X", New Font(Me.Font.FontFamily, 8, FontStyle.Bold), Brushes.Black, BTNRec, sf)
End If
e.Graphics.DrawString(TC.TabPages(e.Index).Text, Me.Font, Brushes.Black, TabRec, sf)
TabRec.Inflate(-3, -3)
Dim Pn As Pen = If(e.State = DrawItemState.Selected, New Pen(Color.Green, 2), New Pen(Color.Red, 1))
e.Graphics.DrawRectangle(Pn, TabRec)
e.DrawFocusRectangle()
End Sub
Private Sub MyTabcontrol_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim TC As TabControl = CType(sender, TabControl)
Dim Rec As Rectangle = MyTabControl.GetTabRect(MyTabControl.SelectedIndex)
Dim HitTest As New Rectangle(Rec.X + Rec.Width - 30, 8, 18, 18)
If HitTest.Contains(New Point(e.X, e.Y)) Then
If Not TC.TabPages.Count = 1 Then
TC.TabPages.Remove(TC.SelectedTab)
End If
End If
End Sub
End Class
26 Eylül 2019 Perşembe
VB.Net Tabcontrol Tabpages close button without image
VB.Net Internet Explorer Browser Emulation
Firstly add this code in Form1 class
Sub SetBrowser()
Dim Key As String = "Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION"
Dim AppName As String = System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".exe"
Dim Mode As Integer = 9999
Dim RKey As RegistryKey = Registry.CurrentUser.CreateSubKey(Key)
If Not CBool(RKey.GetValue(AppName, False)) Then
RKey.SetValue(AppName, Mode, RegistryValueKind.DWord)
System.Threading.Thread.Sleep(1000)
End If
RKey.Close()
End Sub
After add this code Form1 Load
SetBrowser()
'HKEY_CURRENT_USER is recommended if you do not want to run your application with administrative privileges.
InternetExplorer.SetLatestBrowserEmulation(InternetExplorer.RegistryRoot.HKEY_LOCAL_MACHINE)
InternetExplorer.SetLatestBrowserEmulation(InternetExplorer.RegistryRoot.HKEY_CURRENT_USER)
Do not forget change option WebBrowser1 ScriptErrorsSuppressed True
Kaydol:
Yorumlar (Atom)