473,396 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Stretch, Rotate, Rellocate ellipse in C# windows forms

I would like to draw an ellipse on a windows form and through mouse drags
stretch, rotate and relocate the ellipse.

Thanks in advance - Dan

Jun 27 '08 #1
8 6693
Qu
On Apr 16, 7:26*am, Dan <D...@discussions.microsoft.comwrote:
I would like to draw an ellipse on a windows form and through mouse drags
stretch, rotate and relocate the ellipse.

Thanks in advance - Dan
Well, I don't know about drawing the ellipse or streching and
rotating, but I made this code recently to relocate an object. It's
not perfect (the object centre jumps to the mouse position), but it
works.

Call this on the MouseMove event of your object:

if (MouseButtons == MouseButtons.Left)
{
mousePoint = /*Your Form/Groupbox Goes
Here*/.PointToClient(new Point(MousePosition.X - /*Your Control Goes
here*/.Size.Width / 2, MousePosition.Y - /*Your Control Goes
here*/.Size.Height / 2));
/*Your Control Goes here*/.Location = mousePoint;
}

You could fix the above mentioned 'jump to mouse' by recording two
offset values on MouseDown, and adding them to the declaration of
mousePoint, replacing the (yourControl.Size.Width / 2) and
(yourControl.Size.Height /2).

On MouseDown ()
{
xOffset = MousePosition.X - /*Your Control Goes
here*/.Location.X;
yOffset = MousePosition.Y - /*Your Control Goes
here*/.Location.Y;
}

Hope this helps,
Qu.
Jun 27 '08 #2
Thanks Qu. This is part of the battle but I also really need the resizing and
rotating. Hopefully some other guru will be able to help be out.

Thanks - Dan

"Dan" wrote:
I would like to draw an ellipse on a windows form and through mouse drags
stretch, rotate and relocate the ellipse.

Thanks in advance - Dan
Jun 27 '08 #3
On Wed, 16 Apr 2008 06:08:01 -0700, Dan <Da*@discussions.microsoft.com>
wrote:
Thanks Qu. This is part of the battle but I also really need the
resizing and
rotating. Hopefully some other guru will be able to help be out.
Your question is fairly vague, so it'd be impossible to offer very
specific advice.

However, for the UI, handling the MouseDown, MouseMove, and MouseUp events
are useful for detecting and tracking mouse input.

For drawing the ellipse, assuming you just want to use the
Graphics.DrawEllipse() method, you'll probably want to set the Transform
property of the Graphics instance you're drawing into before calling
DrawEllipse(). The actual Matrix you use will be initialized based on the
user input, to apply the desired scaling, rotating, and translation.

Pete
Jun 27 '08 #4
>
Your question is fairly vague, so it'd be impossible to offer very
specific advice.

However, for the UI, handling the MouseDown, MouseMove, and MouseUp events
are useful for detecting and tracking mouse input.

For drawing the ellipse, assuming you just want to use the
Graphics.DrawEllipse() method, you'll probably want to set the Transform
property of the Graphics instance you're drawing into before calling
DrawEllipse(). The actual Matrix you use will be initialized based on the
user input, to apply the desired scaling, rotating, and translation.

Pete
Pete,

Yes I would like to use the Graphics.DrawEllipse method. What I was
envisioning was like you see for example in a paint application. You have a
figure on the screen. When it is highlighted you can "grab" the corner to
stretch the figure. I would like to do this with rotation as well and be able
to move the figure. Hope this explains it a bit better....

Thanks - Dan
Jun 27 '08 #5
On Thu, 17 Apr 2008 06:30:03 -0700, Dan <Da*@discussions.microsoft.com>
wrote:
Yes I would like to use the Graphics.DrawEllipse method. What I was
envisioning was like you see for example in a paint application. You
have a
figure on the screen. When it is highlighted you can "grab" the corner to
stretch the figure. I would like to do this with rotation as well and be
able
to move the figure. Hope this explains it a bit better....
Not really. I mean, I already figured out all of that, and my reply
provided as much information as would be relevant for that degree of
detail.

If you find yourself with specific problems while implementing the mouse
handling and/or ellipse drawing, then please feel free to post the code
you've got, with details about what you expected it to do, what it's
actually doing, and why that's not what you want.

Other than that, there's really nothing more to offer, short of simply
writing the code for you (not something I'm interested in doing right now,
but I suppose you never know...maybe someone else would be).

Pete
Jun 27 '08 #6


"Peter Duniho" wrote:
On Thu, 17 Apr 2008 06:30:03 -0700, Dan <Da*@discussions.microsoft.com>
wrote:
Yes I would like to use the Graphics.DrawEllipse method. What I was
envisioning was like you see for example in a paint application. You
have a
figure on the screen. When it is highlighted you can "grab" the corner to
stretch the figure. I would like to do this with rotation as well and be
able
to move the figure. Hope this explains it a bit better....

Not really. I mean, I already figured out all of that, and my reply
provided as much information as would be relevant for that degree of
detail.

If you find yourself with specific problems while implementing the mouse
handling and/or ellipse drawing, then please feel free to post the code
you've got, with details about what you expected it to do, what it's
actually doing, and why that's not what you want.

Other than that, there's really nothing more to offer, short of simply
writing the code for you (not something I'm interested in doing right now,
but I suppose you never know...maybe someone else would be).

Pete
How do you create a highlighted object to select?
Jun 27 '08 #7
On Thu, 17 Apr 2008 13:30:00 -0700, Dan <Da*@discussions.microsoft.com>
wrote:
How do you create a highlighted object to select?
That depends on how you're drawing the object in the first place. And on
what you mean by "highlighted". And on what you mean by "create".

Let's make some assumptions, since you haven't provided any details:

* We've got a data structure that's a collection of ellipses
* Each ellipse includes information as to size, rotation, and position
* We draw each ellipse based on this information whenever our form's
OnPaint() method is called
* We already have code in place to track mouse input
* By "highlighted" you simply mean the ellipse that is current being
adjusted by the user

Then, you'll want a way to identify which of the existing ellipses is the
one that's "highlighted", and when you are drawing all of the ellipses,
draw that one differently to indicate that it's been highlighted.

For the former, you could do it a variety of ways. Such as, keep a
reference to the "selected" object, and compare this "selected" reference
to the current object as you enumerate your collection of ellipses for
drawing. Alternatively, the objects themselves could maintain state with
respect to whether they are selected or not. You'd simply draw each
ellipse differently depending on this state. This alternative technique
has the advantage of more easily supporting multiple selected objects, but
has the disadvantage that your model data now also includes user-interface
state data.

I'm sorry if the above sounds vague. Unfortunately, it's not really
possible to provide specific advice without being presented with a
specific question.

Pete
Jun 27 '08 #8


"Peter Duniho" wrote:
On Thu, 17 Apr 2008 13:30:00 -0700, Dan <Da*@discussions.microsoft.com>
wrote:
How do you create a highlighted object to select?

That depends on how you're drawing the object in the first place. And on
what you mean by "highlighted". And on what you mean by "create".

Let's make some assumptions, since you haven't provided any details:

* We've got a data structure that's a collection of ellipses
* Each ellipse includes information as to size, rotation, and position
* We draw each ellipse based on this information whenever our form's
OnPaint() method is called
* We already have code in place to track mouse input
* By "highlighted" you simply mean the ellipse that is current being
adjusted by the user

Then, you'll want a way to identify which of the existing ellipses is the
one that's "highlighted", and when you are drawing all of the ellipses,
draw that one differently to indicate that it's been highlighted.

For the former, you could do it a variety of ways. Such as, keep a
reference to the "selected" object, and compare this "selected" reference
to the current object as you enumerate your collection of ellipses for
drawing. Alternatively, the objects themselves could maintain state with
respect to whether they are selected or not. You'd simply draw each
ellipse differently depending on this state. This alternative technique
has the advantage of more easily supporting multiple selected objects, but
has the disadvantage that your model data now also includes user-interface
state data.

I'm sorry if the above sounds vague. Unfortunately, it's not really
possible to provide specific advice without being presented with a
specific question.

Pete
Thanks Pete. As you can tell I am new to C# and will try to work my way
through this. Thanks for your time.
Jun 27 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Greg Bacchus | last post by:
Hi, I'm getting an exception that really has me stumped. It's sporadic at best, it's only happened a handful of times. This particular time it happened when the user pressed 'Alt-S' to save the...
15
by: Wiktor Zychla | last post by:
today we've found a critical issue regarding the ListView from Windows.Forms. it was confirmed on several machines with Win2K and XP. here's the problem: create a ListView with about 50000 rows....
6
by: Ayende Rahien | last post by:
Excetremely annoying problem, I've an application with a long startup time. So I created another form with my logo in it to as a splash screen. The splash screen is run from another thread and is...
4
by: Bilo | last post by:
I have a Windows Forms Class MainGUI I have declared MainGUI maingui; public System.ComponentModel.Container components = new Container(); in the Class I call another class MediaDriver with...
2
by: fperfect13 | last post by:
Hi, I have the folowing exception Exception : System.NullReferenceException: Object reference not set to an instance of an object. 00000019 3:30:48 PM at...
2
by: Raed Sawalha | last post by:
i have a windows form(Main) with listview, when click an item in listview i open other window form (Sub) which generate the selected item from parent window in as treeview items when click any item...
1
by: William Sullivan | last post by:
I've spent plenty of time building windows forms, but I'm working on a web project now. I've scanned a few ASP NET books, checked out some tutorials, but I am unable to figure out how to lay out...
0
by: gxl034000 | last post by:
Hi, I have been trying to use a .net Forms control in my webpage to open up an application(notepad) on the client. The control works fine when embedded in a windows form, but I keep getting a...
21
by: Dan Tallent | last post by:
In my application I have a form (Customer) that I want to be able to open multiple copies at once. Within this form I have other forms that can be opened. Example: ZipCode. When the user enters...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.