This is the context of my controls:
/*
Form
StatusStrip
ToolStripStatusLabel
TableLayoutPanel
MyGenioView
*/
So, MyGenioView is intercepting the MouseMove event handler. The code that is already there is for a rubber band rectangle. So I have:
public void MyMouseMove(Object sender, MouseEventArgs e)
{
Point ptCurrent = new Point(e.X, e.Y);
// If we "have the mouse", then we draw our lines.
if (m_bHaveMouse)
{
// If we have drawn previously, draw again in
// that spot to remove the lines.
if (m_ptLast.X != -1)
{
MyDrawReversibleRectangle(m_ptOriginal, m_ptLast);
}
// Update last point.
m_ptLast = ptCurrent;
// Draw new lines.
MyDrawReversibleRectangle(m_ptOriginal, ptCurrent);
}
// New code here
}
What I can't get my head around is that I want to set the value of statusStrip1.statusLabel from the MyGenioView MouseMove handler. I can't work out how to do it.
The code I want to use is:
OdGePoint3d pt = GetWorldCoordinates(ptCurrent);
String strCoordinate = String.Format("{0},{1}", ptCurrent.X, ptCurrent.Y);
But what is the right way to feed it to the main forms statusStrip object?
Thanks for your help.
Update:
I know how to set the text of a statusStrip label object. That is not my issue. My issue is related to context of my mouse handler event and it's relationship to the form. Please see the context of the controls as described at the start of the question. The comments so far have not taken that into account.
This is the current place in the form that I create the MyGenioView object (that receives the mouse handler):
private void viewToolStripMenuItem_Click(object sender, EventArgs e)
{
OdDbDatabase TDDatabase = m_oGenioView.GetDatabase();
if (m_oGenioViewCtrl != null)
m_oGenioViewCtrl.DeleteContext();
tableLayoutPanel.RowCount = 1;
tableLayoutPanel.ColumnCount = 1;
m_oGenioViewCtrl = new MyGenioView();
m_oGenioViewCtrl.TDDatabase = TDDatabase;
m_oGenioViewCtrl.ResetDevice(true);
m_oGenioViewCtrl.Dock = DockStyle.Fill;
m_oGenioViewCtrl.Margin = new Padding(1);
tableLayoutPanel.Controls.Add(m_oGenioViewCtrl);
}
You have multiple options to update status:
Action<Point>in the user controlStatusUpdateevent in the user controlthis.ParentFormis your parent form and you can find the target control usingControlscollection or by making it public in the form.The first two options are much better because decouple your control from the form and your user control can be used on many forms and other containers this way. Providing a way of updating status is up to container.
The best option is creating and consuming the event.
1- Inject an
Action<Point>in the user controlInject an
Action<Point>in the user control and use it inMouseMove. To do so, put this in User Control:And put this code on Form:
2- Create a
StatusUpdateevent in the user controlCreate a
StatusUpdateevent in the user control and raise it inMouseMoveand consume the event in the form. Also you can use theMouseMoveevent itself.To do so, put this code in user control:
And then put in form, put this code: