Hi, this is a really simple question I have been banging my head on a
brick wall over.
The program below changes the background colour of a form depending on
whether the cursor is inside a rectangle drawn on the form or not. It
works perfectly as shown below.
But it won't work if I change the values of scaleFactor, rotateFactor,
translateFactorX, translateFactorY in the program. I would like to
'correct' the values of e.X and e.Y in "OnMouseMove" so the program
works if I change scaleFactor, rotateFactor etc. I can't get it right
without using slow trigonometry and lots of if statements. I want to
use a matrix transformation similar to how I have done it with
"e.Graphics.ScaleTransform(scaleFactor, scaleFactor)" shown below -
but can't figure it out.
Please please please can someone help me out here.
Thank you in advance
Colin
Here is how to use this sourcecode
1. Launch VS2003
2. Select "New Project"
3. Select "Visual Basic Projects" and "Windows Application" and press
"OK"
4. Double click on "Form1" and paste in the following
Public Class Form1
Inherits System.Windows.Forms.Form
'[+] Windows Form Designer generated code
Dim rectOffX As Integer = 40 'rectangle offset on form
Dim rectOffY As Integer = 30
Dim scaleFactor As Integer = 1
Dim rotateFactor As Integer = 0
Dim translateFactorX As Integer = 0
Dim translateFactorY As Integer = 0
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
Dim container As Drawing2D.GraphicsContainer =
e.Graphics.BeginContainer
Dim myOriginalMatrix As Drawing2D.Matrix =
e.Graphics.Transform()
e.Graphics.ScaleTransform(scaleFactor, scaleFactor)
e.Graphics.RotateTransform(rotateFactor)
e.Graphics.TranslateTransform(translatefactorX,
translateFactorY)
'drawing stuff in here
Dim drawRect As Rectangle = New Rectangle(rectOffX, rectOffY,
30, 10)
e.Graphics.DrawRectangle(New Pen(Color.Blue), drawRect)
e.Graphics.EndContainer(container)
e.Graphics.Transform = myOriginalMatrix
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As
System.Windows.Forms.MouseEventArgs)
MyBase.OnMouseMove(e)
Dim cursorRect As Rectangle = New Rectangle(e.X, e.Y, 1, 1)
Dim drawRect As Rectangle = New Rectangle(rectOffX, rectOffY,
30, 10)
If drawRect.IntersectsWith(cursorRect) Then
Me.BackColor = Color.Yellow
Else
Me.BackColor = Color.Gray
End If
End Sub
End Class 4 2622
What kind of object is your rectangle.
Simple answer, see HitTest
"Colin McGuire" <co***********@lycos.co.uk> wrote in message
news:ab**************************@posting.google.c om... Hi, this is a really simple question I have been banging my head on a brick wall over. The program below changes the background colour of a form depending on whether the cursor is inside a rectangle drawn on the form or not. It works perfectly as shown below.
But it won't work if I change the values of scaleFactor, rotateFactor, translateFactorX, translateFactorY in the program. I would like to 'correct' the values of e.X and e.Y in "OnMouseMove" so the program works if I change scaleFactor, rotateFactor etc. I can't get it right without using slow trigonometry and lots of if statements. I want to use a matrix transformation similar to how I have done it with "e.Graphics.ScaleTransform(scaleFactor, scaleFactor)" shown below - but can't figure it out.
Please please please can someone help me out here. Thank you in advance Colin
Here is how to use this sourcecode
1. Launch VS2003 2. Select "New Project" 3. Select "Visual Basic Projects" and "Windows Application" and press "OK" 4. Double click on "Form1" and paste in the following
Public Class Form1 Inherits System.Windows.Forms.Form
'[+] Windows Form Designer generated code
Dim rectOffX As Integer = 40 'rectangle offset on form Dim rectOffY As Integer = 30
Dim scaleFactor As Integer = 1 Dim rotateFactor As Integer = 0 Dim translateFactorX As Integer = 0 Dim translateFactorY As Integer = 0
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) MyBase.OnPaint(e) Dim container As Drawing2D.GraphicsContainer = e.Graphics.BeginContainer Dim myOriginalMatrix As Drawing2D.Matrix = e.Graphics.Transform() e.Graphics.ScaleTransform(scaleFactor, scaleFactor) e.Graphics.RotateTransform(rotateFactor) e.Graphics.TranslateTransform(translatefactorX, translateFactorY)
'drawing stuff in here Dim drawRect As Rectangle = New Rectangle(rectOffX, rectOffY, 30, 10) e.Graphics.DrawRectangle(New Pen(Color.Blue), drawRect) e.Graphics.EndContainer(container) e.Graphics.Transform = myOriginalMatrix End Sub
Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs) MyBase.OnMouseMove(e) Dim cursorRect As Rectangle = New Rectangle(e.X, e.Y, 1, 1) Dim drawRect As Rectangle = New Rectangle(rectOffX, rectOffY, 30, 10) If drawRect.IntersectsWith(cursorRect) Then Me.BackColor = Color.Yellow Else Me.BackColor = Color.Gray End If End Sub End Class
What kind of object is your rectangle.
Simple answer, see HitTest
"Colin McGuire" <co***********@lycos.co.uk> wrote in message
news:ab**************************@posting.google.c om... Hi, this is a really simple question I have been banging my head on a brick wall over. The program below changes the background colour of a form depending on whether the cursor is inside a rectangle drawn on the form or not. It works perfectly as shown below.
But it won't work if I change the values of scaleFactor, rotateFactor, translateFactorX, translateFactorY in the program. I would like to 'correct' the values of e.X and e.Y in "OnMouseMove" so the program works if I change scaleFactor, rotateFactor etc. I can't get it right without using slow trigonometry and lots of if statements. I want to use a matrix transformation similar to how I have done it with "e.Graphics.ScaleTransform(scaleFactor, scaleFactor)" shown below - but can't figure it out.
Please please please can someone help me out here. Thank you in advance Colin
Here is how to use this sourcecode
1. Launch VS2003 2. Select "New Project" 3. Select "Visual Basic Projects" and "Windows Application" and press "OK" 4. Double click on "Form1" and paste in the following
Public Class Form1 Inherits System.Windows.Forms.Form
'[+] Windows Form Designer generated code
Dim rectOffX As Integer = 40 'rectangle offset on form Dim rectOffY As Integer = 30
Dim scaleFactor As Integer = 1 Dim rotateFactor As Integer = 0 Dim translateFactorX As Integer = 0 Dim translateFactorY As Integer = 0
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) MyBase.OnPaint(e) Dim container As Drawing2D.GraphicsContainer = e.Graphics.BeginContainer Dim myOriginalMatrix As Drawing2D.Matrix = e.Graphics.Transform() e.Graphics.ScaleTransform(scaleFactor, scaleFactor) e.Graphics.RotateTransform(rotateFactor) e.Graphics.TranslateTransform(translatefactorX, translateFactorY)
'drawing stuff in here Dim drawRect As Rectangle = New Rectangle(rectOffX, rectOffY, 30, 10) e.Graphics.DrawRectangle(New Pen(Color.Blue), drawRect) e.Graphics.EndContainer(container) e.Graphics.Transform = myOriginalMatrix End Sub
Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs) MyBase.OnMouseMove(e) Dim cursorRect As Rectangle = New Rectangle(e.X, e.Y, 1, 1) Dim drawRect As Rectangle = New Rectangle(rectOffX, rectOffY, 30, 10) If drawRect.IntersectsWith(cursorRect) Then Me.BackColor = Color.Yellow Else Me.BackColor = Color.Gray End If End Sub End Class
"CJ Taylor" <no****@blowgoats.com> wrote in message news:<10*************@corp.supernews.com>... What kind of object is your rectangle.
Simple answer, see HitTest
The rectangle is not an object, it is just painted on the form (see
code in original posting).
Colin
"CJ Taylor" <no****@blowgoats.com> wrote in message news:<10*************@corp.supernews.com>... What kind of object is your rectangle.
Simple answer, see HitTest
The rectangle is not an object, it is just painted on the form (see
code in original posting).
Colin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: x muzuo |
last post by:
Hi guys,
I have got a prob of javascript form validation which just doesnt work
with my ASP code. Can any one help me out please.
Here is the code:
{////<<head>
<title>IIBO Submit Page</title>...
|
by: MyNameIsnt |
last post by:
Can anyone tell me why, when I click on the buttons it register 2
characters on the display?
if you use the right mousebutton it works ok, but the buttons dont
flash??
it works fine without the...
|
by: Martin Streller |
last post by:
Hello,
The code below represents a simple ownerdrawn,
Listview class in C#. Its purpose is to avoid
the flicker of the MS ListView. So I can't fall
back to their one.
Does anybody know why I...
|
by: Serge Klokov |
last post by:
Hi!
1. Please, help with example "paint on form by mouse"
2. Below is my example, but it clear the line after each Refresh()... how to
fix?
3. How to draw the line in Mouse_Move event?
...
|
by: Marcelo |
last post by:
Greetings!
I develop a multiple forms application on Microsoft Visual Studio C++
..NET 2003. In this application, I draw into a picture box using the
Invalidate() method a very "heavy" graphic...
|
by: Colin McGuire |
last post by:
I apologize for posting yet another scrollbar question. Here is my
code. All I want is for a diagonal line to appear from coordinates
(0,0) to (width,height) in a usercontrol regardless of whether...
|
by: Colin McGuire |
last post by:
Hi, this is a really simple question I have been banging my head on a
brick wall over.
The program below changes the background colour of a form depending on
whether the cursor is inside a...
|
by: Brian Henry |
last post by:
Ok I've never implemented a snap location before so I dont really know what
im doing wrong here... anyways, I am making a custom slider control that
takes dates as its values instead of integers......
|
by: RobinS |
last post by:
I am drawing a rectangle on a picture that has already been drawn
on the graphics area (a user control). It works something like this:
//in the MouseDown event
m_isDragging = true;
m_oldX =...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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,...
|
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...
|
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...
| |