473,767 Members | 3,086 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6739
Qu
On Apr 16, 7:26*am, Dan <D...@discussio ns.microsoft.co mwrote:
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.Le ft)
{
mousePoint = /*Your Form/Groupbox Goes
Here*/.PointToClient( new Point(MousePosi tion.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.Si ze.Width / 2) and
(yourControl.Si ze.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*@discussion s.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.DrawEl lipse() 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.DrawEl lipse() 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.DrawEl lipse 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*@discussion s.microsoft.com >
wrote:
Yes I would like to use the Graphics.DrawEl lipse 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*@discussion s.microsoft.com >
wrote:
Yes I would like to use the Graphics.DrawEl lipse 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*@discussion s.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 "highlighte d". 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 "highlighte d" 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 "highlighte d", 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*@discussion s.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 "highlighte d". 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 "highlighte d" 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 "highlighte d", 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
3790
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 data that they were entering. Following is all exception information. Any thoughts much appreciated. Cheers
15
3896
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. now use task manager to see the GDI usage of the process. everything seems normal. now catch the ListView's scroller and start to move it downwards. you have to hold the constant speed so that the ListView is constantly repainted. look at the...
6
2577
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 communicated solely through static method and Invoke()'s However, when I close my second form, the first one (main window) is hiding under all the windows on the desktop. If I don't close the splash screen, then everything is fine. I tried...
4
464
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 the Constructor class MediaDriver {
2
5553
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 System.Windows.Forms.UnsafeNativeMethods.GetOpenFileName(OPENFILENAME_I ofn) 00000020 3:30:48 PM at
2
7845
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 in treeview i display the content item in axWebBrowser, i close the sub form normally when i close the main the following error is generated An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll ...
1
1216
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 complex groups of controls that need to interact with each other on a web page properly. My main page's design includes a number of different controls. On the left I have three groups of controls: A textbox with a button for searching (the...
0
2031
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 security exception when trying to run it from my webpage on my intranet. I have tried playing with the Code Access Security settings, but I can't get it to work. What do you think? Thanks,
21
3381
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 a zipcode that is unknown this form will open. I don't want users to modify any of this customers data until they close the zipcode form. Normally this can accomplished using a modal form, however this prevents me from opening a new copy of...
0
9575
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9407
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10170
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10014
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9841
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6656
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5425
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3931
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2808
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.