[Closed] dotNet: textBox on return pressed event?
How would I go about using the enter button to call an event in the textBox object? This would be the same as the on editText entered do event. Any one?
I Pen,
That exactly what I’m looking for too. I think it have something to do with the controls.invoke methods but I don’t really know how it work…
http://msdn.microsoft.com/en-us/library/zyzhdc6b.aspx
fn Textbox_KeyPress s e=
(
if e.KeyChar == "\r" then
(
s.control.invoke (ref to the handler here)
)
)
Regard,
Martin Dufour
Thanks Martijn, I finaly found something on it in another post as well. That is a good example that you have there.
That a very good example, it may come handy when I’ll be working on my dotneteditor :applause:
but here’s what I really want :
try (Form1.close()) catch ()
(
Global Form1 = (Dotnetobject "System.Windows.Forms.Form")
Global PboxMap = (Dotnetobject "System.Windows.Forms.PictureBox")
Global PButton = (Dotnetobject "System.Windows.Forms.Button")
--//--
--//-- let say I want to manualy fire this handler when I click the PButton
--//-- and also, I don't want to call the function itself.
--//--
fn PboxMap_Click s e =
(
s.backcolor = (s.backcolor.fromargb 255 (random 100 255) (random 100 255) (random 100 255))
)
--//--
fn PButton_Click s e =
(
--((PboxMap.getType()).GetEvent "Click")
--PboxMap_Click PboxMap ""
)
--//--
fn Form1_Closed s e =
(
Form1 = undefined
PboxMap = undefined
PButton = undefined
gc light:true
)
--//-- Initialisation
PboxMap.backcolor = PboxMap.backcolor.navy
PboxMap.dock = PboxMap.dock.fill
--//--
PButton.backcolor = PButton.backcolor.fromargb 100 100 100 100
PButton.forecolor = PButton.forecolor.white
PButton.dock = PButton.dock.fill
PButton.text = "Fire PboxMap Click Handler"
PButton.font = (dotNetobject "System.Drawing.Font" PButton.font.name 14)
--//--
Form1.Text = "Test Form"
Form1.ShowIcon = true
Form1.ShowInTaskbar = false
Form1.TopMost = true
Form1.StartPosition = Form1.StartPosition.CenterScreen
Form1.ClientSize = dotNetObject "System.Drawing.Size" 200 100
--//--
Form1.Controls.Add PboxMap
PboxMap.Controls.Add PButton
--//--
dotnet.addeventhandler Form1 "closed" Form1_Closed
dotnet.addeventhandler PButton "Click" PButton_Click
dotnet.addeventhandler PboxMap "Click" PboxMap_Click
--//--
Form1.Show()
)
Thank for your help,
Martin
Still no go. I’m writting a scripted modifier and the enter key isn’t firing the keyDown event at all. The first print statement isn’t being fired so enter/return isn’t being seen. Also I can’t get tab to work although I don’t need it. Any ideas any one?
fn initTextBox tb=
(
tb.multiLine=true
tb.AcceptsReturn=true
tb.text=characterName
)
on characterNameDn keyDown arg do
(
print #keyDown
print arg.KeyCode
if arg.KeyCode==arg.KeyCode.enter then
(
print #yup
addPrefixToCharacter senderArg.text replacePrefix:true
)
)
I forgot to add to my initial reply that the AcceptsTab property needs to be set to true as well for this to work. Not sure why…
Martijn
Hi Paul,
I used the keypress and test for “\r” because of this, maybe your could give it a try …
fn Textbox_KeyPress s e=
(
if e.KeyChar == "\r" then
(
---
)
)
Martin Dufour
maybe this could help too…
fn textbox_MouseClick e s = (enableAccelerators = false)
Since they are both the same type of event (Click) and thus share the same event argument, you could simpy use PboxMap_Click s e to pass it on.
Another way could be to have each event call a function instead:
fn changeColor NetObj =
(
NetObj.backcolor = (NetObj.BackColor.FromArgb 255 (random 100 255) (random 100 255) (random 100 255))
)
fn PboxMap_Click s e = changeColor s
fn PButton_Click s e = changeColor s
Cheers,
Martijn
Since they are both the same type of event (Click) and thus share the same event argument, you could simpy use PboxMap_Click s e to pass it on.
That’s what I mean by …I don’t want to call the function itself…:wise:
Well, maybe it’s not possible in maxscript but from what I understand of the
controls.invoke method you can do something like this:
Theevent = (gather the event from the object ???) as a "system.delegate" witch is a ref to the event.
[b]PboxMap.invoke [/b]Theevent
not that I need this, just wanted to know
Martin Dufour
b.GetEvent(“Click”).GetRaiseMethod()[/b] should return a MethodInfo object. This object in turn has an Invoke method (MethodBase.Invoke Method (Object, Object[])). However, a call to GetRaiseMethod() will always return undefined in mxs, simply because the method is not created (there’s more info on this on the MSDN website.
As far as delegates go, I don’t think they can be created from within maxscript.
I am curious though as to what you are trying to do? Do you have a specific reason why you wouldn’t want to call the event handler directly?
Cheers,
Martijn