Sorry for asking again. I spent today and I could not solve it.
I understand that I need to “update” the component by this.ExpireSolution(true);. But I do not know how to do this correctly, when I make the windows form in Visual Studio. I also tried to compile your code from c# component, and it worked, but due to my programming skills, I do not know how to do the same thing when designing visual studio windows form.
I have a windows form in visual studio and component that opens a windows form already. And I get the value after pressing a button.
How to do the same thing that you did with c# with track bar?
Also I uploaded .cs files, as they are not readable here.CurvatureAnalysis.Designer.txt (5.5 KB)
CurvatureAnalysis.txt (2.0 KB)
Mesh_Cuvartue_Component.txt (10.0 KB)
using System;
namespace Bob.Mesh_Analysis
{
public class Mesh_Cuvartue_Component : GH_Component
{
Utilities.CurvatureAnalysis frm;
string mPetras;
public override Guid ComponentGuid
{
get { return new Guid("{6a3c515d-7217-466e-b11c-bee5e8e03f3a}"); }
}
public Mesh_Cuvartue_Component() : base("Mesh Curvature", "Mesh Curvature", "Mesh Curvature", "Bob", "Mesh Analysis")
{
}
public override void AppendAdditionalMenuItems(ToolStripDropDown menu)
{
base.AppendAdditionalMenuItems(menu);
Menu_AppendSeparator(menu);
Menu_AppendItem(menu, "Learn more", Menu_LearnMore);
}
private void Menu_LearnMore(Object sender, EventArgs e)
{
DisplayForm();
}
public override void CreateAttributes()
{
m_attributes = new MySpecialComponentAttributes(this);
}
public void DisplayForm()
{
frm = new Utilities.CurvatureAnalysis();
Grasshopper.GUI.GH_WindowsFormUtil.CenterFormOnCursor(frm, true);
if (frm.ShowDialog() == DialogResult.Retry)
{
//Harvest values from form and assing them to local variables
mPetras = frm.messageForPetras;
}
this.ExpireSolution(true);
}
public class MySpecialComponentAttributes : GH_ComponentAttributes
{
public MySpecialComponentAttributes(IGH_Component Mesh_Cuvartue_Component) : base(Mesh_Cuvartue_Component) { }
public override GH_ObjectResponse RespondToMouseDoubleClick(GH_Canvas sender, GH_CanvasMouseEvent e)
{
((Mesh_Cuvartue_Component)Owner).DisplayForm();
return GH_ObjectResponse.Handled;
}
}
protected override Bitmap Icon { get { return null; } }
protected override void RegisterInputParams(GH_InputParamManager pManager)
{
........
}
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
.....
}
protected override void SolveInstance(IGH_DataAccess DA)
{
base.Message = "Double Click Me" + mPetras;
DA.SetData(3, mPetras);
this.ExpireSolution(true);
}
///////////////////////////////////////////////////////////////////Windows form://///////////////////////////////////////////////////////////////////////////
namespace Bob.Utilities
{
public partial class CurvatureAnalysis : Form
{
public string messageForPetras;
public int _value;
public CurvatureAnalysis()
{
InitializeComponent();
textBox1.Text = "0";
messageForPetras = "Error";
}
private void CurvatureAnalysis_Load(object sender, EventArgs e)
{
trackBar1.Minimum = 0;
trackBar1.Maximum = 100;
trackBar1.TickStyle = TickStyle.BottomRight;
trackBar1.TickFrequency = 10;
}
public void trackBar1_Scroll(object sender, EventArgs e)
{
label1.Text = trackBar1.Value.ToString();
}
// Here I get the value from Windows form slider:
private void OnShowAboutBox(object sender, EventArgs e)
{
MessageBox.Show("Bob - Grasshopper Add-On by Petras Vestartas 2016");
}
private void button1_Click(object sender, EventArgs e)
{
string message2 = " Ok";
messageForPetras = trackBar1.Value.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = DateTime.Now.ToString();
}
}
}