[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 995
  • Last Modified:

To create a office like color picker in vb

I am trying to create a toolstrip color picker just like the MS office.  Base on this link:  http://www.codeproject.com/KB/selection/office2003colorpicker.aspx?display=PrintAll&fid=242507&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=26., there should be a standard control for this already.  From my vs2005,  the closest contol I see is the color dialog.  I am trying to trying to add this into my toolstrip but it says a color dialog cannot be added as a toolstripitem.  Is there a way to do this or I have to just custom build the control?
Dim toolStripColorPicker As New ColorDialog
 Me.ToolStrip1.Items.Add(toolStripColorPicker)

Open in new window

0
johnyu1997
Asked:
johnyu1997
  • 6
  • 5
2 Solutions
 
Wayne Taylor (webtubbs)Commented:
As the article states....

"The project has three controls that are available for use: OfficeColorPicker, ComboBoxColorPicker and ToolStripColorPicker. The first two controls are ToolBoxItem controls and therefore using them is as simple as dragging the control from the toolbox to your form. The third control is derived from ToolStripDropDownButton and will be discussed later in this article. All of these controls have a Color property to get or set the selected color of the control. Also, they have an event called SelectedColorChanged that occurs when the selected color of the control changes."

So download the demo project showing how each of the controls are used.

Wayne
0
 
johnyu1997Author Commented:
I did download the file already.  I just don't know how it works.  Plus it is all in Visual C++ which I don't have much experience.  
0
 
Wayne Taylor (webtubbs)Commented:
It's too big a project for me to re-write for you, but I suggest you download Visual Studio Express (C#) -> http://www.microsoft.com/express/download/

Then open up the source project and build the solution. This will create a DLL (in the \bin\Release\ folder), which you can then reference with your VB.Net windows project.

Then to add the item to your ToolStrip, do something like this....
Public Class Form1
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        Dim tcp As New OfficePickers.ColorPicker.ToolStripColorPicker()
        AddHandler tcp.SelectedColorChanged, AddressOf ColorChanged
        Me.ToolStrip1.Items.Add(tcp)
 
    End Sub
 
    Private Sub ColorChanged(ByVal sender As Object, ByVal e As EventArgs)
        MsgBox(DirectCast(sender, OfficePickers.ColorPicker.ToolStripColorPicker).Color.ToString)
    End Sub
 
End Class

Open in new window

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!

 
johnyu1997Author Commented:
I can kind of get it working already.  But I had already added an item called btncolorpalette into the toolstrip1 in the design time, how can I implement the code under the form1_load into the btncolorpalette_ click event?  
0
 
Wayne Taylor (webtubbs)Commented:
>>how can I implement the code under the form1_load into the btncolorpalette_ click event?  
I don't understand what you mean. Can you explain again, showing the code you are using?
0
 
johnyu1997Author Commented:
Here is the code.  When I click on the btncolorpalette (Item created in the design view), it will add another item called tcp which is the actual color picker.   The problem is I want to use btncolorpalette as the button for my color picker, not to add another button.
 Private Sub Btncolorpalette_ButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btncolorpalette.ButtonClick
        Dim tcp As New OfficePickers.ColorPicker.ToolStripColorPicker()
        AddHandler tcp.SelectedColorChanged, AddressOf ColorChanged
 
        Me.ToolStrip1.Items.Add(tcp)
 
    End Sub
 
    Private Sub ColorChanged(ByVal sender As Object, ByVal e As EventArgs)
        MsgBox(DirectCast(sender, OfficePickers.ColorPicker.ToolStripColorPicker).Color.ToString)
    End Sub

Open in new window

0
 
Wayne Taylor (webtubbs)Commented:
Do it as in the example I posted above, which adds the ColorPicker control to the ToolStrip when the form loads.
0
 
johnyu1997Author Commented:
If I have an image for this button, how can I use it?
0
 
Wayne Taylor (webtubbs)Commented:
Use what? The image? Simply set the Image property of the ToolStripColorPicker.
0
 
johnyu1997Author Commented:
I did set the image property but it looks like there is some kind of default image underneath which I can not get rid of.  Default.jpg is the one I cannot get rid of.  Color-fill.jpg is the image I want to add.  After.jpg is the image after I set the image property.  It looks like I cannot get rid of that "underscore".
color-fill.jpg
after.jpg
default.jpg
0
 
Wayne Taylor (webtubbs)Commented:
The first image looks OK, if the selected color is yellow.
The second image is wrong, because the selected color is Black, not yellow, as in your image.
The third image would look fine if you add your own image.

You need to use a different image, one preferably without the color bar at the bottom.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now