[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

VB.NET Linetype combo box

Posted on 2006-11-12
10
Medium Priority
?
398 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Assisted Solution

by:Kinger247
Kinger247 earned 600 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
 
LVL 6

Assisted Solution

by:Marv-in
Marv-in earned 600 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 800 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

650 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