|
-
Jan 1st, 2008, 05:15 PM
#1
Thread Starter
Frenzied Member
[2.0] UserControlLibrary Default Event Handler
How can you choose which event comes up by default when a control is double clicked? My user control contains one TextBox. When I import the user control into another project and double click it, the Load event comes up by default. Would it be possible to make it TextChanged by default instead?
-
Jan 1st, 2008, 05:35 PM
#2
Re: [2.0] UserControlLibrary Default Event Handler
You need to apply the DefaultEvent attribute to your class, e.g.
Code:
[System.ComponentModel.DefaultEvent("TextChanged")]
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
}
-
Jan 1st, 2008, 06:16 PM
#3
Thread Starter
Frenzied Member
Re: [2.0] UserControlLibrary Default Event Handler
Gracias. I shall give it a try. And while we're at it, how do I create default properties? I have a public property in public user control and I set it to false in the designers file, or in the declaration. Either way, when I import the control and create an instance of it, the public property is bold. For other properties, their default value is always just normal text and when you change them, THEN the text is bold, but for some reason, even when I first create the instance of it, the font is already bold as if it was changed.
Does this even matter? Honestly? No. I just want my control to look and feel like other controls made by Microsoft and other components and such. Also, the way it is shown bold before it is changed leads me to believe that quite possibly I'm doing something wrong.
-
Jan 1st, 2008, 06:22 PM
#4
Re: [2.0] UserControlLibrary Default Event Handler
Use the attributes on the property.
If you specify the default value and of correct type it will not be bolded unless its changed from that value.
Code:
Option Explicit On
Option Strict On
Imports System.Runtime.InteropServices
Imports System.ComponentModel
Imports System.ComponentModel.Design
Public Class UserControl1
Private _ShowMenuBar As Boolean
<Browsable(True), Category("SomeCategory"), DefaultValue(True)> _
Public Property ShowMenuBar() As Boolean
Get
Return _ShowMenuBar
End Get
Set(ByVal Value As Boolean)
_ShowMenuBar = Value
End Set
End Property
End Class
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 1st, 2008, 06:26 PM
#5
Re: [2.0] UserControlLibrary Default Event Handler
Apply the DefaultValue attribute to your property. That also gives you the ability to right-click it in the designer and select Reset.
Remember, if you want to control the design-time behaviour of a type or member then you're almost certainly talking about attributes.
-
Jan 1st, 2008, 06:32 PM
#6
Thread Starter
Frenzied Member
Re: [2.0] UserControlLibrary Default Event Handler
Alright. I don't really know much at all about attributes. Got any good tutorials for learning about them?
-
Jan 1st, 2008, 06:34 PM
#7
Re: [2.0] UserControlLibrary Default Event Handler
Just check out the intellisense and see whats available. There isnt too much too them.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 1st, 2008, 06:37 PM
#8
Re: [2.0] UserControlLibrary Default Event Handler
Ok, here is the C# for you. 
Code:
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.ComponentModel.Design;
public class UserControl1
{
private bool _ShowMenuBar;
[Browsable(true), Category("SomeCategory"), DefaultValue(true)]
public bool ShowMenuBar
{
get
{
return _ShowMenuBar;
}
set
{
_ShowMenuBar = value;
}
}
}
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 1st, 2008, 07:05 PM
#9
Re: [2.0] UserControlLibrary Default Event Handler
Go to the MSDN Library documentation for the Attribute class, read, go to the Inheritance Hierarchy section, click on the Derived Classes link, read about each one. It's all those in the System.ComponentModel namespace that control design-time behaviour.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|