[英]How do I merge these into 1 function
Trying to code clean;尝试编码干净; the goal is to create rounded .Net objects.目标是创建圆形的 .Net 对象。
I would prefer to have 1 call regardless of object type as I figure this will get out of hand quickly.无论对象类型如何,我都希望进行 1 次调用,因为我认为这会很快失控。
//object fails as parameter Width/Height unavailable - there is likely a good way to merge these three void function 1 call but I "can't be asked" - Remo 2019
public void buildOval(int oWDelta, int oHDelta, PictureBox o)
{
System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
gp.AddEllipse(0, 0, o.Width - oWDelta, o.Height - oHDelta);
Region rg = new Region(gp);
o.Region = rg;
}
public void buildOval(int oWDelta, int oHDelta)
{
System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
gp.AddEllipse(0, 0, this.Width - oWDelta, this.Height - oHDelta);
Region rg = new Region(gp);
this.Region = rg;
}
public void buildOval(int oWDelta, int oHDelta, Button o)
{
System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
gp.AddEllipse(0, 0, o.Width - oWDelta, o.Height - oHDelta);
Region rg = new Region(gp);
o.Region = rg;
}
#endregion
... ...
You could the following.您可以进行以下操作。 From your code, it looks like the parameter o
is a Control.从您的代码看来,参数o
是一个控件。 For example例如
public void buildOval(int oWDelta, int oHDelta, Control o)
{
using (System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath())
{
gp.AddEllipse(0, 0, o.Width - oWDelta, o.Height - oHDelta);
Region rg = new Region(gp);
o.Region = rg;
}
}
You could now call them the methods as您现在可以将它们称为方法
buildOval(wDeltaValue,oDeltaValue,this); // when called for Form
buildOval(wDeltaValue,oDeltaValue,pictureBoxInstance);
buildOval(wDeltaValue,oDeltaValue,buttonInstance);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.