473,398 Members | 2,427 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,398 software developers and data experts.

Forcing CreateGraphics.DrawRectangle to Draw rectangle on top

Hello All,

I'm trying to solve a nagging problem. The goal is to draw a rectangle over
the top of all the other controls on a form. Specifically, over a ChartFX
control. The user would draw the rectangle using the right mouse button to
represent the area of the chart they want to zoom on. I haev been able to
draw the rectangle on a blank form but I cannot get it to draw on top of
other controls. I have pasted in the code i am using . Is there a way to
force the rectangle to draw on the 'top layer'? Or is there another method
to draw the rectangle entirely that will accomplish what I am looking for?

Thanks

Jeff

Imports System.Drawing
Imports System.Drawing.Drawing2D

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()Private Sub
InitializeComponent()
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(600, 558)
Me.Name = "Form1"
Me.Text = "Form1"

End Sub

#End Region
Dim f_zoomX As Integer
Dim f_zoomY As Integer
Dim f_zoomWidth As Integer
Dim f_zoomHeight As Integer

Public f_zoomRectPen As Pen

Public f_zoomRectPenSize As Integer = 2
Public f_zoomRectPenDashStyle As Drawing2D.DashStyle =
Drawing2D.DashStyle.Dash

Public f_zoomRectPenColor As Color = Color.Black
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown

Try

If e.Button = MouseButtons.Right Then

f_zoomX = e.X
f_zoomY = e.Y

f_zoomRectPen = New Pen(f_zoomRectPenColor, f_zoomRectPenSize)
f_zoomRectPen.DashStyle = f_zoomRectPenDashStyle

Cursor = Cursors.Cross

End If

Me.Refresh()

Catch exc As Exception

MessageBox.Show(exc.Message, " Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)

End Try

End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove

Try

If e.Button = MouseButtons.Right Then

Me.Refresh()

f_zoomWidth = e.X - f_zoomX
f_zoomHeight = e.Y - f_zoomY

Me.CreateGraphics.DrawRectangle(f_zoomRectPen, f_zoomX,
f_zoomY, f_zoomWidth, f_zoomHeight)
End If

GC.Collect()

Catch exc As Exception

If Err.Number = 5 Then Exit Sub

MessageBox.Show(exc.Message, " Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)

End Try

End Sub

Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp

Try

Cursor = Cursors.Default

Catch exc As Exception

MessageBox.Show(exc.Message, " Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)

End Try

End Sub

End Class
Oct 18 '06 #1
1 3726
You need to be able to use controls that allow a userdraw mode
Oct 18 '06 #2

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

Similar topics

1
by: Siri Krishna | last post by:
Hi, We have a custom control into which we add controls like labels and move them at run time. The problem we have is that when a child control is selected and moved, we draw a rectangle around it...
3
by: Colin McGuire | last post by:
Hi there. I have written a small procedure to draw various shapes on things. A bit of it is shown below. Private Sub drawShape(ByVal shapeType As Integer, ByRef g As Graphics) Select Case...
6
by: saunderl | last post by:
Hello Everyone, I'm trying to just play with managed VC++. I just want to draw a box on the form when it is clicked. Here is my click event handler System::Void Test_Click(System::Object^ ...
2
by: Dan | last post by:
I want to use Graphics.DrawRectangle to draw a rectangle at a position on the screen, and then a few seconds later, erase it. How do you erase a rectangle that you just drew (without affecting the...
7
by: Mark Ingram | last post by:
Hi, how can i draw a rounded rectange, with a border within a specified area? i.e. if i have a Rectangle with width and height of 100, how can i draw a rectange with 2 pixel border inside of the...
2
by: Jon Slaughter | last post by:
How does DrawRectangle position a rectangle w.r.t to the Rectangle passed? Lets suppose I use a pen of width 5. Are the lines centered about the passed Rectangle or is it enclosed or offset? Are...
8
by: pigeonrandle | last post by:
Hi, Please pity me, i am on a dial-up connection for the first time in 5 years :( ! Does anyone know how the resulting Graphics objects differ ...? What i really mean is can someone explain it...
4
by: =?Utf-8?B?SGFpcGluZw==?= | last post by:
I have a DrawRectangle() method to draw a rectangle on my UserControl. The OnPaint clear it. But in my reall application I cannot draw or update the rectangle in OnPain. I have to draw or update...
1
by: kummu4help | last post by:
hi, i want to draw rectangle based on mousedrag event. if user dragging the mouse, then the rectangle on the applet should increase or decrease basing on current mouse coordinates. i have the...
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: 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
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...
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
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...
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
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...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.