Created
March 23, 2012 21:24
-
-
Save sbaer/2175229 to your computer and use it in GitHub Desktop.
Using Custom Messages in a Get operation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Your "get" class will have code that looks like. | |
var go = new Rhino.Input.Custom.GetOption(); | |
var optDbl = new Rhino.Input.Custom.OptionDouble(12, 0,100); | |
go.SetCommandPrompt("Give me an option"); | |
go.SetCommandPromptDefault(""); | |
go.AcceptCustomMessage(true); // NEW!! | |
while (true) | |
{ | |
// need to clear and reset the command options every iteration because | |
// Rhino doesn't know that it needs to update the option string | |
go.ClearCommandOptions(); | |
go.AddOptionDouble("x", ref optDbl); | |
var result = go.Get(); | |
if( result== Rhino.Input.GetResult.Option) | |
continue; | |
if( result==Rhino.Input.GetResult.CustomMessage) | |
{ | |
// NEW - custom message was sent from somewhere | |
object msg = go.CustomMessage(); | |
if (msg != null) | |
{ | |
if (msg is int) | |
optDbl.CurrentValue = (int)msg; | |
else if (msg is double) | |
optDbl.CurrentValue = (double)msg; | |
} | |
continue; | |
} | |
break; | |
} | |
//////////////////////////// | |
// Somewhere else in code... | |
// Probably your button click event handler | |
... | |
private void Button_Click(object sender, EventArgs e) | |
{ | |
// NEW - send a custom message from anywhere and your Get() | |
// will retrieve it as a custom message | |
Rhino.Input.Custom.GetBaseClass.PostCustomMessage(10); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment