Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User Control Properties 2

Status
Not open for further replies.

jv6886

Programmer
Dec 31, 2002
46
0
0
US
I have created a user control with two or more constituent controls on it.

Can anyone tell me what is the easiest way to allow certain properties, events, and methods from each of the controls to be "visible" to the user, but not other properties, events and methods?

Thanks,
wcprog
 
By the way... this is using the 1.1 framework :)
 
UserControl named ThumbNail
-Has an image
-Has text under it


in your usercontrol, you can open up properties such as ThumbnailText and ThumbnailImage


public string ThumbnailText
{
get
{
return this.txtBox1.Text;
}
set
{
this.txtBox1.Text = value;
}
}


public Image ThumbNailImage
{
get
{
return this.imgBox1.Image;
}
set
{
this.imgBox1.Image = value;
}
}
 
Thank you for your response.

This is the approach that I am taking currently. In my particular case, I am combining a CheckedListBox and a Button. I want most of the CheckedListBox functionality and some of the Button functionality to come through with only a few "rewired" properties, events and methods. Unfortunately there are dozens of these that need to be "wired through" and this can get rather tedious. Especially when you have to add to this process redocumenting features that are already documented in the .NET framework.

I was really hoping that I was overlooking some important feature of inheritance that would simplify this process

Thanks once again for your input,
wcprog
 
The only other option is to make the controls public, but that gives the user waaaaay too much control in most cases.
 
To make constituent controls public is not a real option. You can use a ControlDesigner class to remove properties from such a control. Properties and event you want to show should be handled by your own code, i.e. shadowing.

Here's some VB code I once wrote to remove a couple of properties from a Panel control:

Code:
Imports System
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Collections
Imports System.Drawing
Imports System.Windows.Forms.Design

Friend Class ProgressBarDesigner
  Inherits System.Windows.Forms.Design.ControlDesigner

  Public Sub New()
  End Sub

  Protected Overrides Sub PostFilterProperties(ByVal properties As IDictionary)
    properties.Remove("AllowDrop")
    properties.Remove("AutoScroll")
    properties.Remove("AutoScrollMargin")
    properties.Remove("AutoScrollMinSize")
    properties.Remove("BackgroundImage")
    properties.Remove("ContextMenu")
    properties.Remove("DockPadding")
    properties.Remove("RightToLeft")
    properties.Remove("Locked")
  End Sub
End Class

In your control's code you would have to specify the controldesigner to use:

Code:
<Designer(GetType(ProgressBarDesigner)), ToolboxBitmap(GetType(ProgressBar))> _
Public Class ProgressBar
  Inherits System.Windows.Forms.Panel
'
'
'

I'm sorry about the code being VB .NET but I don't have time right now to port it ;) It should be self-explanatory though.

Regards, Ruffnekk
---
Is it my imagination or do buffalo wings taste just like chicken?
 
P.S: You have to add a reference to System.Design.dll

Regards, Ruffnekk
---
Is it my imagination or do buffalo wings taste just like chicken?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top