【发布时间】:2016-05-27 12:12:14
【问题描述】:
这是我的控件的上下文:
/*
Form
StatusStrip
ToolStripStatusLabel
TableLayoutPanel
MyGenioView
*/
所以,MyGenioView 正在拦截 MouseMove 事件处理程序。已有的代码用于橡皮筋矩形。所以我有:
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
}
我无法理解的是我想从MyGenioView MouseMove 处理程序中设置statusStrip1.statusLabel 的值。我不知道该怎么做。
我要使用的代码是:
OdGePoint3d pt = GetWorldCoordinates(ptCurrent);
String strCoordinate = String.Format("{0},{1}", ptCurrent.X, ptCurrent.Y);
但是将它提供给主要表单statusStrip 对象的正确方法是什么?
感谢您的帮助。
更新:
我知道如何设置 statusStrip 标签对象的文本。那不是我的问题。我的问题与我的鼠标处理程序事件的上下文以及它与表单的关系有关。请参阅问题开头所述的控件上下文。到目前为止,cmets 还没有考虑到这一点。
这是我在 form 中创建MyGenioView 对象(接收鼠标处理程序)的当前位置:
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);
}
【问题讨论】:
-
在设计时为其添加标签并设置标签的
Text。 -
当您使用设计器将状态标签添加到 StatusStrip 时,您将获得它的标识符名称。它只是 toolStripStatusLabel1.Text = strCoordinate;相当不清楚这是哪里出了问题。
-
@RezaAghaei,我已经有了“statusLabel”。我不知道如何从给定的上下文中访问它。
-
如果是同一个表格,直接用
this.toolStripStatusLabel1.Text = "Some text"; -
@HansPassant 我知道这一点。重点是无法从 MyGenioView 访问变量 toolStripStatusLabel。
标签: c# winforms onmousemove statusstrip