如何访问点坐标

时间:2012-10-22 08:03:26

标签: c++ winforms mouseevent

刚开始使用GUI Windows编程。我正在使用Visual Studio C ++ Wondows Forms。

我已经想出如何抓住鼠标坐标并将它们转换为双点坐标变量但是当我尝试访问X& Y值操纵它我得到......

error C2248: 'System::Drawing::Point::x' : cannot access private member declared in class 'System::Drawing::Point'

Point变量名为firstPoint,我正在尝试使用firstPoint.X和firstPoint.Y访问这些值。我想这不是正确的方法。

如何将值转换为int,以便我可以搞砸?转换:: ToInt32(firstPoint.x)是引发错误的原因。

谷歌搜索不断向我发送指针主题而不是点坐标主题。

要求的附加代码:

private:
    /// <summary>
    /// Required designer variable.
    unsigned char ucRed, ucGrn, ucBlu;
    bool drawing;
    Point firstPoint, finalPoint;
    //int iShape, iX1,iY1,iX2,iY2;

private: System::Void panel1_Paint_1(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) 
     {
        Graphics^ g = e->Graphics;

 //create an ellipse with
 //  Black color
 //  start position = firstPoint mouse coordinate
 //  width = difference between firstPoint and finalPoint, height = difference between firstPoint and finalPoint


        g->DrawEllipse(Pens::Black,firstPoint.x,firstPoint.Y,(finalPoint.X-firstPoint.X),(finalPoint.Y-firstPoint.Y));

1 个答案:

答案 0 :(得分:0)

使用带有大写字母的公共属性X和Y(不是:区分大小写),x和y是结构的私有成员变量。

http://msdn.microsoft.com/en-us/library/system.drawing.point.aspx

转换:: ToInt32(firstPoint.X)