Go Premium for a chance to win a PS4. Enter to Win

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

CONVERT TEXTBOX BACKCOLOR TO RGB

Hi All,

I want to change textbox backcolor into RGB.

How could I do it ?

Thank you.
0
emi_sastra
Asked:
emi_sastra
  • 28
  • 24
1 Solution
 
Rahul GuptaCommented:
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
 
emi_sastraAuthor Commented:
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
 
CodeCruiserCommented:
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
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.

 
emi_sastraAuthor Commented:
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
 
CodeCruiserCommented:
Its an RGB value. Set it as a color of something and see what color it is.
0
 
emi_sastraAuthor Commented:
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
 
CodeCruiserCommented:
Why are you using the FromWin32?

CellBackColor is already of type Color and you are converting it again to color.
0
 
emi_sastraAuthor Commented:
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
 
CodeCruiserCommented:
What is oCell? And did you try

ColorTranslator.FromArgb(oCell.CellBackColor)

?
0
 
emi_sastraAuthor Commented:
-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
 
CodeCruiserCommented:
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
 
emi_sastraAuthor Commented:
I use oCell.CellBackColor, what's wrong with it ?

Thank you.
0
 
CodeCruiserCommented:
>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
 
emi_sastraAuthor Commented:
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
 
CodeCruiserCommented:
Sir its of type Color within OOCalc name space not withing System.Drawing namespace.
0
 
emi_sastraAuthor Commented:
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
 
CodeCruiserCommented:
No idea. If its coming back as Fuchsia then use that in condition.
0
 
emi_sastraAuthor Commented:
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
 
CodeCruiserCommented:
Yes.
0
 
emi_sastraAuthor Commented:
I have no idea how to code from the link you provided.

Thank you.
0
 
CodeCruiserCommented:
If you are getting the correct color name now then why you need that?
0
 
emi_sastraAuthor Commented:
Because I want to learn.

Thank you.
0
 
CodeCruiserCommented:
The type seems to be
Com.sun.util.color

See if you can find it.
0
 
emi_sastraAuthor Commented:
I have already :

Imports unoidl.com.sun.star.util

What should I do next ?

Thank you.
0
 
CodeCruiserCommented:
Use the color class similar to as you were using the system.drawing.color class
0
 
emi_sastraAuthor Commented:
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
 
CodeCruiserCommented:
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
 
emi_sastraAuthor Commented:
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
 
CodeCruiserCommented:
Ints should be correct. Get the Int value for each color and then just use that for condition in your switch statement.
0
 
emi_sastraAuthor Commented:
oCell.CellBackColor = 16776960 (this is aqua, not yellow).

Thank you.
0
 
CodeCruiserCommented:
How do you know?
0
 
emi_sastraAuthor Commented:
Please look at this link http://www.endprod.com/colors/

Thank you.
0
 
CodeCruiserCommented:
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
 
emi_sastraAuthor Commented:
-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
 
CodeCruiserCommented:
>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
 
emi_sastraAuthor Commented:
-Hence 16776960 is Yellow not Aqua.
Ok, but how to convert that number into color that known by system.drawing namespace
 
Thank you.
0
 
emi_sastraAuthor Commented:
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
 
CodeCruiserCommented:
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
 
emi_sastraAuthor Commented:
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
 
CodeCruiserCommented:
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
 
emi_sastraAuthor Commented:
- 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
 
CodeCruiserCommented:
>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
 
emi_sastraAuthor Commented:
ARGB and RGB, What A for ? When to use it ?

Thank you.
0
 
CodeCruiserCommented:
Its the Alpha component used for transparency. I think OOCalc does not use it where as System.Drawing.Color does
0
 
emi_sastraAuthor Commented:
Ok. When we are not using ooCalc then when will we use it ?
Not just use in spread sheet.

Thank you.
0
 
emi_sastraAuthor Commented:
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
 
CodeCruiserCommented:
To set transparency levels.
0
 
emi_sastraAuthor Commented:
Would you please provide samples or link.

Thank you.
0
 
CodeCruiserCommented:
Samples for what? Its not relevant here.
0
 
emi_sastraAuthor Commented:
I try to understand why OOCalc does not use A by understanding A.

Thank you.
0
 
emi_sastraAuthor Commented:
Thank you very much for your link.

Let me learn it firs. Be back again.

Thank you.
0
 
emi_sastraAuthor Commented:
Hi Code Cruiser,

Thank you very much for your help.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 28
  • 24
Tackle projects and never again get stuck behind a technical roadblock.
Join Now