Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / April 2008

Tip: Looking for answers? Try searching our database.

Stretch, Rotate, Rellocate ellipse in C# windows forms

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dan - 15 Apr 2008 22:26 GMT
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
Qu - 16 Apr 2008 04:34 GMT
> 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.
Dan - 16 Apr 2008 14:08 GMT
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

> 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
Peter Duniho - 16 Apr 2008 23:33 GMT
> 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
Dan - 17 Apr 2008 14:30 GMT
> Your question is fairly vague, so it'd be impossible to offer very  
> specific advice.
[quoted text clipped - 9 lines]
>
> 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
Peter Duniho - 17 Apr 2008 17:40 GMT
> 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  
[quoted text clipped - 3 lines]
> 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
Dan - 17 Apr 2008 21:30 GMT
> > 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  
[quoted text clipped - 18 lines]
>
> Pete

How do you create a highlighted object to select?
Peter Duniho - 17 Apr 2008 22:02 GMT
> 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
Dan - 17 Apr 2008 22:30 GMT
> > How do you create a highlighted object to select?
>
[quoted text clipped - 30 lines]
>
> 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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.