DrawRectangle over every control 
Author Message
 DrawRectangle over every control

Hi there-

It looks to me that what you want to do is get the graphics object of the
control itself and not of the parent form. Then you can do all of this
rendering when the control is drawn instead of drawing it on the form.  Hope
this helps!

Matthew Stoecker and Cat Francis
Visual Basic User Education
Microsoft Corporation

--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> Does any one know how to draw a rectangle over every control on a
> form? I'm creating movable controls, and I want a rectangle outline to
> follow the mouse until I drop it. Right now I'm using the
> CreateGraphics method of the ParentForm object of the Control. While
> this approach will create a rectangle on the form, When I pass over
> controls with the mouse the rectangle is drawn under the controls.
> These are the three overrides I've coded so far.

> Public Class VisualHand
> Inherits System.Windows.Forms.UserControl
> #Region " Windows Form Designer generated code "
> #End Region

>         Private xDif As Integer
>         Private yDif As Integer
>         Private myx As Integer
>         Private myy As Integer
>         Private g As Graphics
>         Private Sub VisualHand_MouseDown(ByVal sender As Object, ByVal
> e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown

>             If e.Button = MouseButtons.Left Then
>                 xDif = e.X - sender.Left
>                 yDif = e.Y - sender.Top
>                 myx = e.X
>                 myy = e.Y
>                 Dim r As New Rectangle()
>                 If g Is Nothing Then
>                     g = MyBase.ParentForm.CreateGraphics()
>                 End If
>                 g.Clear(Me.ParentForm.BackColor)
>                 r.X = sender.left + e.X - myx
>                 r.Y = sender.top + e.Y - myy
>                 r.Width = sender.Width
>                 r.Height = sender.Height
>                 g.DrawRectangle(New Pen(Drawing.Color.Black), r)

>             End If
>         End Sub

>         Private Sub VisualHand_MouseMove(ByVal sender As Object, ByVal
> e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
>             If e.Button = MouseButtons.Left Then
>                 Dim r As New Rectangle()
>                 If g Is Nothing Then
>                     g = MyBase.ParentForm.CreateGraphics()
>                 End If

>                 g.Clear(Me.ParentForm.BackColor)
>                 r.X = sender.left + e.X - myx
>                 r.Y = sender.top + e.Y - myy
>                 r.Width = sender.Width
>                 r.Height = sender.Height
>                 g.DrawRectangle(New Pen(Drawing.Color.Black), r)
>             End If
>         End Sub

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

>             If e.Button = MouseButtons.Left Then
>                 sender.Left = e.X - xDif
>                 sender.Top = e.Y - yDif
>                 g.Clear(Me.ParentForm.BackColor)
>                 Console.WriteLine(e.X)
>                 Console.Write(e.Y)
>             End If
>         End Sub
>     End Class



Sat, 29 Jan 2005 03:18:27 GMT  
 DrawRectangle over every control
The graphics object of the control will only let me draw within the
rectangle of the control. I'm looking for a solution that gives me a
plain to draw on that is above(z index) every control on the form and
that is the same size as the form. Does this plain exist?


Quote:
> Hi there-

> It looks to me that what you want to do is get the graphics object of the
> control itself and not of the parent form. Then you can do all of this
> rendering when the control is drawn instead of drawing it on the form.  Hope
> this helps!

> Matthew Stoecker and Cat Francis
> Visual Basic User Education
> Microsoft Corporation

> --
> This posting is provided "AS IS" with no warranties, and confers no rights.



> > Does any one know how to draw a rectangle over every control on a
> > form? I'm creating movable controls, and I want a rectangle outline to
> > follow the mouse until I drop it. Right now I'm using the
> > CreateGraphics method of the ParentForm object of the Control. While
> > this approach will create a rectangle on the form, When I pass over
> > controls with the mouse the rectangle is drawn under the controls.
> > These are the three overrides I've coded so far.

> > Public Class VisualHand
> > Inherits System.Windows.Forms.UserControl
> > #Region " Windows Form Designer generated code "
> > #End Region

> >         Private xDif As Integer
> >         Private yDif As Integer
> >         Private myx As Integer
> >         Private myy As Integer
> >         Private g As Graphics
> >         Private Sub VisualHand_MouseDown(ByVal sender As Object, ByVal
> > e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown

> >             If e.Button = MouseButtons.Left Then
> >                 xDif = e.X - sender.Left
> >                 yDif = e.Y - sender.Top
> >                 myx = e.X
> >                 myy = e.Y
> >                 Dim r As New Rectangle()
> >                 If g Is Nothing Then
> >                     g = MyBase.ParentForm.CreateGraphics()
> >                 End If
> >                 g.Clear(Me.ParentForm.BackColor)
> >                 r.X = sender.left + e.X - myx
> >                 r.Y = sender.top + e.Y - myy
> >                 r.Width = sender.Width
> >                 r.Height = sender.Height
> >                 g.DrawRectangle(New Pen(Drawing.Color.Black), r)

> >             End If
> >         End Sub

> >         Private Sub VisualHand_MouseMove(ByVal sender As Object, ByVal
> > e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
> >             If e.Button = MouseButtons.Left Then
> >                 Dim r As New Rectangle()
> >                 If g Is Nothing Then
> >                     g = MyBase.ParentForm.CreateGraphics()
> >                 End If

> >                 g.Clear(Me.ParentForm.BackColor)
> >                 r.X = sender.left + e.X - myx
> >                 r.Y = sender.top + e.Y - myy
> >                 r.Width = sender.Width
> >                 r.Height = sender.Height
> >                 g.DrawRectangle(New Pen(Drawing.Color.Black), r)
> >             End If
> >         End Sub

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

> >             If e.Button = MouseButtons.Left Then
> >                 sender.Left = e.X - xDif
> >                 sender.Top = e.Y - yDif
> >                 g.Clear(Me.ParentForm.BackColor)
> >                 Console.WriteLine(e.X)
> >                 Console.Write(e.Y)
> >             End If
> >         End Sub
> >     End Class



Sat, 29 Jan 2005 22:32:16 GMT  
 DrawRectangle over every control
Hi, Mark

The only plane above the form is the plane of the screen, which you can
draw on.

It sounds like the rectangle  you want to draw is only a temporary
artifact.  
Is the rectangle going to be of a fixed size, or were you going to use
{*filter*}banding?  

Take a look at the following Knowledge Base articles on {*filter*}banding in
VS.Net and see if they meet your needs:

http://www.*-*-*.com/ ;[LN];Q317479
http://www.*-*-*.com/ ;[LN];Q314394

If your application is restricted to Win2k and WinXP, you can try changing
the opacity of a form and use it as a drawable outline.  You can also
create a form with a transparent region to create a similar effect

Please let me know which way you are leaning and we can pursue it in more
depth.

HTH,

John Eikanger
Microsoft Visual Basic Team

This posting is provided AS IS with no warranties, and confers no rights.
(c) 2002 Microsoft Corporation.  All rights reserved.
--------------------

| Newsgroups: microsoft.public.dotnet.languages.vb
| Subject: Re: DrawRectangle over every control
| Date: 13 Aug 2002 07:32:16 -0700
| Organization: http://www.*-*-*.com/
| Lines: 93
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| The graphics object of the control will only let me draw within the
| rectangle of the control. I'm looking for a solution that gives me a
| plain to draw on that is above(z index) every control on the form and
| that is the same size as the form. Does this plain exist?
|
|
|


| > Hi there-
| >
| > It looks to me that what you want to do is get the graphics object of
the
| > control itself and not of the parent form. Then you can do all of this
| > rendering when the control is drawn instead of drawing it on the form.  
Hope
| > this helps!
| >
| > Matthew Stoecker and Cat Francis
| > Visual Basic User Education
| > Microsoft Corporation
| >
| > --
| > This posting is provided "AS IS" with no warranties, and confers no
rights.
| >


| > > Does any one know how to draw a rectangle over every control on a
| > > form? I'm creating movable controls, and I want a rectangle outline to
| > > follow the mouse until I drop it. Right now I'm using the
| > > CreateGraphics method of the ParentForm object of the Control. While
| > > this approach will create a rectangle on the form, When I pass over
| > > controls with the mouse the rectangle is drawn under the controls.
| > > These are the three overrides I've coded so far.
| > >
| > > Public Class VisualHand
| > > Inherits System.Windows.Forms.UserControl
| > > #Region " Windows Form Designer generated code "
| > > #End Region
| > >
| > >         Private xDif As Integer
| > >         Private yDif As Integer
| > >         Private myx As Integer
| > >         Private myy As Integer
| > >         Private g As Graphics
| > >         Private Sub VisualHand_MouseDown(ByVal sender As Object, ByVal
| > > e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
| > >
| > >             If e.Button = MouseButtons.Left Then
| > >                 xDif = e.X - sender.Left
| > >                 yDif = e.Y - sender.Top
| > >                 myx = e.X
| > >                 myy = e.Y
| > >                 Dim r As New Rectangle()
| > >                 If g Is Nothing Then
| > >                     g = MyBase.ParentForm.CreateGraphics()
| > >                 End If
| > >                 g.Clear(Me.ParentForm.BackColor)
| > >                 r.X = sender.left + e.X - myx
| > >                 r.Y = sender.top + e.Y - myy
| > >                 r.Width = sender.Width
| > >                 r.Height = sender.Height
| > >                 g.DrawRectangle(New Pen(Drawing.Color.Black), r)
| > >
| > >             End If
| > >         End Sub
| > >
| > >         Private Sub VisualHand_MouseMove(ByVal sender As Object, ByVal
| > > e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
| > >             If e.Button = MouseButtons.Left Then
| > >                 Dim r As New Rectangle()
| > >                 If g Is Nothing Then
| > >                     g = MyBase.ParentForm.CreateGraphics()
| > >                 End If
| > >
| > >                 g.Clear(Me.ParentForm.BackColor)
| > >                 r.X = sender.left + e.X - myx
| > >                 r.Y = sender.top + e.Y - myy
| > >                 r.Width = sender.Width
| > >                 r.Height = sender.Height
| > >                 g.DrawRectangle(New Pen(Drawing.Color.Black), r)
| > >             End If
| > >         End Sub
| > >
| > >         Private Sub VisualHand_MouseUp(ByVal sender As Object, ByVal e
| > > As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
| > >
| > >             If e.Button = MouseButtons.Left Then
| > >                 sender.Left = e.X - xDif
| > >                 sender.Top = e.Y - yDif
| > >                 g.Clear(Me.ParentForm.BackColor)
| > >                 Console.WriteLine(e.X)
| > >                 Console.Write(e.Y)
| > >             End If
| > >         End Sub
| > >     End Class
|



Sun, 30 Jan 2005 07:22:28 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Every Control on my Form just disappeared?????

2. to gain control of every pixel on the form

3. TabStop/Tabindex prob (skips control every other time)

4. how to automate loading custom control every time VB opens

5. Getting Every Control On A form

6. Run a function every 5/minutes with the timer control

7. Textbox control, how to change every character to UCASE

8. need to know if every one planning control

9. VB Oracle Data Control fail every 7th refresh

10. VB calles every Property Get on my Custom Control

11. font size changes on every control

12. Scanning every line of code

 

 
Powered by phpBB® Forum Software