본문 바로가기
ProjectMyPOS

VB6 - Using Common Dialog To Select Color

by 존버2028 2024. 6. 12.

1. 버튼의 배경색 바꾸기. 같은 방법으로 글씨색(ForeColor)도 바꿀 수 있다. 단, 일반 커맨드버튼은 글씨색을 바꿀 수 없으므로 체크박스를 사용해야 한다.

Private Sub cmd_backcolor_Click()  
  Dim pickedColor As Long
​
  ' Set Cancel to True
  CommonDialog1.CancelError = True
  On Error GoTo ErrHandler
​
  'Set the Flags property
  CommonDialog1.Flags = cdlCCRGBInit
​
  ' Display the Color Dialog box
  CommonDialog1.ShowColor
​
  pickedColor = CommonDialog1.Color
​
  ' Set the button's background color to selected color
  fm_New.cmd_user(cbo_button.ListIndex).BackColor = pickedColor
  ButtonArr(cbo_button.ListIndex).btnBackColor = pickedColor
​
ErrHandler:  
  ' User pressed the Cancel button  
End Sub