GDI+ user control

lprayaga

New member
Joined
Apr 23, 2005
Messages
1
Programming Experience
1-3
Hi;

I am a newcomer. I have a question, I created a rectangle control, can drag it and drop it on a form. I can also in the form double click this new instance of the control and put some code in it, and at rrun time the code gets executed.

However my question is can I put this click event in the control itself? I tried all I could but no help.

Appreciate any help.

Here is my code:

Imports System.Drawing.Drawing2D

Imports System.Drawing.Color

Imports System.Drawing.Graphics

Public Class RectangleCtrl2

Inherits System.Windows.Forms.UserControl

#
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

'UserControl1 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.

Friend WithEvents Button1 As System.Windows.Forms.Button

<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()

Me.Button1 = New System.Windows.Forms.Button

Me.SuspendLayout()

'

'Button1

'

Me.Button1.Location = New System.Drawing.Point(32, 48)

Me.Button1.Name = "Button1"

Me.Button1.Size = New System.Drawing.Size(80, 48)

Me.Button1.TabIndex = 0

Me.Button1.Text = "Button1"

'

'RectangleCtrl2

'

Me.Controls.Add(Me.Button1)

Me.Name = "RectangleCtrl2"

Me.ResumeLayout(False)

End Sub

#End Region



Public p1 As New System.Drawing.Pen(System.Drawing.Color.Blue)

Public br1 As New SolidBrush(System.Drawing.Color.Red)

Public reg As Region

Public gp As GraphicsPath

Public side, outside As Boolean

Public localMPos As Point

Event labelClick(ByVal sender As Object, ByVal e As System.EventArgs)







Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)

' Dim br As New LinearGradientBrush(Me.ClientRectangle, m_StartColor, m_EndColor, m_GradientMode)

p1.Width = 6.0



e.Graphics.FillRectangle(br1,
Me.ClientRectangle)

e.Graphics.DrawRectangle(p1,
Me.ClientRectangle)

' gp.AddRectangle(Me.ClientRectangle)

' reg = New Region(gp)



'p1.Dispose()

gp = New GraphicsPath

'G.DrawRectangle(Pen1, RectSPC)

gp.AddRectangle(Me.ClientRectangle)

reg =
New Region(gp)

MsgBox(
Me.ClientRectangle.X)

MyBase.OnPaint(e)

End Sub







Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)

Dim mp As New Point(e.X, e.Y)

If Me.ClientRectangle.Contains(e.X, e.Y) Then

MsgBox("hi")

End If

MsgBox(Me.ClientRectangle.X)



If Me.ParentForm.MouseButtons.Left Then

MsgBox("hi")

End If

If e.Button = MouseButtons.Right Then

MsgBox("hi")

End If

If ParentForm.MouseButtons.Left Then

MsgBox("hi")

End If

If reg.IsVisible(mp) Then

'If e.Button = MouseButtons.Right Then

MsgBox("You clicked the right button")

'Else

'MsgBox("You did not click the right button")

End If

MyBase.OnMouseDown(e)

End Sub

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

Dim mp As New Point(e.X, e.Y)





If reg.IsVisible(mp) Then

'If e.Button = MouseButtons.Right Then

MsgBox("You clicked the right button")

'Else

'MsgBox("You did not click the right button")

End If

MyBase.OnMouseDown(e)



End Sub

Public Sub ParentForm_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown

MsgBox("hello")

If ParentForm.MouseButtons.Left Then

MsgBox("hi")

End If

If e.Button = MouseButtons.Right Then

MsgBox("hello")

End If



MyBase.OnMouseDown(e)

End Sub



End
Class

 
Back
Top