How to duplicate text of Edit control while editing? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
hiahkforum
Posts: 47
Joined: 08 Feb 2024, 04:21

How to duplicate text of Edit control while editing?

Post by hiahkforum » 11 Mar 2024, 11:31

How to duplicate text of Edit control while editing? Without clicking buttons and MsgBoxes, all changes only in current GUI, but Text control can be replaced with disabled Edit control.

Code: Select all

1::{
	Title := WinGetTitle('A')
	TableC := Gui('+AlwaysOnTop +ToolWindow', Title)
	TableC.Add('Text',, 'Batch name:')
	TableC.Add('Text',, 'Clones amount:')
	TableC.Add('Edit', 'vBatchName ym')
	TableC.Add('Edit', '+Number vClonesAmount w95')
	TableC.Add('Edit', '+Number vStartingPosition x190 y32 w22 Center', '1')
	TableC.Add('Text', 'xm', 'Duplicate of Edit control "vBatchName"') ; Here I want to duplicate the text of the "vBatchName" variable while editing.
	TableC.Add('Button', 'Default x8 y85 w102 h35', 'OK').OnEvent('Click', ProcessUserInput)
	TableC.Add('Button', 'x112 y85 w102 h35', 'Close').OnEvent('Click', Close)
	TableC.Show()

	ProcessUserInput(*) {
	}
	Close(*) {
		WinClose()
	}
}

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: How to duplicate text of Edit control while editing?

Post by mikeyww » 11 Mar 2024, 11:51

Code: Select all

#Requires AutoHotkey v2.0
g := Gui(, 'Mirror')
g.AddEdit('w300').OnEvent('Change', (ed, info) => mirror.Text := ed.Text)
mirror := g.AddEdit('wp ReadOnly')
g.Show

hiahkforum
Posts: 47
Joined: 08 Feb 2024, 04:21

Re: How to duplicate text of Edit control while editing?

Post by hiahkforum » 11 Mar 2024, 12:52

@mikeyww It works perfectly with one result from vBatchName, but how to combine 3 results at once and add vClonesAmount and vStartingPosition to it? I tried it myself, but I couldn't handle it. :oops:

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: How to duplicate text of Edit control while editing?  Topic is solved

Post by mikeyww » 11 Mar 2024, 13:31

Code: Select all

#Requires AutoHotkey v2.0
TableC := Gui('+AlwaysOnTop +ToolWindow', 'Mirror')
TableC.SetFont 's10'
TableC.AddText 'ym+3 w120', 'Batch name:'
TableC.AddText 'wp', 'Clones amount:'
TableC.AddEdit('vBatchName ym').OnEvent('Change', ed_Change)
TableC.AddEdit('+Number vClonesAmount w95').OnEvent('Change', ed_Change)
TableC.AddEdit('+Number vStartingPosition x+m w22 Center', 1).OnEvent('Change', ed_Change)
txt := TableC.AddEdit('xm w200 r3 ReadOnly')
ed_Change
TableC.Show 'y500'

ed_Change(ed := '', info := '') {
 g := TableC.Submit(0)
 txt.Text := g.BatchName '`r`n' g.ClonesAmount '`r`n' g.StartingPosition
}

hiahkforum
Posts: 47
Joined: 08 Feb 2024, 04:21

Re: How to duplicate text of Edit control while editing?

Post by hiahkforum » 11 Mar 2024, 14:41

@mikeyww Thanks, this is exactly what I wanted. :D But also I wanted to do math operations with g.StartingPosition and g.ClonesAmount, but got an error "Expected a Number but got an empty string.". Could you please tell me how to solve this? :roll:

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: How to duplicate text of Edit control while editing?

Post by mikeyww » 11 Mar 2024, 14:55

Code: Select all

If IsNumber(g.ClonesAmount) and IsNumber(g.StartingPosition)
 txt.Text := g.ClonesAmount + g.StartingPosition

hiahkforum
Posts: 47
Joined: 08 Feb 2024, 04:21

Re: How to duplicate text of Edit control while editing?

Post by hiahkforum » 11 Mar 2024, 16:59

Everything just :rainbow: beatiful. :thumbup:
Beatiful.png
Beatiful.png (11 KiB) Viewed 142 times

Post Reply

Return to “Ask for Help (v2)”