I'm using a self-authored ActiveX control on an MS Access form. On adding the Active X control, I can set a custom design time property without issue. However, if I go back into design mode to change the value of the design time property, the property change is not retained. Appreciate for guidance on why design time change to custom property is not retained. Is the ActiveX control design missing some required functionality to retain design mode property changes?
To recreate the issue:
Using the ActiveX control in C# as per Microsoft sample found at C# ActiveX Control (CsActiveX)
After compiling the sample, open MS Access, add a reference to the CsActiveX.tlb from the C# project.
Add the CsActiveX control (csActiveX.CSActiveXCtrl) to a form and set it's custom 'FloatProperty' to 5. Save the form.
Open form in 'Form View' and the float property is displayed as expected i.e. 5.
Re-open the form in design mode and change the 'FloatProperty' to 8. Save design changes.
Re-open form in 'Form View' but the float property is displayed as 5 and not 8 as expected. i.e. the change in design mode was lost!
Fyi, if I use the ActiveX control in a c# Win Forms application, the control works as expected. Also, I'm inexperienced in ActiveX control design and am using this sample as a base on which to design my own custom controls for use in VBA.
Related
I'm having a problem trying to embed an ILPlotPanel inside a
UserControl which will be used as a COM Component, and will be imported by
a third part software.
I can put the ILPanel, but it don't render nothing (keeps the design mode visualization).
In another hand the ILPlotPanel gives me a error while trying do click and drag it (VS2010) to
a empty UserControl.
Here's the given error:
So the problems are:
1°. ILPanel don't render scenes while hosted by another application.
2º. In VS2010, can't click and drag the ILPlotPanel to a UserControl.
So anyone have a clue on this issues?
Thanks.
Try the ILNumerics.Settings.IsHosted property! You can set it via code (if your Host allows it early enough) or via configuration (by using the key ILNIsHosted).
What I am looking for is the same type of designer support for controls inside a usercontrol. ie - resizing a textbox, moving a label, that are inside a usercontrol after placeing the usercontrol on to a form.
What I've been able to do...
create a usercontrol
use the designer to add controls to the it
create a new window forms app
add the usercontrol to the toolbox
drag and drop the control on the a form
where I am stuck...
edit the usercontrols controls. IE - being able to resize a textbox that is inside the usercontrol using the designer.
I found a similar question on stack that was never answered. So if I am being too vague you can follow this link https://stackoverflow.com/questions/10359772/example-make-constituent-controls-in-a-usercontrol-editable.
Thank you.
After reading Nikita's comment I was able to find Microsoft support page on creating a custom designer for controls.
Here's a quote if your interested on how the designed-time support works
The design-time support for components in the .NET Framework, however, is not defined exclusively by a design tool such as Microsoft Visual Studio .NET. Rather, the development environment supports the extension and definition of design-time behavior by classes such as designers that provide design-time support for components. Support for extensible and customizable design mode behavior is an integrated part of the .NET Framework. Tools such as Visual Studio .NET also provide a range of design-time services that designers can use.
This is the webpage if you like to continue reading and view samples from Microsoft
Enhancing Design-Time Support
Everything seems complicated when you just start learning it, heres a working code sample for a UserControl that has a PictureBox and a Label on it. Both controls can be edited during design time, ie. resizing and repositioning, and expose all their events and properties if you click on them.
You will need to add a reference to System.Design, which can only be referenced if you are not targeting ".Net Client Profile." You can change you target profile in Proprieties/Application/TargetFramework.
Add a usercontrol to your project and add a class to handle it's designer. Double click the usercontrol and then add a label and picture box from the toolbar.
Next open that class you create to be it's designer. Add this...
using System.Windows.Forms;
using System.Windows.Forms.Design;
public override void Initialize(IComponent component)
{
base.Initialize(component);
if (this.Control is MyUserControl) // replace this with your usercontrol type
{
// cast this.Control to you type of usercontrol to get at it's
// controls easier
var i = this.Control as MyUserControl; // replace ***
this.EnableDesignMode(i.label1, "unique_name1");
this.EnableDesignMode(i.pictureBox1, "unique_name2");
}
}
Is there a way to see controls which are created via code in designer instantly but not only during execution?
The Windows Forms designer only applies properties contained in the automatically generated file "Form1.Designer.cs" (example filename for "Form1"). If you change properties (e.g. text, color, whatever) or create new controls in your own code, i.e. in "Form1.cs", the designer does not show it.
It is practically impossible because the designer would have to either 1) parse your code or 2) execute it to apply all changes to the controls.
Option 1 does not work because expression evaluation only works when running the code... Which leads us to option 2: Letting the designer running your code to find out dynamically added properties? First of all, automatically running untrusted code is not what you want. Second, there must be a reason that you do these changes dynamically instead of statically in the designer, so showing dynamic changes as WYSIWYG does not even make sense.
The designer can only display controls that exist at design time or show example controls for databound controls. If you think about code that would dynamically at runtime create a textbox or label based on a variable, how would the designer know which one to display in design mode?
If you have specific logic for how you want your dynamically created controls to display in design mode, you would have to create a custom control and implement the design time drawing code. This is mentioned under the Custom Design Experience heading here: http://msdn.microsoft.com/en-us/library/ms171725.aspx
How can one set GridLayout known from Java or Wpf in WinForms control? Is it available by default or does it require writing some code (custom LayoutEngine implementation)?
Yes, it is available by default. If you are using Visual Studio, just drag it from toolbox to your form and set properties.
As far as I know Windows Forms work totally different from Java and WPF forms. One of thier differences is that there's no layout for windows forms whatsoever, instead there's this ability that you can place a control whenever you would like using its location property.
I am currently exploring the option of porting some older VB6 application to WPF with C#. The plan, in phase one, is to port several key forms and not all the application. The theoretical goal is to open the VB6 form in a container of some sort within WPF via an ActiveX dll.
Is this even possible?
I've tried looking at the Interop and can't seem to find a solid example of how get it to work with anything but Win32 controls, not a full form. I have full access to the old VB6 code and can modify it in anyway needed.
The following screenshot of the main WPF app would serve as the wrapper/container:
http://www.evocommand.com/junk_delete_me/main_menu_mockup.png
The current VB6 maintenance screen that would be loaded in the “white space” section on the right side of the previous screen.
I was able to accomplish the task with the following steps:
Created a new VB6 Active X Control Project. Copied and pasted the entire contents of the VB6 form controls and code behind into the new control. There are several elements that have to be handled in switching to a control:
you lose the ability to display
the caption of the form in the
previous manner. You can work around
it with alternate controls
(label/borderlesstextbox, etc) that
accomplish the same functionality if
needed. This wasn’t a priority since
each screen was being hosted in a
browser like tab system in our new
.Net project.
All mousepointer references have to
be changed from Me.Mousepointer to
Screen.mousepointer
You cannot use Me.Hide and have to
alternate events to hide the .Net
container.
Any and all references to
Me.[anything] have to be removed or
replaced with UserControl.[anything]
if they are applicable.
If you use any functions that
reference a
[yourcontrol].Contianer.Property on a
form they will need to be altered to
loop through the UserControl.Controls
collection instead and “Container” is
invalid for vb6 ActiveX controls
All non-modal forms/dialog boxes
must be removed from the project as
there is now no Hwnd to handle in WPF.
You get an error of 'Non-modal forms
cannot be displayed in this host
application from an ActiveX DLL,
ActiveX Control, or Property page'.
In our case we had a simple splash
screen that would display when certain
long processes/reports displayed to
let the user know what was running.
I was unable to directly add the VB6 control via the interop to a WPF project . As such a new .Net “Windows Form Control Library” project was created. A reference to the VB6 OCX was added to the project. The VB6 Control s were then added to the .Net toolbox by “right click” –> “Add Item” and pointing a com reference to the VB6 control ocx. The .Net control was then used to host/serve the VB6 Control.
To display host a form in the VB6 and get it to fire the necessary initialization functionality the VB6 OCX controls were defaulted in a Visible.False manner so they were initially added to the .Net OCX as invisible controls. When needed the VB6 control is set to visible = True which fires the UserControl_Show() event. All code formerly in Form_Load() was moved to this event. The show event was the easiest method of accessing the Form_Load as needed. MSDN: “The control does not receive Show events if the form is hidden and then shown again, or if the form is minimized and then restored. The control’s window remains on the form during these operations, and its Visible property doesn’t change.”
Wrapping the vb6 controls within a .Net Winform control resolved the issue with Radio/Option buttons being rendered as black as outlined elsewhere in one of my responses to this question without having to convert the frames to Picture boxes as suggested.
In the WPF app as a menu choice is selected xaml code is dynamically created and displayed via a wrapper with a WindowsFormsHost tag. A dynamically created control object from the .Net winform app is then pushed into the WindowsFormsHost tag on the xaml and the control is made visible on the .net project which fires vb6 UserControl_Show and then load and display of the vb6 form.
I think what you will have to do is extract the VB6 form contents into an ActiveX control. You can then expose this in your ActiveX dll and place that in your WPF form. I doubt it's possible to host a VB6 form within any other type of form.
Can you even load that VB6 form in another VB6 form? I suggest you get that working first.
There is no reliable way to set parent of a VB6 form. You can always hack it or use plain ActiveX control (UserControl in VB6) as UI container instead of VB6 forms.
I found a method to do what was needed within WinForms rather than WPF at this point.
http://www.codeproject.com/KB/vb-interop/VB6formsinNET.aspx
I figure if I can get it working 100% there I can port it over to WPF or worse case host the WinForm element in the WPF form if I absolutely have too (U-G-L-Y).
Anyway, I've gotten a bit closer, but am having a very odd issue with certain controls painting too the screen. Radio/Option buttons are rendering as solid black:
http://www.evocommand.com/junk_delete_me/optionbuttons.png
I've tried explicitly changing the controls' background color from buttonface to a fixed color and it still does it. I'm assuming it's a layering issue with the option buttons being within the frame control. I'm at a bit of a loss on how to proceed without massive rework of the VB6 content to change the options buttons to checkboxes. It's a hefty app and there are 600+ option button controls across the application that I don't exactly want to deal with.
EDIT:
I was able to confirm it has something to do with the layering of the option within a Frame control. If pulled out to the base form the issue does not occur:
http://www.evocommand.com/junk_delete_me/optionbuttons2.png