Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:rhinocommonsamples:replacecolordialog [2015/09/14] (current)
Line 1: Line 1:
 +===== Sample: Replace Rhino'​s Color Picking Dialog =====
 +
 +===== C# =====
 +<code c#>
 +public class ReplaceColorDialogCommand : Command
 +{
 +  public override string EnglishName { get { return "​csReplaceColorDialog";​ } }
 +
 +  private ColorDialog m_dlg = null;
 +
 +  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
 +  {
 +    Dialogs.SetCustomColorDialog(OnSetCustomColorDialog);​
 +    return Result.Success;​
 +  }
 +
 +  void OnSetCustomColorDialog(object sender, GetColorEventArgs e)
 +  {
 +    m_dlg = new ColorDialog();​
 +    if (m_dlg.ShowDialog(null) == DialogResult.OK)
 +    {
 +      var c = m_dlg.Color;​
 +      e.SelectedColor = c;
 +    }
 +  }
 +}
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +Public Class ReplaceColorDialogCommand
 +  Inherits Command
 +  Public Overrides ReadOnly Property EnglishName() As String
 +    Get
 +      Return "​vbReplaceColorDialog"​
 +    End Get
 +  End Property
 +
 +  Private m_dlg As ColorDialog = Nothing
 +
 +  Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result
 +    Dialogs.SetCustomColorDialog(AddressOf OnSetCustomColorDialog)
 +    Return Result.Success
 +  End Function
 +
 +  Private Sub OnSetCustomColorDialog(sender As Object, e As GetColorEventArgs)
 +
 +    m_dlg = New ColorDialog()
 +    If m_dlg.ShowDialog(Nothing) = DialogResult.OK Then
 +      Dim c = m_dlg.Color
 +      e.SelectedColor = c
 +    End If
 +  End Sub
 +End Class
 +d Namespace
 +</​code>​
 +===== Python =====
 +<code python>
 +from Rhino import *
 +from Rhino.Commands import *
 +from Rhino.UI import *
 +from System.Windows.Forms import *
 +
 +m_dlg = None
 +
 +def RunCommand():​
 +  Dialogs.SetCustomColorDialog(OnSetCustomColorDialog)
 +  return Result.Success
 +
 +def OnSetCustomColorDialog(sender,​ e):
 +  m_dlg = ColorDialog()
 +  if m_dlg.ShowDialog(None) == DialogResult.OK:​
 +    c = m_dlg.Color
 +    e.SelectedColor = c
 +
 +if __name__ == "​__main__":​
 +  RunCommand()
 +</​code>​
 +
 +{{tag>​Developer rhinocommon}}
  
developer/rhinocommonsamples/replacecolordialog.txt ยท Last modified: 2015/09/14 (external edit)