Adding Transparent backgrounds to WindowsFormsHost Controls in WPF - c#

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.

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):

.NET Compact Framework Transparent UserControl

I am programming a mobile application. I need a UserControl (emulating the TabContol navigation - the customer wants the tabs at the top) with a transparent background. The control contains three buttons each with an OnClick handler.
In Googling, I've found a number of solutions for WinForms. But they seemed incompatible with Win Mobile. I used the Christian Helle blog for a transparent label used in the app, but cannot wrap my mind around modifying it for UserControls.
TIA, Gus
Yeah, it's a complex task - way more complex than it should be, but it is what it is. While I never actually finished Project Resistance, it does have code for transparent user controls
The resistor body itself is a UserControl, the background shows through the surrounding area and it even dynamically draws the color bands so that the resistor body shows through the band transparent areas.

Use winforms control with transparent background in MFC

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.

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!

Categories

Resources