Solved

VB.NET Linetype combo box

Posted on 2006-11-12
10
369 Views
Last Modified: 2008-01-09
Hi Experts,

I would like to know how i could propulate a combo box with all excels different line types. I could display the linetypes as words, but i'd prefer  to show the actual line type

Cheers.

Tom
0
Comment
Question by:TommyTwoPints
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 13

Expert Comment

by:newyuppie
ID: 17924864
what do you mean linetype? can you give an example?
0
 
LVL 3

Author Comment

by:TommyTwoPints
ID: 17924883
in excel, you have the border line types; Single, dashed, dotted etc...

Also a line thickenss combo would be useful (showing the thickness as a graphic rather than an integer)

Cheers,

Tom
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17924901
and you would need this to interact with an Excel cell automatically or would you jsut display the string values and not interact at all with Excel?
0
 
LVL 10

Assisted Solution

by:Kinger247
Kinger247 earned 150 total points
ID: 17924960
The only way you'll do that is by creating images of the line types and putting them into a listbox used by a combo ..

But you'll need to manually create the line type images (which you could do by taking several screen shots of the line type dropdown).

Here's an example of that in practice : http://www.codeproject.com/vb/net/ImageComboBox_VBNET.asp
0
 
LVL 3

Author Comment

by:TommyTwoPints
ID: 17924973
newyuppie. i will handle the code that changes the excel cells border. I just need to display the line types in a combo.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 6

Assisted Solution

by:Marv-in
Marv-in earned 150 total points
ID: 17925023
I did a simple draw string but you can draw line and change the thikness.

you also need to change the comboboxes drawmode to owner draw

Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem

        e.DrawBackground()
        e.DrawFocusRectangle()

        e.Graphics.DrawString("-----", Me.Font, Brushes.DarkSlateGray, e.Bounds.Left, e.Bounds.Top)


    End Sub

from article
http://www.codeproject.com/vb/net/xComboBox.asp
0
 
LVL 7

Accepted Solution

by:
Mohamed Zedan earned 200 total points
ID: 17927299
I quickly whiped this up for you hope it is what you want :)

Imports System.ComponentModel

Public Class LineTypeCombo
    Inherits ComboBox

    Private _SelectedType As Drawing2D.DashStyle

    Public Sub New()
        MyBase.New()
        MyBase.DrawMode = DrawMode.OwnerDrawFixed
        MyBase.DropDownStyle = ComboBoxStyle.DropDownList
        FillLineTypes()
    End Sub

    Private Sub FillLineTypes()
        Dim Dashs As Drawing.Drawing2D.DashStyle
        Dim Names As String() = [Enum].GetNames(GetType(Drawing2D.DashStyle))
        MyBase.Items.Clear()
        For i As Integer = 0 To Names.Length - 1
            MyBase.Items.Add(Names(i))
        Next

        MyBase.SelectedIndex = 0
        _SelectedType = [Enum].Parse(GetType(Drawing2D.DashStyle), MyBase.Items(0))
    End Sub

    Public ReadOnly Property SelectedLineStyle()
        Get
            Return _SelectedType
        End Get
    End Property

    Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
        MyBase.OnDrawItem(e)
        If e.Index >= 0 Then
            Dim ItemRect As Rectangle = e.Bounds
            Dim Pen As New Pen(Color.Black, 2)
            Pen.DashStyle = [Enum].Parse(GetType(Drawing2D.DashStyle), MyBase.Items(e.Index))

            e.Graphics.FillRectangle(New SolidBrush(Me.BackColor), e.Bounds)

            If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
                e.DrawBackground()
            End If
            If (e.State And DrawItemState.Focus) = DrawItemState.Focus Then
                e.DrawFocusRectangle()
            End If

            e.Graphics.DrawLine(Pen, Convert.ToSingle(ItemRect.X), Convert.ToSingle(ItemRect.Y + ItemRect.Height / 2), _
                                    Convert.ToSingle(ItemRect.X + ItemRect.Width), Convert.ToSingle(ItemRect.Y + ItemRect.Height / 2))
        End If
    End Sub

    Protected Overrides Sub OnSelectedIndexChanged(ByVal e As System.EventArgs)
        _SelectedType = [Enum].Parse(GetType(Drawing2D.DashStyle), (MyBase.SelectedItem))
        MyBase.OnSelectedIndexChanged(e)
    End Sub

    <Browsable(False)> _
    Public Shadows ReadOnly Property DropDownStyle()
        Get
            Return MyBase.DropDownStyle
        End Get
    End Property 'DropDownStyle
    <Browsable(False)> _
    Public Shadows ReadOnly Property Text()
        Get
            Return MyBase.DropDownStyle
        End Get
    End Property 'Text
    <Browsable(False)> _
        Public Shadows ReadOnly Property Items()
        Get
            Return MyBase.Items
        End Get
    End Property 'Items
    <Browsable(False)> _
        Public Shadows ReadOnly Property DrawMode()
        Get
            Return MyBase.DrawMode
        End Get
    End Property 'DrawMode
    <Browsable(False)> _
        Public Shadows ReadOnly Property DataSource()
        Get
            Return MyBase.DataSource
        End Get
    End Property 'Datasource
    <Browsable(False)> _
        Public Shadows ReadOnly Property DisplayMember()
        Get
            Return MyBase.DisplayMember
        End Get
    End Property 'DisplayMember
    <Browsable(False)> _
            Public Shadows ReadOnly Property ValueMember()
        Get
            Return MyBase.ValueMember
        End Get
    End Property 'ValueMember

    Protected Overrides Sub RefreshItem(ByVal index As Integer)
        MyBase.RefreshItem(index)
    End Sub

    Protected Overrides Sub SetItemsCore(ByVal items As System.Collections.IList)
        MyBase.SetItemsCore(items)
    End Sub

End Class


If you need anything else just ask :)
0
 
LVL 10

Expert Comment

by:Kinger247
ID: 17928684
Good work mohzedan !

TommyTwoPints: Remember to reference the System.ComponentModel (in case you haven't)
0
 
LVL 7

Expert Comment

by:Mohamed Zedan
ID: 17928933
Thanks .. hope it helps him ...
0
 
LVL 3

Author Comment

by:TommyTwoPints
ID: 17930122
Hi guys,

thankyou for your suggestions,

i am actually on holiday until next monday. I will put these suggestions into practice then and accept answer(s) once ive done so,

thank you all,

Tom

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now