473,770 Members | 4,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() 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.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'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.Diagnos tics.DebuggerSt epThrough()Priv ate Sub
InitializeCompo nent()
'
'Form1
'
Me.AutoScaleBas eSize = 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_zoomRectPenSi ze As Integer = 2
Public f_zoomRectPenDa shStyle As Drawing2D.DashS tyle =
Drawing2D.DashS tyle.Dash

Public f_zoomRectPenCo lor As Color = Color.Black
Private Sub Form1_MouseDown (ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles MyBase.MouseDow n

Try

If e.Button = MouseButtons.Ri ght Then

f_zoomX = e.X
f_zoomY = e.Y

f_zoomRectPen = New Pen(f_zoomRectP enColor, f_zoomRectPenSi ze)
f_zoomRectPen.D ashStyle = f_zoomRectPenDa shStyle

Cursor = Cursors.Cross

End If

Me.Refresh()

Catch exc As Exception

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

End Try

End Sub

Private Sub Form1_MouseMove (ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles MyBase.MouseMov e

Try

If e.Button = MouseButtons.Ri ght Then

Me.Refresh()

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

Me.CreateGraphi cs.DrawRectangl e(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", MessageBoxButto ns.OK,
MessageBoxIcon. Error)

End Try

End Sub

Private Sub Form1_MouseUp(B yVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles MyBase.MouseUp

Try

Cursor = Cursors.Default

Catch exc As Exception

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

End Try

End Sub

End Class
Oct 18 '06 #1
1 3776
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
2573
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 to identify it as selected. The DrawRectangle works fine when the child controls is on left half of the custom control area but fails to draw the rectangle when moved to right half of the custom control. When placed some where in between we see...
3
10329
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 shapeType Case 1 : g.DrawRectangle(New Pen(Color.Black), 0, 0, 50, 10) Case 2 'draw a circle Case 3 'draw a triangle Case 4 'draw other shape Case 5 'draw other shape
6
3932
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^ sender, System::EventArgs^ e) { // Create a Graphics object for the Control. Graphics* g = this->CreateGraphics() ;
2
3382
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 original background of the window(s) behind the rectangle)? Thanks... Dan
7
10692
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 original one? (the current attempts all draw the border just outside of the original rectangle). At the moment im using the following code, but it allows the rectangle to grow - which i definately dont want!
2
3506
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 there ways to change the default behavior? The reason I ask is cause when I do g.DrawRectangle(P, this.ClientRectangle) for drawing a rectangle as the border for a control(button) and the width of P is larger than 1(or even when its not it...
8
12777
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 to me please? A) protected static extern IntPtr GetWindowDC (IntPtr hWnd );
4
2048
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 it in my own method. What shoudl I do? Another question: how to draw just one pixel. The coe snippet do not work. theGraphicsToDrawPoints.DrawRectangle(pen, xCoordinate, yCoordinate, 1, 1); // Draw 2 by 2 sqare....
1
5133
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 following code. in the following code i am using SelectionArea class which extends a canvas on which i am performing drawing operation. i am using image variable in this class for double buffering to reduce flickering and to save the applet's previous...
0
9592
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
10059
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...
1
10005
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9871
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
8887
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7416
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6679
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
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3972
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

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.