当前位置: 首页 > 编程语言 > C#

访问发件人控件-C#分享

时间:2023-04-11 11:41:57 C#

访问发件人控件-C#如何访问发件人控件(即:更改位置等)?我在面板运行时创建了一些图片框,将它们的点击事件设置为一个函数。我想获取用户点击的图片框的位置。我也试过this.activecontrol但它没有用,并给出了放置在表单中的控件的位置。我使用以下代码:voidAddPoint(intGraphX,intGraphY,intPointNumber){stringPointNameVar="A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";字符串[]PointNameArr=PointNameVar.Split(',');PictureBoxpb_point=newPictureBox();pb_point.Name="Point"+PointNameArr[PointNumber];pb_point.Width=5;pb_point.Height=5;pb_point.BorderStyle=BorderStyle.FixedSingle;pb_point.BackColor=Color.DarkBlue;pb_point.Left=GraphX;//Xpb_point.Top=GraphY;//Ypb_point.MouseDown+=newMouseEventHandler(pb_point_MouseDown);pb_point.MouseUp+=newMouseEventHandler(pb_point_MouseUp);pb_point.MouseMove+=newMouseEventHandler(pb_point_MouseMove);pb_point.Click+=newEventHandler(pb_point_Clpanel1.Controls.Add(pb_point);}voidpb_point_Click(objectsender,EventArgse){MessageBox.Show(this.ActiveControl.Location.ToString());//返回另一个位置}AddPoint函数由循环调用,以创建多个PictureBoxes,这些PictureBoxes被赋予X、Y和Point编号。根据名为PointA...PointZ的代码创建PointA...PointZ在您的点击处理程序中,将“发件人”参数转换为PictureBox并检查其位置。voidpb_point_Click(objectsender,EventArgse){varpictureBox=(PictureBox)sender;MessageBox.Show(pictureBox.Location.ToString());发件人是你的图片框。管用就好:以上就是C#学习教程:Sender控件的获取-C#分享的全部内容,如果对大家有用还需要详细了解C#学习教程,希望大家点赞更多关注—voidpb_point_Click(objectsender,EventArgse){varpictureBox=(PictureBox)sender;MessageBox.Show(pictureBox.Location.ToString());//重新运行另一个控件的位置。}本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: