0

I am trying to add a WPF user control to windows form. The WPF user control currently does not have anything in it, but I will be adding buttons. In form load, I do this:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    SetStyle(ControlStyles.SupportsTransparentBackColor, True)
    Application.EnableVisualStyles()

    Dim elemHost As New ElementHost
    Dim wuc As WPFUC = New WPFUC

    elemHost.Controls.Add(wuc)    <<-- I get error here
    'elemHost.child = wuc    <<-- and here
    AddSolid()
    'AddPanel()
End Sub

Error is "Value of type WindowsApplication1.WPFUC cannot be converted to System.Windows.Forms.Control. What else should I do?

Gareth
  • 2,746
  • 4
  • 30
  • 44
Veda
  • 243
  • 1
  • 15
  • i think this will be helpful > http://stackoverflow.com/questions/4874495/how-to-programmatically-create-a-wpf-window-in-a-winform-application – safi Dec 18 '14 at 11:49
  • @safi: Thanks for that article. It helped a lot. Instead of WPF user control, i just used a WPF window. Now it works great. So it opens on top of my MainForm at a specified location. Is there a way to anchor it to the edge of the MainForm? I know it's a window, so may be not directly, but is there a possible work around? – Veda Dec 20 '14 at 10:17

1 Answers1

0

I just calculated the screen points using PointToScreen method and specify that as location of WPF window wherever I needed.

Veda
  • 243
  • 1
  • 15