Hello friends.
Can anybody direct me to a good tutorial on creating a usercontrol. Something you have wrote yourself maybe ?, I am predominantly visual when it comes to learning so any simple examples would be great ;)
thank you.
casey.
Printable View
Hello friends.
Can anybody direct me to a good tutorial on creating a usercontrol. Something you have wrote yourself maybe ?, I am predominantly visual when it comes to learning so any simple examples would be great ;)
thank you.
casey.
Hi,Quote:
Originally Posted by vbasicgirl
This is how I started off. I hope this will help u too.
I could have obviously posted the whole project, but I think that won't help you much, how to start off. So here's what to do setp-by step.
Not much of functionality here, but this will demonstrate how to just create a simple OCX control.
This OCX just emulates a clock. Additionaly the User can reset it whenever required.
First start a New Project. Choos the project type to be Activex Control.
On the form, add a Label and a Timer. Then open teh code window and add this code.
VB Code:
Option Explicit Dim dBaseTime As Date Private Sub Label1_DblClick() Dim s As String s = InputBox("Enter New Time (hh:mm:ss):", "Reset Time", "00:00:00") If s = "" Then Exit Sub If IsDate(s) Then dBaseTime = s Else MsgBox "Time was not reset.", vbExclamation End If End Sub Private Sub Timer1_Timer() dBaseTime = DateAdd("n", 1, dBaseTime) Label1 = Format(dBaseTime, "hh:mm:ss") End Sub Private Sub UserControl_Initialize() With Label1 .Font.Name = "Courier New" .Font.Size = 14 .Font.Bold = True .Alignment = vbCenter .BackColor = vbGreen End With Timer1.Interval = 1000 'One second dBaseTime = Time End Sub Private Sub UserControl_Resize() Label1.Move 0, 0, UserControl.Width, UserControl.Height End Sub
Now save the project somewhere. Then click File > Make Project1.ocx
That's all. the OCX is created.
Now how do you test this.
Click File > Add Project... Then Choose to add a Standard EXE. The last control you see here is your control. (If it is not available, first close the Usercontrol's object window.)
Add this control to your Form.
U r almost done!
In the Project Explorer Window, right click your EXE Project (Project2) and choose "Set as Start Up"
Save everything and Press F5 to see the result.
Double click your control and it will give you option to reset the time.
This is just a simple demo, but just sufficient to start off.
After this step by step you can start defining more events, methods, properties, classes, add more forms and functionality...
Hope this helps.
Pradeep :)
Pradeep, you have taken some considerable time to write that out and i would like to thank you for that. i will look into it.
anybody else like to add to this.
thank you.
casey.
Hi,
Another source is if you have VB6 Enterprise along with the code Samples installed they have a user control project that you can use.
Another option is to use the VB6 ActiveX Control Wizard and see how a user control is "built".
Have a good one!
BK
This is really good : http://www.developer.com/net/vb/arti...0926_1539541_1