Set color for Button

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
nodochau
Pro Scripter
Posts: 89
Joined: Wed Jan 16, 2019 12:59 pm

Set color for Button

Post by nodochau » Fri Jul 17, 2020 4:30 pm

Hello All,
Are we able to set color for buttons in dialog?
Thanks

User avatar
Grovkillen
Automation Wizard
Posts: 497
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Re: Set color for Button

Post by Grovkillen » Fri Jul 17, 2020 5:42 pm

Yes I use that all the time. You can do it manually in the dialog editor or by invoking the dialog property commands.
Let>ME=%Script%

Running: 15.0.9
version history

nodochau
Pro Scripter
Posts: 89
Joined: Wed Jan 16, 2019 12:59 pm

Re: Set color for Button

Post by nodochau » Fri Jul 17, 2020 5:52 pm

I tried to find where to set the color for it manually but I couldn't find it though. I could change Font size, color...
but I want to change the color for buttons.
Also tried the setdialogobjectcolor for MSbutton and it did not work :(
Please show me how to do that

User avatar
Grovkillen
Automation Wizard
Posts: 497
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Re: Set color for Button

Post by Grovkillen » Sat Jul 18, 2020 10:16 am

Sorry, I use images to fake buttons.... I see that now.
Let>ME=%Script%

Running: 15.0.9
version history

User avatar
Grovkillen
Automation Wizard
Posts: 497
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Re: Set color for Button

Post by Grovkillen » Sat Jul 18, 2020 10:16 am

But better might be to use the awesome HTML element instead and change colors with HTML.
Let>ME=%Script%

Running: 15.0.9
version history

User avatar
JRL
Automation Wizard
Posts: 3337
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Set color for Button

Post by JRL » Sat Jul 18, 2020 4:10 pm

Microsoft for some unknown reason did not give buttons color flexibility. However, panels are a lot like buttons and they can change colors. Here's a way to use a panel as a button.

HighLight and UnHighLight are not technically needed to be able to execute the panel like a button, but I think they add to the user experience.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Caption = 'Demo'
  ClientHeight = 135
  ClientWidth = 210
  object Label1: TLabel
    Left = 48
    Top = 56
    Width = 109
    Height = 13
    Caption = 'Panel Button with color'
  end
  object Panel1: TPanel
    Left = 59
    Top = 86
    Width = 86
    Height = 27
    Caption = 'Ok'
    Color = 4227327
    ParentBackground = False
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,Panel1,OnMouseEnter,HighLight
AddDialogHandler>Dialog1,Panel1,OnMouseLeave,UnHighLight
AddDialogHandler>Dialog1,Panel1,OnClick,Msg

Show>Dialog1,

SRT>Msg
  MDL>Button Clicked
END>Msg

SRT>HighLight
  SetDialogProperty>Dialog1,Panel1,Color,4227300
END>HighLight

SRT>UnHighLight
  SetDialogProperty>Dialog1,Panel1,Color,4227327
END>UnHighLight

nodochau
Pro Scripter
Posts: 89
Joined: Wed Jan 16, 2019 12:59 pm

Re: Set color for Button

Post by nodochau » Mon Jul 20, 2020 11:23 am

JRL wrote:
Sat Jul 18, 2020 4:10 pm
Microsoft for some unknown reason did not give buttons color flexibility. However, panels are a lot like buttons and they can change colors. Here's a way to use a panel as a button.

HighLight and UnHighLight are not technically needed to be able to execute the panel like a button, but I think they add to the user experience.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Caption = 'Demo'
  ClientHeight = 135
  ClientWidth = 210
  object Label1: TLabel
    Left = 48
    Top = 56
    Width = 109
    Height = 13
    Caption = 'Panel Button with color'
  end
  object Panel1: TPanel
    Left = 59
    Top = 86
    Width = 86
    Height = 27
    Caption = 'Ok'
    Color = 4227327
    ParentBackground = False
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,Panel1,OnMouseEnter,HighLight
AddDialogHandler>Dialog1,Panel1,OnMouseLeave,UnHighLight
AddDialogHandler>Dialog1,Panel1,OnClick,Msg

Show>Dialog1,

SRT>Msg
  MDL>Button Clicked
END>Msg

SRT>HighLight
  SetDialogProperty>Dialog1,Panel1,Color,4227300
END>HighLight

SRT>UnHighLight
  SetDialogProperty>Dialog1,Panel1,Color,4227327
END>UnHighLight
Great! That is what I wanted.
Thanks a lot for your help.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts