How to create a record button?

How to create a dontnet button to display one image when pressed once, and another - when pressed second time(for example red and grey)

		--btn = dotnetobject "Button"
                dotnetcontrol btn "System.Windows.Forms.Button" pos:[667,101] width:15 height:15 border:false
		--btn.FlatStyle = btn.FlatStyle.Flat
                btn.flatstyle = dotnetobject "System.Windows.Forms.FlatStyle" Flat
 
                btn.Location = dotNetObject "System.Drawing.Point" 1 prevh
               i=1
             if i==1 then
             (
                btn.image = (StringToImage record_red)
                i=0
             ) 
             else 
                btn.image = (StringToImage record_grey)

just to use that if, or there is a more correct way?

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
barigazy's picture

;)

Is this simple enought

try(destroyDialog ::bgaRoll)catch()
rollout bgaRoll "• • •"
(
	fn defColor r g b = (dotNetClass "System.Drawing.Color").FromArgb r g b
	fn defFont fName fSize = (dotNetObject "System.Drawing.Font" fName fSize ((dotNetClass "System.Drawing.FontStyle").bold))
	local C1 = defColor 100 100 100, C2 = defColor 0 0 0, C3 = defColor 150 20 20, C4 = defColor 220 220 220, Fnt = defFont "Verdana" 30
	dotnetcontrol btn "CheckBox" pos:[10,10] width:180 height:80
 
	on bgaRoll open do
	(
		btn.BackColor = C1 ; btn.ForeColor = C2 ; btn.font = Fnt
		btn.Text = "• REC" ; btn.Appearance = btn.Appearance.Button
		btn.TextAlign = btn.TextAlign.MiddleCenter ; btn.FlatStyle = btn.FlatStyle.Flat
		btn.FlatAppearance.BorderSize = 10 ; btn.Cursor = (dotNetClass "Cursors").Hand
       btn.FlatAppearance.CheckedBackColor = btn.FlatAppearance.MouseDownBackColor = C3
		--btn.FlatAppearance.MouseOverBackColor = C1
		--dnCBtn.FlatAppearance.BorderColor = C2		
	)
	on btn MouseUp arg do
	(
		if btn.checked then btn.forecolor = C4 else btn.forecolor = C2
	)
)
createDialog bgaRoll 200 100 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

barigazy

barigazy's picture

:)

And finaly I add example with ContextMenuStrip that you asked in previous post
Here we go. Just press RMB over button

try(destroyDialog ::bgaRoll)catch()
rollout bgaRoll "• • •"
(
	fn defColor r g b = (dotNetClass "System.Drawing.Color").FromArgb r g b
	fn defFont fName fSize = (dotNetObject "System.Drawing.Font" fName fSize ((dotNetClass "System.Drawing.FontStyle").bold))
	fn defSize x y = (dotNetObject "System.Drawing.Size" x y)
	fn defPoint x y = (dotNetObject "System.Drawing.Point" x y)
	local C1 = defColor 100 100 100, C2 = defColor 0 0 0, C3 = defColor 150 20 20, C4 = defColor 220 220 220
	local Fnt1 = defFont "Verdana" 30, Fnt2 = defFont "Verdana" 6.5
 
	fn defCnxMenu dnCM items:#("Record1", "Record2", "Record3", "Record4") = 
	(
		fn defTSMI itmStr = 
		(
			local itm = dotNetObject "ToolStripMenuItem" itmStr ; itm.BackColor = C1
			itm.AutoSize = off ; itm.Size = defSize 80 20 ; itm.Font = Fnt2 ; itm
		)
		dnCM.RenderMode = dnCM.RenderMode.Professional
		dnCM.ShowCheckMargin = dnCM.ShowImageMargin = dnCM.AutoSize = off
		dnCM.Size = defSize 81 84 ; dnCM.Opacity = 0.85d0
		dnCM.Items.AddRange (for i in items collect (defTSMI i))
		dotNet.addEventHandler dnCM "ItemClicked" \
		(
			fn cnxMenuClick s e =
			(
				case e.ClickedItem.Text of
				(
					("Record1"): print "Start Record1"
					("Record2"): print "Start Record2"
					("Record3"): print "Start Record3"
					("Record4"): print "Start Record4"
				)
			)	
		)			
	)
 
 
	dotnetcontrol btn "CheckBox" pos:[10,10] width:180 height:80
 
	on bgaRoll open do
	(
		local dnCM = dotNetObject "ContextMenuStrip" ; defCnxMenu dnCM
 
		btn.BackColor = C1 ; btn.ForeColor = C2 ; btn.font = Fnt1
		btn.Text = "• REC" ; btn.Appearance = btn.Appearance.Button
		btn.TextAlign = btn.TextAlign.MiddleCenter ; btn.FlatStyle = btn.FlatStyle.Flat
		btn.FlatAppearance.BorderSize = 10 ; btn.Cursor = (dotNetClass "Cursors").Hand
       btn.FlatAppearance.CheckedBackColor = btn.FlatAppearance.MouseDownBackColor = C3
		btn.ContextMenuStrip = dnCM
		--btn.FlatAppearance.MouseOverBackColor = C1
		--dnCBtn.FlatAppearance.BorderColor = C2		
	)
	on btn MouseUp arg do
	(
		if btn.checked then btn.forecolor = C4 else btn.forecolor = C2
		if arg.Button == arg.Button.Right do (btn.ContextMenuStrip.Show btn (defPoint arg.x arg.y))
	)
)
createDialog bgaRoll 200 100 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

barigazy

barigazy's picture

edit

If you need to change items count or font size in CMS you need also adjust height and width

--in this lines
itm.Size = defSize 80 20
dnCM.Size = defSize 81 84

barigazy

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.