Home > Net >  how to replace the names controls with each other
how to replace the names controls with each other

Time:12-31

Button1.Name = cbName
Button2.Name = pickName

how can i make this work? be replaced by Button1.Name will be named Button2 (pickName) and Button2 will be named Button1 (cbName)

but so as not to tell me that it already exists controls in Form.

Button1.Name = Button1.Name.Replace("cb", "pick")

that is, after I execute the order, I expect to have

Button1.Name = pickName
Button2.Name = cbName

CodePudding user response:

The question is not clear: are you just trying to do a name swap? In this case:

'Original names
Button1.Name = "cbName"
Button2.Name = "pickName"
Console.WriteLine("Case A: {0}, {1}", {Button1.Name, Button2.Name})

'Name swap
Dim tmp As String = Button1.Name
Button1.Name = Button2.Name
Button2.Name = tmp
Console.WriteLine("Case B: {0}, {1}", {Button1.Name, Button2.Name})

Output:

Output

  • Related