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

Custom controls

I've created a custom control that inherits
System.Windows.Forms.UserControl. It consists of three
labels next to each other. I am able to access the
control's properties and methods, but none of the events
I try to raise, such as MouseEnter or MouseDown, will
work wtih the control. What's the deal?
Nov 20 '05 #1
4 1393
* "Robert" <an*******@discussions.microsoft.com> scripsit:
I've created a custom control that inherits
System.Windows.Forms.UserControl. It consists of three
labels next to each other. I am able to access the
control's properties and methods, but none of the events
I try to raise, such as MouseEnter or MouseDown, will
work wtih the control. What's the deal?


Post your code.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
This is the code for the custom control:

Public Class SPCLabel
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

'UserControl 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 lblScore As
System.Windows.Forms.Label
Friend WithEvents lblNumber As
System.Windows.Forms.Label
Friend WithEvents lblStk As
System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
Me.lblScore = New
System.Windows.Forms.Label()
Me.lblNumber = New
System.Windows.Forms.Label()
Me.lblStk = New System.Windows.Forms.Label
()
Me.SuspendLayout()
'
'lblScore
'
Me.lblScore.BackColor =
System.Drawing.Color.WhiteSmoke
Me.lblScore.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle
Me.lblScore.Cursor =
System.Windows.Forms.Cursors.Hand
Me.lblScore.Font = New System.Drawing.Font
("Microsoft Sans Serif", 10.0!,
System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lblScore.ForeColor =
System.Drawing.Color.ForestGreen
Me.lblScore.Location = New
System.Drawing.Point(0, 16)
Me.lblScore.Name = "lblScore"
Me.lblScore.Size = New System.Drawing.Size
(40, 16)
Me.lblScore.TabIndex = 2
Me.lblScore.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter
'
'lblNumber
'
Me.lblNumber.BackColor =
System.Drawing.Color.Silver
Me.lblNumber.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle
Me.lblNumber.Cursor =
System.Windows.Forms.Cursors.Hand
Me.lblNumber.Font = New
System.Drawing.Font("Microsoft Sans Serif", 10.0!,
System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lblNumber.ForeColor =
System.Drawing.Color.DarkBlue
Me.lblNumber.Name = "lblNumber"
Me.lblNumber.Size = New
System.Drawing.Size(40, 16)
Me.lblNumber.TabIndex = 2
Me.lblNumber.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter
'
'lblStk
'
Me.lblStk.BackColor =
System.Drawing.Color.Gainsboro
Me.lblStk.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle
Me.lblStk.Cursor =
System.Windows.Forms.Cursors.Hand
Me.lblStk.Font = New System.Drawing.Font
("Microsoft Sans Serif", 8.0!,
System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lblStk.ForeColor =
System.Drawing.Color.SteelBlue
Me.lblStk.Location = New
System.Drawing.Point(0, 32)
Me.lblStk.Name = "lblStk"
Me.lblStk.Size = New System.Drawing.Size
(40, 16)
Me.lblStk.TabIndex = 2
Me.lblStk.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter
'
'SPCLabel
'
Me.Controls.AddRange(New
System.Windows.Forms.Control() {Me.lblScore,
Me.lblNumber, Me.lblStk})
Me.Name = "SPCLabel"
Me.Size = New System.Drawing.Size(40, 48)
Me.ResumeLayout(False)

End Sub

#End Region
#Region " Properties "

Dim PACEStatus As String
Dim PACEPosition As Byte

Property Number() As String
Get
Number = lblNumber.Text
End Get
Set(ByVal Value As String)
lblNumber.Text = Value
End Set
End Property

Property Score() As String
Get
Score = lblScore.Text
End Get
Set(ByVal Value As String)
lblScore.Text = Value
End Set
End Property

Property STK() As String
Get
STK = lblStk.Text
End Get
Set(ByVal Value As String)
lblStk.Text = Value
End Set
End Property

Property Status() As String
Get
Status = PACEStatus
End Get
Set(ByVal Value As String)
PACEStatus = Status
End Set
End Property

Property Position() As Byte
Get
Position = PACEPosition
End Get
Set(ByVal Value As Byte)
PACEPosition = Position
End Set
End Property

Function Clear()
lblNumber.Text = ""
lblScore.Text = ""
lblStk.Text = ""
End Function

#End Region

End Class
The control is built and appears in the toolbox, and I
place it on another form with an event handler like:

Private Sub Control1_MouseEnter(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Control1.MouseEnter
MessageBox.Show("CustomControl1")
End Sub

..... and nothing happens.

Thanks,
Rob

Nov 20 '05 #3
* "Robert" <an*******@discussions.microsoft.com> scripsit:
The control is built and appears in the toolbox, and I
place it on another form with an event handler like:

Private Sub Control1_MouseEnter(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Control1.MouseEnter
MessageBox.Show("CustomControl1")
End Sub

.... and nothing happens.


Does the control receive 'Click' events when clicked on an area not
covered by an embedded control?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
Does the control receive 'Click' events when clicked on an area notcovered by an embedded control?


No, Click events will not work either.
Nov 20 '05 #5

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

Similar topics

7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
6
by: Suzanne | last post by:
Hi all, I really hope someone out there can help me as I've been tearing my hair out on this one for a good while and I'm getting really frustrated now! My problem is this - my custom...
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
2
by: J R M | last post by:
I've developed a custom control (it's basically a drop-down list and then a couple of textboxes to include meta-data for the selection) that I'm embedding into another custom control (the idea is...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
1
by: rizwanahmed24 | last post by:
Hello i have created a custom control. i have placed two template controls on it. One is check box and second is picture box. The custom control also contain two picture boxes as property. These...
2
by: Ron | last post by:
I would like some more information on custom controls, what they can do and things like that, what you would use them for etc... Can anyone here share some examples of what you have used a custom...
1
by: Abdo Haji-Ali | last post by:
Previously I used to create user controls if I wanted to use a specific set of controls in multiple pages, however I want to deploy my control in other applications so I thought of creating custom...
5
by: gerry | last post by:
I am trying to create a custom container control that will only ever contain a specific type of control. At design time, when a control of a different type is added to the container I would like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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...
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,...

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.