create my own control having combination of multiple controls?

Innovative1

Member
Joined
Feb 24, 2013
Messages
8
Programming Experience
Beginner
I want to create my own control having combination of multiple controls......and also use it multiple time at run-time with different behavior.
 
can i pass value to user control from vb.net project...means user control should perform operation as per the command send by the project to it??
in user control i want to draw shapes and each user control should draw separate shape as per user selection from following list...circle,ellipse,rectangle,triangle etc....
 
Last edited:
Hi,

Yes, you can create Properties within a Custom control that can be changed either at design time or runtime which will then effect how your control reacts. Have a comprehensive look here:-

Developing Custom Windows Forms Controls with the .NET Framework

This is an overview of creating a custom control but if there are specific things that you want to learn then try typing these requirements into Google since there are loads of examples on the net of creating custom controls.

Hope that helps.

Cheers,

Ian
 
i am creating multiple instances of single user control in my project at run-time, then how to recognize click on particular user control...?
 
Hi,

Sorry, I missed the fact that you said you were creating these at runtime.

You need to add a handler to each of the controls to handle their Click events. You can then cast the Sender object in your called subroutine to identify which controls was clicked and then do something with it. Have a look at this example:-

VB.NET:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  Dim myShape1 As New ShapeControl
  Dim myShape2 As New ShapeControl
 
  With myShape1
    .Name = "Shape No. 1"
    .Top = 100
    .Left = 100
  End With
  With myShape2
    .Name = "Shape No. 2"
    .Top = 100
    .Left = 400
  End With
 
  AddHandler myShape1.Click, AddressOf ShapeClicked
  AddHandler myShape2.Click, AddressOf ShapeClicked
 
  Me.Controls.Add(myShape1)
  Me.Controls.Add(myShape2)
End Sub
 
Private Sub ShapeClicked(sender As System.Object, e As System.EventArgs)
  Dim myShape = DirectCast(sender, ShapeControl)
  MsgBox(myShape.Name)
End Sub

Hope that helps.

Cheers,

Ian
 
I take it you missed my last post?

Cheers,

Ian


My project shows following error and this error is for DLL.
"The specified module could not be found. (Exception from HRESULT: 0x8007007E)"
But this error comes only on my pc , on other pc project runs Ok..is there any setting problem in vs2008?
 
Hi,

That's a bit vague since you give no indication what DLL you are talking about. On the basis that you have been creating a User Control, is this the DLL you are referring to? If so, then check to make sure the DLL exists in the bin\debug Directory of your Project.

Hope that helps.

Cheers,

Ian
 
Why do people always insist on starting their programming journey by skipping the basics I wonder...

Ask yourself this question:
- Do I know what classes, properties, and events are, and how to use them?

If your answer is anything but a definite YES, you need to back up and read a couple of tutorials.
 
Hi,

That's a bit vague since you give no indication what DLL you are talking about. On the basis that you have been creating a User Control, is this the DLL you are referring to? If so, then check to make sure the DLL exists in the bin\debug Directory of your Project.

Hope that helps.

Cheers,

Ian

DLL exist in bin\debug directory of my project.
but when i copied DLL into windows\ system32 ,error solved.
 
Back
Top