Winform Composite Control Project? - c#

Is it possible to have a single project which allow to include a custom custom control within another custom control ?
Update: of course I'm not asking about how to put a custom control on a winform!!! But if I can create put a CUSTOM user CONTROL inside ANOTHER CUSTOM user CONTROL within the SAME PROJECT.

Sure, you're able to do this. In fact you're able to put a custom control inside another custom control the same way you'd do it on a form (it's essentially the same while editing). You might as well base your custom control off another class (or custom control), but not all will support the built in gui editor (so you might just see an error message but the code will still work).

Related

WPF CustomControl in dll

Is it possible to add definition of WPF Custom Control to dll?
There is no such a template in Visual Studio 2015. Only template "WPF User Control" is avaiable, but I don't want to create control from scratch but modernize existing standard control.
The following project types exist that might fit your needs:
WPF Custom Control Library: Custom controls extend one of the WPF control base classes and provide additional functionality through code.
WPF User Control Library: A user control is technically a normal content control which you can extend in some parts in the code but usually it is extended by placing other controls inside of it.
See this answer for more information: What is the difference between a User Control Library and a Custom Control Library?
If I understand you correct, you want to create a User Control based on XAML. In my Visual Studio, this template is called "User Control WPF" and yes, you can add it to a Dll.
To modernize an existing control it might be simple to modifiy the style and ControlTemplate of this control. You can extract style and control template using Blend and then modify it to your needs.

Accessing a Custom Renderer Instance from Xamarin Forms Element Shared Code

I am creating a component that uses a custom renderer on each platform. Let's just call it a SpecialButton element. BindableProperty works fine for values but I also want to allow a user to invoke operations on the renderer from shared code (call methods on the renderer from the Forms control code). I was looking at DependencyService as a possible solution but I don't think that will work because it is possible for multiple buttons to appear on the same page so I need the specific renderer instance that was created and linked to my Xamarin Forms element.
So, is there an elegant way for my Xamarin Forms control element to
get access to the custom renderer that was instantiated by the Forms
framework?
I had thought about exposing a property on the control and letting the renderer set itself to the property in its constructor but this feels hacky and also exposes it to the user of the control which I don't want to do.
I think I figured out a solution. I didn't realize the MessagingCenter had a source parameter which can be used to specify the element property.
MessagingCenter.Subscribe(this, "DoOperation", myButton => DoOperation(), Element);

Building custom controls: use WebControl or Control?

There are a lot of ways to build custom controls for Asp.Net. Some people use the System.Web.UI.WebControls.WebControl as a base class and other people use the System.Web.UI.Control as a base class for their new controls.
What are the reasons to choose the one or the other as a base?
System.Web.UI.WebControls.Webcontrol derives from the System.Web.UI.Control and adds support for styling (BackgroundColor, Style, etc.).
Control doesn’t have that support by default, you’ll have to implement it yourself by creating properties and handle those on the Render() method. WebControls also come with theming and toolbox support for certain common properties.
Control does not have a user interface where as WebControl renders to the response object.
You should use System.Web.UI.WebControls.WebControl when your control is going to have a UI component visible on the rendered page, as it contains the various plumbing code generate a UI (though still requiring considerable work from you to create that UI).
System.Web.UI.Controls are for when your control will not have a UI on the rendered page (think some of the ASP.NET DataSource controls that reside in the toolbox, can be dragged onto a page, don't render anything, and act as a conduit for getting data to a GridView control that does have a UI).
See this MSDN article.

Transforming a c# class into a visual control

I new to c# and windows form programming. Here is the problem i am trying to solve.
I have to write an application that uses an multiple instance of an ActiveX control. Therefore, I dragged as many control as necessary to my Form. Now my problem is that i'd like to add some personalised methods to this activeX. The logical solution I thought was to create my own class derived from that aciveX and add some more members and methods to that class so it would work as desired. Now my problem is that the newly generated class doesn't exists as a control that can be inserted into the form.
So How can a class become a control and then inserted into a form ?
If you look at the Designer.CS file that corresponds to your form, you should see, in the #region Windows Form Designer generated code, the code that was generated when you dragged the ActiveX control onto the form.
This code is similar to what your code needs to look like.
My guess would be that you should wrap this activex into your own control, and add funcionality that lacks into that wrapper.
Pros: you'l have .net control and will be able to extend it and use it anyway you like.
Cons: if you want to access original methods, you'll have to generate pass-through method wrappers.
How:
- create a control class
- drop activex you have onto it
- set activex dock to 'fill'
- either set control to public, create get wrapper for it, or create method wrappers you desire
- compile that and use it on the form.

What are the purpose of User Controls in Visual C#?

User Controls -- Do they serve a special purpose?
As far as I can tell they are no different to forms - they have the same toolbox and features.
Are there certain times when they are appropriate to use over forms?
It would be interesting to understand what they are good for.
You use them to group a set of controls and behaviors together in a re-usable way. You can't show a control on the screen unless it's added to a form somewhere.
One good example is a textbox. It's very common to have a label next to your textboxes. You can build a user control to make this easier. Just drop a label and a textbox on the control, expose whatever your properties you want, setup the new control in your toolbox, and now you can just drop this control on your form instead of needing to arrange a label and a toolbox on the form separately.
You could kind of think of them as a panel which "remembers" what controls you put on it. And there's one more important piece. You can put code in these controls as well, and use that to also build special behaviors into your custom controls.
I have to disagree (slightly) with the selected answer. Reusability is only part of what a UserControl is for.
All Controls are reusable. Almost all controls are reusable on the same Form/Window/Panel/etc. For example, a TextBox is a control.
There are two ways to create your own reusable control:
Custom Control
Completely custom, and reusable.
Created entirely in code.
You get a bit more granular control over what your control is doing this way.
Lighter weight (usually), because there isn't anything added in for designability within Visual Studio.
In ASP.Net only: No "HTML" type file to use or edit.
User Control
Completely custom, and reusable.
Created partially in a designer in Visual Studio, and partially in code. (via code behind)
Much easier to deal with from a visual aspect.
A little heavier, as there is pre-existing code added in by the framework to support designing inside Visual Studio.
In ASP.Net only: You can change the appearance a bit simply by editing the .ascx file (basically HTML).
User Controls serve the purpose of reusing controls.
Imagine you need a search box in several pages of your application. You can create a search user control and drop it in every page where you want it visible.
So, it's nothing more than a container that aggregates reusable blocks for your pages.
Forms have a lot of extra furniture that you don't need if you simply want a collection of controls together - the minimize and maximize buttons for example. If you just simply grouped your controls in a Panel, you'd have all the event handlers on the same form as the panel - with a user control, the event handling code is in the user control class, not the form class.
You can reuse the same control on many forms. In fact all items you are using while creating windows forms are the controls. User controls are just extra controls extending controls library provided by .NET.
In ASP.NET, user controls enable you to split your page into reusable components. For example, you may want to have a search box which can be used in different places on your website, so you'd use a user control. They can also be used for partial page caching. You can cache portions of your page to improve performance.

Categories