I'm creating a ActiveX control. I've created a bunch of properties in a User Control and now I want to access those properties in the other modules, classes, forms, etc in the same project but I can't seem to find the correct syntax to do so?
Syntaxt I've tried:
connectString = user_control_name.DBConnectionString
connectString = Property("DBConnectionString")
connectString = Property(DBConnectionString)
connectString = Property Get ("DBConnectionString")
If you want to access a property on an instance of a UserControl on a specific form, you can do:
my_form_reference.my_usercontrol_name.my_property = <whatever>
If you want to access the instance of a UserControl that is in a UserControl, you will have to pass the reference to the UserControl via a property on the containing UserControl.
I generally recommend you don't pass UserControl references around. It is generally better to wrap up these controls, and not break abstraction.
If you want to access a property on an instance of a UserControl from inside the ActiveX Control project, I would recommend against it. The only way you can do this is by using module-level variables in a BAS module. This variable would potentially be accessible from every module in the project. You would have to set the variable in the UserControl_Initialize event of the control. However, I would strongly recommend you not doing this, because this creates an extra reference to your UserControl, which should really only have a reference from the containing Form or UserControl. This extra reference would mean that if the containing Form or UserControl was unloaded, the control would stick around in memory for the lifetime of your application, causing a memory leak. There are ways around this issue by using "weak references". But this is not supported in VB6, requires API hacks, and is prone to causing crashes.
I seriously would suggest you find some other way to do what you want. Perhaps you could explain exactly why you have this requirement.
Related
In Xamarin Forms what is the difference between the EventHandlerBehavior and EventToCommandBehavior? I have been using the former successfully, but the latter was suggested to me to use instead. EventToCommandBehavior is less verbose which is a good thing.
About difference between EventHandlerBehavior and EventToCommandBehavior, I have some point, you can take a look:
For EventHandlerBehavior, you need to install Behaviors.Forms in your project firstly, behaviors let you add functionality to controls without having to subclass them. Instead, the functionality is implemented in a behavior class and attached to the control as if it was part of the control itself. Behaviors enable you to implement code that you would normally have to write as code-behind, because it directly interacts with the API of the control in such a way that it can be concisely attached to the control and packaged for reuse across more than one app.
For EventToCommandBehavior,the EventToCommandBehavior is a custom class, there are need you create EventToCommandBehavior class derives from the BehaviorBase class firstly, then implementing Bindable Properties, for detailed info, you can take a look:
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/behaviors/reusable/event-to-command-behavior
So I suggest you can use EventHandlerBehavior, because you don't need to create many code behind.
2021 Edit
EventHandlerBehavior from community-toolkit is now equivalent to EventHandlerBehavior.
Documentation:
https://learn.microsoft.com/en-us/xamarin/community-toolkit/behaviors/eventtocommandbehavior
In Xamarin Forms what is the difference between the EventHandlerBehavior and EventToCommandBehavior?
Eventhandler like:
OnTextChanged, OnSelectedIndexChanged etc are defined behind the C# code file of XAML. These methods are completely tied to your controls you define behind your pages/controls.
However the Behaviors in Xamarin allows us to ATTACH them to any View. Your behavior will know which controls it is being attached to. Hence, for those Events like OnTextChanged/OnSelectedIndexChanged can be controlled from the Behaviors.
EventToCommandBehaivor: As we already know that Behavior get attached to any view; you have to define the behavior as such that It will expose the BINDABLE property for Commands. EventToCommandBehavior is just a normal behavior control which supports binding the Command and the Eventname. Which in runtime, whenever the Event for the control get fired, your behavior will execute the Command attached making it more ViewModel friendly.
Remember if you use Events; you are writing them behind the code base than ViewModel your logics are in two separate places. If you want to properly separate the logics from View and Model then then you have to use EventToCommandBehavior.
Let me know if you need more info.
Often, when I'm looking for information of how to set certain properties of controls (I'm using Visual Studio primarily, but this question does apply to any IDE), the examples I find normally involve programatically setting said properties.
Here's an example, using the DataGridView.DefaultCellStyle property on MSDN:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.defaultcellstyle(v=vs.110).aspx
So my question is: is it better for a programmer to modify these properties by code, or is it better to use the IDE itself to change them via the properties pane? I realize that doing it the latter way will result in auto-generated code anyway, but it will be "somewhere else" in relation to the main bulk of user-generated code.
It depends on your requirements. If the app you are developing is planned to be dynamic, then it is a good idea to do it the way it is described in the reference you provided. For example, you may create a class containing the method which will set the basic settings of the gridview, so on every page you may just call this method and pass to it the gridview as a parameter instead of repeating setting the grid properties on every page.
I'm using MSVS2012 and I develop in C++ .NET. When debugging, I watch variables that are property 's of certain classes. When the property change I have to update the watches manually (because it implies calling get() to object instances) using the small "2-arrow icon" at the left of the watch boxes.
My question is: is it possible to set the debugger to enable it to automatically call the get() methods in order to refresh the displayed values? In other words, is it possible to see the property values as if they were simple variables?
Note: Maybe this applies to MSVS2010 too?
Thanks!
Well, you can't automatically refresh the properties, and there is a reason for that....
http://msdn.microsoft.com/en-us/library/z4ecfxd9.aspx
Calling for propertie
I have a Visual Studio designer enabled control which uses a collection editor to allow the user to create and edit sub components.
For example, I have a control which offers a readonly "List" property containing a collection of bindings (themselves components with a name property and an event). The user can modify this list of bindings at will and everything works pretty well. They can create and remove bindings without a glitch.
However, when they copy the control, the designer does not copy the binding, it still refers to the original binding components. Also, when they delete the control, it doesn't delete the bindings. It is as if the form has the ownership of these bindings, not the control.
I'm sure there is an attribute to use or some interface to implement, maybe even a custom editor trick to use, but googling for it has left me "feeling unlucky".
Thanks for any help you may have! :)
Can You tell me about subj?
For example I need to create new custom control that must be derived from datagrid and toolbar. And I want that new control to expose/propagate properties of base controls in order they to be accessed easily. The only way I know is deriving a class. Then descendant automatically gets all properties of ancestor. But multiple deriving in C# is prohibited, so I don't know how to expose properties and other behavior of second control... Styling and templating of such custom control is also needed.
Thanks!
In WPF inheritance is "out". ;O) Actually, it was complicated before WPF already, but with WPF you get various really powerful alternatives.
For the basic control I thing you'd better go with composition, create some usercontrol and make it contain a ToolBar and a DataGrid. You can then expose these as public properties, if you need to manipulate them from outside.
For special feature additions, attached properties are a very versatile mechanism.
Watching a window from windowsclient.net is a good place to start.
Make sure you understand dependency properties well.
Reading wpf blogs is my best guest for what to do then.