[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Visual Basic 2008. color dropdown menu

Posted on 2009-05-06
2
Medium Priority
?
510 Views
Last Modified: 2013-11-27
How do I make a color choosing dropdown just like the color dropdown in properties window?

I don't want the color dialog but a color dropdown.

Thanks!
0
Comment
Question by:NerdsOfTech
[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
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 24327970
Here is one version:
Imports System.Reflection
Public Class Form1
 
    Private KnownColors As New List(Of KnownColor)
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For Each C As Color In System.ComponentModel.TypeDescriptor.GetConverter(GetType(Color)).GetStandardValues
            If Not C.IsSystemColor Then
                KnownColors.Add(C.ToKnownColor)
            End If
        Next
        ComboBox1.DataSource = KnownColors
        ComboBox1.DrawMode = DrawMode.OwnerDrawFixed
    End Sub
 
    Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem
        Static width As Integer = 15
        e.DrawBackground()
        Dim KC As KnownColor = KnownColors(e.Index)
        Dim rc As New Rectangle(e.Bounds.X + 3, e.Bounds.Y + 3, width, e.Bounds.Height - 6)
        Using B As New SolidBrush(Color.FromKnownColor(KC))
            e.Graphics.FillRectangle(B, rc)
            e.Graphics.DrawRectangle(Pens.Black, rc)
        End Using
        e.Graphics.DrawString(KC.ToString, ComboBox1.Font, Brushes.Black, e.Bounds.X + (width + 6), e.Bounds.Y)
    End Sub
 
    Private Sub ComboBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged
        If ComboBox1.SelectedIndex <> -1 Then
            Dim kc As KnownColor = ComboBox1.SelectedValue
            Me.BackColor = Color.FromKnownColor(kc)
        End If
    End Sub
 
End Class

Open in new window

ColorDropDown.jpg
0
 
LVL 19

Author Closing Comment

by:NerdsOfTech
ID: 31578867
Another superb display of knowledge! Thank you Idle_Mind.

I will be asking another related question about this type of control in the future. I will post here to notify you.

=NerdsOfTech
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

656 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