TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
S J
NA
171
25.1k
If rectangle locations exceed draw rectangle within panel
Dec 4 2020 1:25 AM
hi
if(x>1000 || y>1000)
if these two coordinates went out of panel, bring that into 1000 location and draw rectangle within panel. donot allow to exceed in any case. I did something like this but iam getting negative values how to avoid that. Draw rectangle within panel only, check for all 4coordinates.
HighPreference
Assume
XCoordinate=1100 this is default my Panelsize(h=1013,w=1556)
Ycoordinate==1100
width=500
height=500
How this is drawn for if width and height exceed panelsize.
_displayobj.height = panel1.Height - _displayobj.yCoordinate - padding;
_displayobj.width = panel1.Width - _displayobj.xCoordinate - padding;
if(_displayobj.xCoordinate>1000 ||_displayobj.yCoordinate>1000 || _displayobj.height<0 ||_displayobj.width<0)
{
var a =(panel1.Location.X);
var b = panel1.Location.Y;
_displayobj.xCoordinate = a;
_displayobj.yCoordinate = b;
_displayobj.height = panel1.Height - 12 - padding;
_displayobj.width = panel1.Width - 274 - padding;
}
if (_displayobj.rectWidth > _displayobj.width || _displayobj.rectHeight > _displayobj.height)
{
_displayobj.rectHeight = Math.Min(_displayobj.rectHeight, _displayobj.height);
_displayobj.rectWidth = Math.Min(_displayobj.rectWidth, _displayobj.width);
string message = ("The given size and location are not fit to this area, so we are adjusting rectangle withine drawing area.If you want to draw press 'OK'");
string title = ("Please Confirm Your Action");
MessageBoxButtons buttons = MessageBoxButtons.OKCancel;
DialogResult result = MessageBox.Show(message, title, buttons);
if (result == DialogResult.OK)
{
Graphics g = panel1.CreateGraphics();
g.DrawRectangle(Pens.Black, _displayobj.xCoordinate, _displayobj.yCoordinate, _displayobj.rectWidth, _displayobj.rectHeight);
txtHeight.Text = Convert.ToString(_displayobj.rectHeight);
txtWidth.Text = Convert.ToString(_displayobj.rectWidth);
panel1.Invalidate();
}
else if (result == DialogResult.Cancel)
{
_displayobj._isValid = false;
return _displayobj._isValid;
}
}
i wrote this is for X,Y exceed panel.But showing error not able to draw
if(_displayobj.xCoordinate>1000 ||_displayobj.yCoordinate>1000)
var c = 1000;
var d = 1000;
int newx, newy;
_displayobj.xCoordinate = c;
_displayobj.yCoordinate = d;
newx = _displayobj.xCoordinate - _displayobj.rectWidth - padding;
newy = _displayobj.yCoordinate - _displayobj.rectHeight - padding;
help me how to solve this.please.
Thank u
Reply
Answers (
0
)
Submit feed product to Walmart by feed API .NET
How to Create Chart with huge data