Click here to Skip to main content
15,560,678 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionCallbackOnCollectedDelegate was detected with LowLevelMouserProc Pin
Member 78319591-Aug-11 12:46
Member 78319591-Aug-11 12:46 
QuestionFont ComboBox add to Toolstrip Pin
nyt197231-Jul-11 4:13
professionalnyt197231-Jul-11 4:13 
AnswerRe: Font ComboBox add to Toolstrip Pin
Dave Kreskowiak31-Jul-11 5:24
mveDave Kreskowiak31-Jul-11 5:24 
GeneralRe: Font ComboBox add to Toolstrip Pin
nyt197231-Jul-11 19:36
professionalnyt197231-Jul-11 19:36 
GeneralRe: Font ComboBox add to Toolstrip Pin
Dave Kreskowiak1-Aug-11 4:49
mveDave Kreskowiak1-Aug-11 4:49 
GeneralRe: Font ComboBox add to Toolstrip Pin
nyt19722-Aug-11 2:42
professionalnyt19722-Aug-11 2:42 
GeneralRe: Font ComboBox add to Toolstrip Pin
Dave Kreskowiak2-Aug-11 4:47
mveDave Kreskowiak2-Aug-11 4:47 
GeneralRe: Font ComboBox add to Toolstrip Pin
nyt19722-Aug-11 22:21
professionalnyt19722-Aug-11 22:21 
Thanks Dave,

It worked, below is my code:

Imports System.Drawing
Imports System.Windows.Forms
Imports System.Windows.Forms.Design

<ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip)> _
Public Class ToolStripmyFontCombo
    Inherits ToolStripControlHost

    Public Sub New()
        MyBase.New(New FontClass)
    End Sub
End Class


Public Class FontClass
    Inherits ComboBox
    Dim wait As Boolean
    Public Sub New()
        Me.DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
        Me.DropDownStyle = ComboBoxStyle.DropDownList
        Me.Text = ""
        Dim ff As FontFamily
        Dim fc As New FontConverter

        For Each ff In FontFamily.Families
            Dim comboitem As New ComboBoxItem
            If ff.IsStyleAvailable(FontStyle.Regular) Then
                comboitem.Text = ff.Name
                comboitem.Font = fc.ConvertFromString(ff.Name)
                Me.Items.Add(comboitem)

            End If
        Next

    End Sub

    Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
        e.DrawBackground()
        e.DrawFocusRectangle()
        Dim item As New ComboBoxItem
        Dim bounds As New Rectangle
        bounds = e.Bounds
        Try
            item = Me.Items(e.Index)
            e.Graphics.DrawString(item.Text, item.Font, New SolidBrush(e.ForeColor), bounds.Left, bounds.Top)

        Catch ex As Exception
            If (e.Index <> -1) Then
                e.Graphics.DrawString((e.Index).ToString(), e.Font, New SolidBrush(e.ForeColor), bounds.Left, bounds.Top)
            Else
                e.Graphics.DrawString(Text, e.Font, New SolidBrush(e.ForeColor), bounds.Left, bounds.Top)
            End If

        End Try

        MyBase.OnDrawItem(e)
    End Sub

    Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
        wait = False
        MyBase.OnMouseLeave(e)
    End Sub

    Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
        wait = False
        MyBase.OnMouseUp(e)
    End Sub


    Protected Overrides Sub OnSelectedIndexChanged(ByVal e As System.EventArgs)
        Try
            If wait = False Then
                Dim fc As New FontConverter

                Me.Font = fc.ConvertFromString(Me.Text)
            End If
        Catch ex As Exception
            MsgBox(ex.Message.ToString)
        End Try
    End Sub



End Class

Public Class ComboBoxItem

    Private ctext As String
    Private cSelFont As Font

    Property Text() As String
        Get
            Return ctext
        End Get
        Set(ByVal Value As String)
            ctext = Value
        End Set
    End Property
    Property Font() As Font
        Get
            Return cSelFont
        End Get
        Set(ByVal Value As Font)
            cSelFont = Value
        End Set
    End Property
    Public Overrides Function ToString() As String
        Return ctext
    End Function



End Class


But it gives me a warning:


Warning	1	Constructor on type 'System.Windows.Forms.ToolStripControlHost' not found.		0	0	

QuestionConnection string in with sqlserver 2005 Pin
nazimghori31-Jul-11 1:30
nazimghori31-Jul-11 1:30 
AnswerRe: Connection string in with sqlserver 2005 Pin
Shameel31-Jul-11 1:53
professionalShameel31-Jul-11 1:53 
AnswerRe: Connection string in with sqlserver 2005 Pin
Eddy Vluggen31-Jul-11 3:56
professionalEddy Vluggen31-Jul-11 3:56 
AnswerRe: Connection string in with sqlserver 2005 Pin
Dave Kreskowiak31-Jul-11 5:18
mveDave Kreskowiak31-Jul-11 5:18 
GeneralRe: Connection string in with sqlserver 2005 [modified] Pin
nazimghori31-Jul-11 7:19
nazimghori31-Jul-11 7:19 
GeneralRe: Connection string in with sqlserver 2005 Pin
Dave Kreskowiak31-Jul-11 14:57
mveDave Kreskowiak31-Jul-11 14:57 
AnswerRe: Connection string in with sqlserver 2005 Pin
thatraja31-Jul-11 7:05
professionalthatraja31-Jul-11 7:05 
GeneralRe: Connection string in with sqlserver 2005 Pin
Shameel31-Jul-11 8:30
professionalShameel31-Jul-11 8:30 
GeneralRe: Connection string in with sqlserver 2005 Pin
thatraja31-Jul-11 16:37
professionalthatraja31-Jul-11 16:37 
QuestionUse MS Windows Theme Pin
ivo7530-Jul-11 22:14
ivo7530-Jul-11 22:14 
AnswerRe: Use MS Windows Theme Pin
Dalek Dave23-Aug-11 12:27
professionalDalek Dave23-Aug-11 12:27 
QuestionGraph on Windows Forms (VB) Pin
geekgautam29-Jul-11 23:34
geekgautam29-Jul-11 23:34 
AnswerRe: Graph on Windows Forms (VB) Pin
DaveAuld30-Jul-11 1:41
professionalDaveAuld30-Jul-11 1:41 
AnswerRe: Graph on Windows Forms (VB) Pin
Carmelo La Monica30-Jul-11 3:12
professionalCarmelo La Monica30-Jul-11 3:12 
AnswerRe: Graph on Windows Forms (VB) Pin
thatraja30-Jul-11 3:34
professionalthatraja30-Jul-11 3:34 
Questionworking with USB Pin
hrishi32128-Jul-11 3:45
hrishi32128-Jul-11 3:45 
AnswerRe: working with USB Pin
Dr.Walt Fair, PE28-Jul-11 20:26
professionalDr.Walt Fair, PE28-Jul-11 20:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.