Solved

CONVERT TEXTBOX BACKCOLOR TO RGB

Posted on 2013-01-13
53
988 Views
Last Modified: 2013-08-19
Hi All,

I want to change textbox backcolor into RGB.

How could I do it ?

Thank you.
0
Comment
Question by:emi_sastra
  • 28
  • 24
53 Comments
 
LVL 4

Expert Comment

by:rahulgupta9x
ID: 38771839
Color.FromArgb Method (Int32, Int32, Int32)

Namespace:  System.Drawing


Besides this, have a look at this page.

http://msdn.microsoft.com/en-us/library/ed705s37.aspx
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38771850
I get :

oCell.CellBackColor = 16776960

I try this :
 

 Select Case oCell.CellBackColor  
                                                   
           Case Me.txtSecondShift.BackColor.ToArgb            
                  ' do something <----- it does not run this code

+            Me.txtSecondShift.BackColor      "{Name=Yellow, ARGB=(255, 255, 255, 0)}"      System.Drawing.Color                                                
                                                     
End Select

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38773977
ToArgb returns the Argb value of the color. You are using it as a condition. What are you trying to achieve?

http://msdn.microsoft.com/en-us/library/system.drawing.color.toargb.aspx
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38775560
Actually the cell backcolor is yellow, what  oCell.CellBackColor = 16776960 means, what color is it ?

How to compare the 16776960 with the control backcolor ?

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38775661
Its an RGB value. Set it as a color of something and see what color it is.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38775682
Dim oColor As Color = ColorTranslator.FromWin32(oCell.CellBackColor)
It get aqua, ARGB(0, 255, 255, 0), but it should be yellow back color not aqua.

Look at Row 8, Column AD

Very weird.

Thank you.
COLOR-PROBLEM.PNG
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38775692
Why are you using the FromWin32?

CellBackColor is already of type Color and you are converting it again to color.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38775709
I try :

 Select oCell.CellBackColor --> 16776960
            Case Color.White --> Specified cast is not valid.
            Case Color.Yellow
             Case Color.Lime
End Select

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38775726
What is oCell? And did you try

ColorTranslator.FromArgb(oCell.CellBackColor)

?
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38775749
-What is oCell?
Is the ooCalc Cell.

- ColorTranslator.FromArgb(oCell.CellBackColor)
Should be  Dim oColor As Color = ColorTranslator.FromWin32(oCell.CellBackColor)

But again it gets aqua not yellow.

Thank you
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38775773
That properties is not of type System.Drawing.Color. You need to use the OOCalc object model

http://www.openoffice.org/api/docs/common/ref/com/sun/star/table/CellProperties.html#CellBackColor
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38775803
I use oCell.CellBackColor, what's wrong with it ?

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38775826
>I use oCell.CellBackColor, what's wrong with it ?

The problem with it is that you get an error.


 Select oCell.CellBackColor --> Type: OOCALC.blablabla
            Case Color.White --> Type: System.Drawing.Color HENCE --> Specified cast is not valid.
            Case Color.Yellow
             Case Color.Lime
End Select
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38775856
You said :
CellBackColor is already of type Color and you are converting it again to color.

No error for oCell.CellBackColor, since you said it is a color then I try :

  Case Color.White  

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38775882
Sir its of type Color within OOCalc name space not withing System.Drawing namespace.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38775975
No problem with that. I've got the solution.

Dim a As Integer = Color.FromArgb(oCell.CellBackColor).A = 0
Dim r As Integer = Color.FromArgb(oCell.CellBackColor).R = 255
Dim g As Integer = Color.FromArgb(oCell.CellBackColor).G = 255
Dim b As Integer = Color.FromArgb(oCell.CellBackColor).B = 0

I ommit the A

Since RGB(255, 255, 0) = YELLOW

Dim oColor As Color = ColorTranslator.FromWin32(RGB(r, g, b)), IT GETS YELLOW.

 Select Case oColor
             Case Color.White
             Case Color.Yellow
             Case Color.Lime
             Case Color.Fuchsia

End Select

One more weird thing, when the color is light magenta (at oocalc), its name became Fuchsia (May be you called this is system.drawing...? Why are they different ?. How to compare with ooCalc Color ?

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38776119
No idea. If its coming back as Fuchsia then use that in condition.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38776716
Sorry, just back.

You do you mean by :

You need to use the OOCalc object model

http://www.openoffice.org/api/docs/common/ref/com/sun/star/table/CellProperties.html#CellBackColor

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38777771
Yes.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38777794
I have no idea how to code from the link you provided.

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38777852
If you are getting the correct color name now then why you need that?
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38777871
Because I want to learn.

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38777894
The type seems to be
Com.sun.util.color

See if you can find it.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38777912
I have already :

Imports unoidl.com.sun.star.util

What should I do next ?

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38777936
Use the color class similar to as you were using the system.drawing.color class
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38777951
I have function like below :

Function MakePropertyValue(ByVal cName, ByVal uValue) As Object

        Dim oPropertyValue As Object
        Dim oSM As Object

        oSM = CreateObject("com.sun.star.ServiceManager")
        oPropertyValue = oSM.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
        oPropertyValue.Name = cName
        oPropertyValue.Value = uValue

        MakePropertyValue = oPropertyValue

    End Function

Function MakeCellBorderLine(ByVal oDoc As Object, _
                                ByVal nColor As Integer, _
                                ByVal nInnerLineWidth As Integer, _
                                ByVal nOuterLineWidth As Integer, _
                                ByVal nLineDistance As Integer) As Object

        Dim oBorderLine As Object = CreateUnoStruct(oDoc, "com.sun.star.table.BorderLine")

        With oBorderLine
            .Color = nColor

            .InnerLineWidth = nInnerLineWidth
            .OuterLineWidth = nOuterLineWidth
            .LineDistance = nLineDistance
        End With
        Return oBorderLine
    End Function

What should I change to suit our need for the color ?

Thank you.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38777988
I have totally no idea what your needs are. You are setting colors in this unrelated code segment using Int and you expect it to be Yellow. Why
Cant you use int as your condition?
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38778042
I you see the screen shot. Its background color is yellow.
The weird thing is I get aqua color from the oCell.CellBackColor.

-Cant you use int as your condition?
Anything, as long as it is correct.

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38778318
Ints should be correct. Get the Int value for each color and then just use that for condition in your switch statement.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38778342
oCell.CellBackColor = 16776960 (this is aqua, not yellow).

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38778495
How do you know?
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38780864
Please look at this link http://www.endprod.com/colors/

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38782176
Did you read the title of that column where you read the 16776960? The title is MSAccess!


Check following site (RGB values for Yellow are 255, 255, 0)

http://www.shodor.org/stella2java/rgbint.html
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38782356
-Did you read the title of that column where you read the 16776960? The title is MSAccess!
I don't get it, I use VB to read from ooCalc.

-Check following site (RGB values for Yellow are 255, 255, 0)
I know, that's way I just get the RGB color, I ommit the A Color.

- http://www.shodor.org/stella2java/rgbint.html
I put that RGB to the textbox, its result is 16776960.

- The background of the page will change to the color selected.
I don't see any change.

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38782500
>I don't get it, I use VB to read from ooCalc.

The website you referred to says 16776960 is the code for Aqua in MSACCESS not in OOCALC.


>I know, that's way I just get the RGB color, I ommit the A Color.
>I put that RGB to the textbox, its result is 16776960.
>oCell.CellBackColor = 16776960 (this is aqua, not yellow).

Hence 16776960 is Yellow not Aqua.


>- The background of the page will change to the color selected.
>I don't see any change.

Background does change to yellow for me.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38782537
-Hence 16776960 is Yellow not Aqua.
Ok, but how to convert that number into color that known by system.drawing namespace
 
Thank you.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38782539
As you can see I use below code to get it.

  Dim a As Integer = Color.FromArgb(oCell.CellBackColor).A
                                                Dim r As Integer = Color.FromArgb(oCell.CellBackColor).R
                                                Dim g As Integer = Color.FromArgb(oCell.CellBackColor).G
                                                Dim b As Integer = Color.FromArgb(oCell.CellBackColor).B

                                                Dim oColor As Color = ColorTranslator.FromWin32(RGB(r, g, b))

Is there any other way ?

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38782620
If all you need is

Dim oColor As Color = ColorTranslator.FromWin32(RGB(r, g, b)), IT GETS YELLOW.

 Select Case oColor
             Case Color.White
             Case Color.Yellow
             Case Color.Lime
             Case Color.Fuchsia

End Select

Then why convert it to color?


 Select oCell.CellBackColor
             Case Color.White 'Find value for this
             Case 16776960
             Case Color.Lime 'Find value for this
             Case Color.Fuchsia 'Find value for this

End Select
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38782655
Please see below :
   
Select Case oColor ---> I can not use oCell.CellBackColor

                                                    Case txtFirstShift.BackColor
                                                        strShiftCodeDay = Me.txtFirstShift.Text & dteDateLog.DayOfWeek()
                                                        'Case Me.txtSecondShift.BackColor.ToArgb
                                                    Case txtSecondShift.BackColor
                                                        strShiftCodeDay = Me.txtSecondShift.Text & dteDateLog.DayOfWeek()
                                                    Case txtThirdShift.BackColor
                                                        strShiftCodeDay = Me.txtThirdShift.Text & dteDateLog.DayOfWeek()
                                                End Select

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38782776
txtFirstShift is a .NET textbox? If yes, you will struggle mate.

What you can do is

Dim oColor As Color

If oCell.CellBackColor = 16776960 Then
    oColor = Color.Yellow
Else ...
End If

Select Case oColor
...
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38782845
- txtFirstShift is a .NET textbox?
Yes, it is .net textbox

-If yes, you will struggle mate.
Why ?

Dim oColor As Color

-If oCell.CellBackColor = 16776960 Then
    oColor = Color.Yellow
Else ...
End If

Above code is not flexible, I don't want to use it that way.

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38783010
>If yes, you will struggle mate.
>Why ?
>Above code is not flexible, I don't want to use it that way.

Good luck then. Both of us have tried.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38792367
ARGB and RGB, What A for ? When to use it ?

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38792961
Its the Alpha component used for transparency. I think OOCalc does not use it where as System.Drawing.Color does
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38793525
Ok. When we are not using ooCalc then when will we use it ?
Not just use in spread sheet.

Thank you.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38793537
Ok. When we are not using ooCalc then when will we use it ?
Not just use in spread sheet.

When and How to use it ?

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38794042
To set transparency levels.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38795021
Would you please provide samples or link.

Thank you.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38795050
Samples for what? Its not relevant here.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38795088
I try to understand why OOCalc does not use A by understanding A.

Thank you.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 38795098
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38795129
Thank you very much for your link.

Let me learn it firs. Be back again.

Thank you.
0
 
LVL 1

Author Closing Comment

by:emi_sastra
ID: 39421990
Hi Code Cruiser,

Thank you very much for your help.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now