2009-08-06 5 views

답변

4

요컨대, 그렇습니다. MSDN에서 다루는 내용은 here입니다. 문제는 그것이 Color을 통해 이루어지지 않는다는 것입니다. BGR 세트로 값을 처리해야합니다. 즉, 각 정수는 00BBGGRR이라는 색으로 구성되어 있으므로 파란색으로 16을 왼쪽, 파란색으로 8 시프트하고 빨간색을 사용합니다. 그대로".

내 VB는 짜증,하지만 C#으로, 보라색 추가 :

Using dlg As ColorDialog = New ColorDialog 
    Dim purple As Color = Color.Purple 
    Dim i As Integer = (((purple.B << &H10) Or (purple.G << 8)) Or purple.R) 
    dlg.CustomColors = New Integer() { i } 
    dlg.ShowDialog 
End Using 
+0

+1 비트 단위 조작. 나는 MS가이 자료를 더 잘 문서화하기를 바란다. –

2

기존의 예에 오류가 있습니다 :

using (ColorDialog dlg = new ColorDialog()) 
    { 
     Color purple = Color.Purple; 
     int i = (purple.B << 16) | (purple.G << 8) | purple.R; 
     dlg.CustomColors = new[] { i }; 
     dlg.ShowDialog(); 
    } 

반사경이 유사한 것을 저를 보장합니다.

purple.B는 정수가 아닌 바이트이므로 8 또는 16 비트로 시프트하면 아무 것도 수행하지 않습니다. 각 바이트는 먼저 그것을 이동하기 전에 정수로 형변환되어야합니다. 이 (VB.NET)와 같은 뭔가 : 당신이 1 개 이상의 사용자 정의 색상을 원한다면

Dim CurrentColor As Color = Color.Purple 
Using dlg As ColorDialog = New ColorDialog 
    Dim colourBlue As Integer = CurrentColor.B 
    Dim colourGreen As Integer = CurrentColor.G 
    Dim colourRed As Integer = CurrentColor.R 
    Dim newCustomColour as Integer = colourBlue << 16 Or colourGreen << 8 Or colourRed 
    dlg.CustomColors = New Integer() { newCustomColour } 
    dlg.ShowDialog 
End Using 
4

, 당신은이 작업을 수행 할 수 있습니다

  'Define custom colors 
    Dim cMyCustomColors(1) As Color 
    cMyCustomColors(0) = Color.FromArgb(0, 255, 255) 'aqua 
    cMyCustomColors(1) = Color.FromArgb(230, 104, 220) 'bright pink 

    'Convert colors to integers 
    Dim colorBlue As Integer 
    Dim colorGreen As Integer 
    Dim colorRed As Integer 
    Dim iMyCustomColor As Integer 
    Dim iMyCustomColors(cMyCustomColors.Length - 1) As Integer 

    For index = 0 To cMyCustomColors.Length - 1 
     'cast to integer 
     colorBlue = cMyCustomColors(index).B 
     colorGreen = cMyCustomColors(index).G 
     colorRed = cMyCustomColors(index).R 

     'shift the bits 
     iMyCustomColor = colorBlue << 16 Or colorGreen << 8 Or colorRed 

     iMyCustomColors(index) = iMyCustomColor 
    Next 

    ColorDialog1.CustomColors = iMyCustomColors 
    ColorDialog1.ShowDialog() 
0

SIMPLFIED을

하면 (개비 기준) 목표 맞춤 색상의 ARGB를 알고 있다면 다음을 사용하십시오.

'    Define custom colors 
ColorDialog1.CustomColors = New Integer() {(255 << 16 Or 255 << 8 Or 0), _ 
              (220 << 16 Or 104 << 8 Or 230), _ 
              (255 << 16 Or 214 << 8 Or 177)} 
ColorDialog1.ShowDialog() 
'where colors are (arbg) 1: 0,255,255 [aqua] 
'      2: 230,104,220 [bright pink] 
'      3: 177,214,255 [whatever] 
관련 문제