I seek to @override
the DrawLine
method of the Graphics
class, but I am unsure if this is possible?
I seek to put a validation in the method so that it stops drawing at a certain Y variable that I would provide, effectively adding a new parameter to the method.
Anyone got some experience or advice on overriding that specific method?
I am unsure about this rproblem so I dont know if I can simply do @Override
and then give it a validation as it is plotting the separate pixel points.
Thanks.
You just need a separate method. Put it wherever you want:
void CheckedDrawLine(Graphics g, int x1, int y1, int x2, int y2, int stopY) {
// Do the validation, draw the line
}
And you could make it into an extension method by sticking it in a static class
:
void CheckedDrawLine(this Graphics g, int x1, int y1, int x2, int y2, int stopY) {
// Do the validation, draw the line
}
to do a g.CheckedDrawLine(...)
instead of a CheckedDrawLine(g, ...)
.
It is not possible for normal code to replace method that is not designed to be replaced/overriden.
You can
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.