Solved

System.Drawing.Color Converting to Integer?

Posted on 2009-04-07
8
2,905 Views
Last Modified: 2013-12-26
I am using the colordialog to set the backcolor of a text box.
I use VB 2008 as the front end and MS Access as the backend.  
Can you convert the color to an integer or something that can be saved to the database and then easily set when the value is retrieved?
Please provide an example.  When I click on links my IE crashes.
Thanks
This is what I use to get the color... no idea on how to save it.
ColorDialog1.AllowFullOpen = True
        ColorDialog1.AnyColor = True
        ColorDialog1.SolidColorOnly = False
        ColorDialog1.ShowHelp = True
        If ColorDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Me.txtCarColor.BackColor = ColorDialog1.Color
            Me.txtCarColor.Text = ColorDialog1.Color.Name.ToString
        End If

Open in new window

0
Comment
Question by:Sheritlw
  • 5
  • 2
8 Comments
 
LVL 9

Expert Comment

by:Sreedhar Vengala
ID: 24085253
0
 
LVL 9

Expert Comment

by:Sreedhar Vengala
ID: 24085318
POC should do for you:
            colorDialog1.ShowDialog();
            Color mycolor = colorDialog1.Color;
            int valuetoDb = mycolor.ToArgb();
           
            //save valuetodb into db

            Color getColorfrom = Color.FromArgb(valuetoDb);
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 24085324
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 9

Expert Comment

by:Sreedhar Vengala
ID: 24085326
VB version:
colorDialog1.ShowDialog()
Dim mycolor As Color = colorDialog1.Color
Dim valuetoDb As Integer = mycolor.ToArgb()

'save valuetodb into db

Dim getColorfrom As Color = Color.FromArgb(valuetoDb)
0
 

Author Comment

by:Sheritlw
ID: 24090293
How do I convert it back to the color from the integer?
0
 
LVL 47

Assisted Solution

by:Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs) earned 100 total points
ID: 24091828
0
 
LVL 9

Expert Comment

by:Sreedhar Vengala
ID: 24092192
Its all there in :

POC should do for you:
            colorDialog1.ShowDialog();
            Color mycolor = colorDialog1.Color;
            int valuetoDb = mycolor.ToArgb();
           
            //save valuetodb into db
            //Convert back to color
            Color getColorfrom = Color.FromArgb(valuetoDb);
0
 
LVL 9

Accepted Solution

by:
Sreedhar Vengala earned 400 total points
ID: 24092202
All there in (VB version)
VB version:
colorDialog1.ShowDialog()
Dim mycolor As Color = colorDialog1.Color
Dim valuetoDb As Integer = mycolor.ToArgb()

'save valuetodb into db
//Convert int back to color
Dim getColorfrom As Color = Color.FromArgb(valuetoDb)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

776 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