[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Color Dialog in VB Express Edition

Posted on 2006-05-02
7
Medium Priority
?
402 Views
Last Modified: 2012-08-13
Hi,

when using this code in VB Express Edition:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Dim MyDialog As New ColorDialog()
MyDialog.AllowFullOpen = False
MyDialog.ShowHelp = True
MyDialog.Color = TextBox1.ForeColor

If (MyDialog.ShowDialog() = Windows.Forms.DialogResult.OK) Then
TextBox1.ForeColor = MyDialog.Color
End If

End Sub

the variable TextBox1.ForeColor gets the value of "{Name=ffff8040,
ARGB=(255, 255, 128, 64)}".
How do I extract only the last three numbers in a string in a format like
"255 128 064"?
I need this result stored in a string.

Thanks for help
Thomas
0
Comment
Question by:moellert
  • 3
  • 2
  • 2
7 Comments
 
LVL 19

Expert Comment

by:Rimvis
ID: 16583982
Try this:

    Dim iColor As Long
    Dim iRed As Byte, iGreen As Byte, iBlue As Byte
   
    CommonDialog1.ShowColor
   
    iColor = CommonDialog1.Color
   
    iRed = iColor Mod 256
    iGreen = ((iColor And &HFF00) / 256&) Mod 256&
    iBlue = (iColor And &HFF0000) / 65536
   
    MsgBox iRed & " " & iGreen & " " & iBlue
0
 
LVL 19

Assisted Solution

by:Rimvis
Rimvis earned 600 total points
ID: 16584004
I forgot it's Vb.NET. Should be:

        ColorDialog1.ShowDialog()  

        MsgBox(String.Format("{0} {1} {2}", ColorDialog1.Color.R, ColorDialog1.Color.G, ColorDialog1.Color.B))
           
0
 
LVL 2

Author Comment

by:moellert
ID: 16586499
I have used this code now:

        Dim iColor As Long
        Dim iRed As Byte, iGreen As Byte, iBlue As Byte

        ColorDialog1.ShowDialog()

        iColor = ColorDialog1.Color

        iRed = iColor Mod 256
        iGreen = ((iColor And &HFF00) / 256&) Mod 256&
        iBlue = (iColor And &HFF0000) / 65536

        MsgBox(String.Format("{0} {1} {2}", ColorDialog1.Color.R, ColorDialog1.Color.G, ColorDialog1.Color.B))

I get an error message (line "   iColor = ColorDialog1.Color") stating that it is not possible to convert type of 'System.Drawing.Color' to type 'Long'
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 400 total points
ID: 16587267
*** NOT FOR POINTS ***

Rimvis has already given you the answer...

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            Dim c As Color = ColorDialog1.Color
            Dim s As String = String.Format("{0} {1} {2}", c.R, c.G, c.B)
            MsgBox(s)
        End If
    End Sub
0
 
LVL 2

Author Comment

by:moellert
ID: 16587919
This code works perfectly. Thanks a lot.
@Idle Mind: Your code looks very different from the one Rimvis posted. I am not very good in VB programming so I could not decide if the solution Rimvis posted already solves my problem. Your does without any modification.

So who should get the points?
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16588380
The important part is that the Color() class exposes the values you need via the R(), G(), and B() properties...which is what Rimvis demonstrated in his line of code:

     MsgBox(String.Format("{0} {1} {2}", ColorDialog1.Color.R, ColorDialog1.Color.G, ColorDialog1.Color.B))

I just took that already provided information and placed into a snippet of code that shows it in a different form (easier to read IMHO).

I didn't really provide any NEW information to the thread, just a variation of the same info.

This is why I think the points should go to Rimvis...    =)
0
 
LVL 2

Author Comment

by:moellert
ID: 16588487
I have splitted the points to be fair to both of you. Thanks a lot again.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month17 days, 14 hours left to enroll

831 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