Use winforms control with transparent background in MFC - c#

all.
I'm writting a MFC App that use Winforms user controls in it.
I made a rounded control with c# and placed it on my MFC dialog using MFC-hosting technology.
But the control does not show its background transparently.
So, it looks very poor. I tried to set control properties related transparency but it's useless.
Who can help me to make my control pretty?
Best regards.

Related

Can I make WebBrowser translucent and borderless in WPF?

I am finding that setting the Opaque value has no effect. Also there is always a border around the WebBrowser.
From the WPF WebBrowser page on MSDN:
The WebBrowser control internally instantiates the native WebBrowser ActiveX control.
So it's not an actual WPF control... just a wrapper around a native control that allows little customization.
Here's a blog that summarizes what you can't do with the ActiveX control pretty well:
If you add a Win32 component into a wpf application using the hwndhost control you have some limitations:
Resizing is limited because only the container(hwndhost) will be resized, not the contained component itself.
Forget about rotation and skewing.
The hosted component is a black hole for your application : always at the top (forget the z-order!).
Opacity can’t be applied to an hosted Win32 control.
VisualBrush do not work with Win32 controls.
He goes on to explain a work-around that would come with WPF 4.5, but I can't find anywhere that those promised features ever shipped. They don't appear to have.
About the border.. when I test it I don't have one. But if you do, I'm guessing there's no way to remove that either.
Here's what I see in a small test project (the WebBrowser has a margin of 20px, and it's inside of a GroupBox with 20px padding):

Adding Transparent backgrounds to WindowsFormsHost Controls in WPF

I'm using the WindowsFormsHost to add a Windows Forms control in my WPF application, but I realise that WinForms controls cannot have transparent backgrounds without setting the style as in here How to: Give Your Control a Transparent Background. How would this be done in WPF?
BTW, I'm using C# and .net 4.0.
Thanks.
I don't think you can do this. The link you provided is really about being able to set the BackColor to Transparent. When that happens the WinForms control (in its paint background handling) gets the Parent Control and calls its PaintBackground and Paint methods. While your control will have a parent - the control that the WindowsFormsHost will create - that control will not and so there will be nothing to draw the background. In a Win32 world one might set the WS_EX_TRANSPARENT bit but that introduces all sorts of issues and I suspect it may not even work based on how WPF works. I would check out the MSDN topics (e.g. Technology Regions Overview and WindowsFormsHost interop) discussing the various air space issues with interop between WPF and other technologies.

Control sizing and position will change when form will resize in win form application c#

suppose i have label and button on textbox and i want that if i resize my win form then my label and button size and position will change. i got the solution in wpf but i am working with win form apps. here i am giving the url from where you can see what kind of output i am looking form. the url is http://i.stack.imgur.com/QeoVK.png. please see the image and tell me how can i implement the same output in win form apps. please help me with code snippet in c#.thanks.
You should make yourself familiar with the Anchor and Dock properties of the controls. They are great tools for this kind of work.
Note though that they will alter the size of the controls only, they will not affect font size.
consider that window forms and WPF are very different, especially about the UI management and controls nesting / UI composition.
I have seen some articles describing what you are trying to do now in windows forms, long ego, it's something called control scaling if I recall well.
Use Anchor and Dock properties for simple stuff and SizeChanged event for more complicated stuff. UI positioning API is much more limited than WPF and you will probably have to do stuff like scaling manually.

Is there a way to prevent WinForms controls in a WPF window from being unstyled?

I have some WinForms controls that I need to use in a WPF window. I'm able to get the controls to show up just fine and everything works as I would expect, but I'm experiencing one issue: all the WinForms controls are unstyled.
I'd like for the WinForms controls to at least use the default OS style (like I would see in a WinForms application). Is there any way to control this, or do I have to live with the controls the way they are?
The WinForms controls can't use the WPF styles, because Windows Forms doesn't understand the WPF styling and templating system.
To get them to use the "OS style" (the OS visual theme), try calling System.Windows.Forms.Application.EnableVisualStyles in your Main method. (I thought WPF handled this automatically, but I guess that's not what you're seeing.) This must be called before any controls get created!

Can/how do you host a full VB6 Form in a C# WPF app?

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

Categories

Resources