By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

How to create user difned controls? in v.b 6.0

P: 52
Hi everybody!

I would like to develope an application, in this a should abel to create user defined controls. i should have some properties. when ever i drag and drop that control it should apper on the form and should work. i can abel to write code behind that(when i clicked that contro, some thing should be done).

for ex: now i am developing a electrical circuit GUI in v.b user defined control is generator( asume it is like a picture in a circuit). i shold abel to drag and drop many generators in my GUI.

How can i do it. what controls are to be used. if u provide sample code, i would be grateful to u.
May 28 '07 #1
Share this Question
Share on Google+
4 Replies

Expert 5K+
P: 8,434
There are much better tutorials for this on the web than we could come up with in a short time here.

Hm... we had a reference to one of them here recently. Hold on, I'll have a look...
May 28 '07 #2

Expert 5K+
P: 8,434

P: 52
dear killer,
Thanks for u r reply.... your link has helped me alot.
now i am able to create user controls, set some properties. but still i have a problem.
my user control is an image. now i would like to assign a propery to my control called "mycolor". my objective is when ever user assigns this property with a different color, then my user control's color should be changed. how it is possible? my idea is instead of making color to my control, why don't i replace the image with another image which has the required color. if it is fine how to replace that. kindly help me if u know it.


Here we go...
Jun 5 '07 #4

Expert 5K+
P: 8,434
I've been playing with some usercontrols myself, lately. I wouldn't claim to be expert, but can probably help a little.

The way I understand it, you need to...
  • Create a private variable to hold the property value. For example...
    Private m_MyColor As Long (or possibly As OLE_COLOR)
  • Optionally, create a constant to hold a default value. For example...
    Private Const m_def_MyColor As Long = &H00FF00 ' (Green)
  • Add routines to retrieve and set the property...
    Public Property Get MyColor() As OLE_COLOR
    MyColor = m_MyColor
    End Property

    Public Property Let MyColor(ByVal New_Value As OLE_COLOR)
    m_MyColor = New_Value
    PropertyChanged "MyColor" ' Note that property needs to be saved.
    ' I guess this might be where you need to do whatever
    ' it is you do with your color. Perhaps set UserControl.BackColor.
    End Property
  • In the UserControl_ReadProperties routine, add your one...
    m_MyColor = PropBag.ReadProperty("MyColor", m_def_MyColor)
  • In the UserControl_WriteProperties routine, add your one...
    Call PropBag.WriteProperty("MyColor", m_MyColor, m_def_MyColor)
Have a play with that, let us know how it goes. It may take some fiddling to get it right (I know it does for me.)
Jun 5 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.