By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,296 Members | 1,476 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,296 IT Pros & Developers. It's quick & easy.

Forcing CreateGraphics.DrawRectangle to Draw rectangle on top

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
You need to be able to use controls that allow a userdraw mode
Oct 18 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.