473,387 Members | 1,364 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,387 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 1391
* "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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.