My code:
Imports Microsoft.Office.Interop
Imports OpenQA.Selenium
Imports OpenQA.Selenium.Chrome
Imports System.Text
Imports System.Windows.Threading
Imports UiPath
Imports UiPath.Orchestrator.Extensibility
Imports System.IO
Imports System.Net.NetworkInformation
Imports EASendMail
Imports VB = Microsoft.VisualBasic
Class MainWindow
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
'Dim OutlookApp As New Outlook.Application
Dim OutlookApp As Outlook.Application = GetObject(, "Outlook.Application")
Dim Inbox = OutlookApp.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).Items
AddHandler Inbox.ItemAdd, AddressOf Inbox_ItemAdd
'Inbox.ItemAdd += New Outlook.ItemsEvents_ItemAddEventHandler(AddressOf Inbox_ItemAdd)
'This line does not work, but it works in the C# stack question for some reason
End Sub
Public Sub Inbox_ItemAdd(ByVal Item As Object)
Dim mail As Outlook.MailItem = CType(Item, Outlook.MailItem)
If Item IsNot Nothing Then
MsgBox("Received")
End If
End Sub
End Class
I tried both adding a handler from the .ItemAdd to my method called Inbox_ItemAdd and tried a solution from a different stackoverflow question like this: Inbox.ItemAdd += New Outlook.ItemsEvents_ItemAddEventHandler(AddressOf Inbox_ItemAdd).
I'm out of ideas.
The issue is that the Inbox_ItemAdd will not trigger even if I use the AddHandler.
You should keep the object that raises the event alive by storing it in a field:
Class MainWindow
Dim Inbox As Outlook.Items
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
...
Inbox = OutlookApp.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).Items
AddHandler Inbox.ItemAdd, AddressOf Inbox_ItemAdd
End Sub
Public Sub Inbox_ItemAdd(ByVal Item As Object)
...
End Sub
End Class
Related
I have a XamDataGrid in my MainWindow which has a Public Shared List(Of Artikelstammdaten) as DataSource. After opening a few other forms I want to add more data to the XamDataGrid with a button click. I thought the easiest way would be just to update the DataSource, but I get an Error:
The reference to an unreleased member requires an object reference.
This is what I have tried:
Private Sub Add_Click(sender As Object, e As RoutedEventArgs)
Dim update = MainWindow.listArtikelstammdaten.Concat(CType(Import.ComparedAccessData, IEnumerable(Of Artikelstammdaten)))
dgArticleMasterData.DataSource = update
Me.Close()
End Sub
If dgArticleMasterData is defined in the MainWindow class, you need to get a reference to the MainWindow instance to be able to access it.
You should be able to find it in the Application.Current.Windows collection:
Private Sub Add_Click(sender As Object, e As RoutedEventArgs)
Dim update = MainWindow.listArtikelstammdaten.Concat(CType(Import.ComparedAccessData, IEnumerable(Of Artikelstammdaten)))
Dim window = Application.Current.Windows.OfType(Of MainWindow).FirstOrDefault()
If window IsNot Nothing Then
window.dgArticleMasterData.DataSource = update
End If
Me.Close()
End Sub
I have a usercontrol that contains a spread and I have this methods
Public Event DOBLECLICK()
Public Sub sp1_CellDoubleClick(sender As Object, e As FarPoint.Win.Spread.CellClickEventArgs)
RaiseEvent DOBLECLICK()
End Sub
and in the mainwindow.xaml in the function MainWindow_Loaded I have:
AddHandler host.sp1.CellDoubleClick, AddressOf host.sp1_CellDoubleClick
my question is, how can i use the event of double click and when clicked i hide the windowsformhost i know that i can hide it whit
WinFormsHost.Visibility = Windows.Visibility.Hidden but how to when clicked the doubleclick on the spread.
finally i got it,
in the user control put this:
Public Event Dobleclick()
Private Sub sp1_CellDoubleClick(sender As Object, e As FarPoint.Win.Spread.CellClickEventArgs) Handles spEmpresas.CellDoubleClick
RaiseEvent Dobleclick()
End Sub
and in the MainWindow.xaml:
Imports nameofyourprogram.Control
Public Class MainWindow
Dim host As New nameofyourprogram.Control
Public Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
AddHandler host.Dobleclick, AddressOf doubleclick
end sub
Sub doubleclick()
msgbox("now you can work whit and event in your mainwindow ")
'after this message i want to hide my windownforhost
WinFormsHost.Visibility = Windows.Visibility.Hidden
end sub
End Class
(WPF system). How to open and close the same window several times?
The code below does not work. I can only open the "About" window once.
I do not know how to avoid this mistake. Could you help me ? Thank you.
'Window Main
Class MainWindow
Dim WindowAbout As FormAbout = New FormAbout
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
WindowAbout.ShowDialog()
End Sub
End Class
--------
'Window About
Imports System.ComponentModel
Public Class FormAbout
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
Close()
End Sub
End Class
After searching, here is the answer: add WindowAbout = New FormAbout
'Window Main
Class MainWindow
Dim WindowAbout As FormAbout = New FormAbout
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
WindowAbout = New FormAbout
WindowAbout.ShowDialog()
End Sub
End Class
--------
'Window About
Imports System.ComponentModel
Public Class FormAbout
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
Close()
End Sub
End Class
I am trying to figure out how to animate/move elements in WPF with VB.NET. It was suggested to me to try using CompositionTarget.Rendering but I am having difficulty getting started. Below is my code and below that is the error message I am getting. Could someone please tell me where I am going going wrong.
Code:
Imports System.ComponentModel
Class MainWindow
Dim flake0 As New flake
Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
canvas1.DataContext = flake0
AddHandler CompositionTarget.Rendering, AddressOf compo
End Sub
Private Sub compo(ByVal sender As Object, ByVal e As EventArgs)
flake0.move()
End Sub
End Class
Error:
Handles clause requires a WithEvents variable defined in the containing type or one of its base types
I had another method that accidentally got "handles CompositionTarget.Rendering" tagged to the end of it.
I have a WPF Project to which i've added a Windows Form.
The windows form has a method runme(). But I'd like to call it from the WPF form.
Currently I've used
Dim wpfForm as new wpfForm
wpfForm.Show()
to display the the WPF form from a Windows form.
I'm not sure how to send a command back though.
I've tried:
Me.parent.runme()
But this gives me errors
The only way that I can think of to do what you are wanting is to create a Custom Constructor for your Winform and pass the reference to the Wpf Window to it. There appears to be no easy way to assign a WPF Window as an Owner/Parent of a Winforms Window.
Winforms Form
Public Class Form1
Dim myParent As System.Windows.Window
Public Sub New()
InitializeComponent()
End Sub
Public Sub New(parent As System.Windows.Window)
myParent = parent
InitializeComponent()
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
CType(myParent, MainWindow).runMe()
End Sub
End Class
Wpf Form
Class MainWindow
Dim winForm As Form1
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
winForm = New Form1(Me)
winForm.Show()
End Sub
Public Sub runMe()
Me.Background = Brushes.Red
End Sub
End Class
Eventually what worked was to create an interface as suggested by Cyborgx37
Interface ILogOut
Sub DoIt()
End Interface
Class WinFormWindow : Implements ILogOut
Public Sub DoIt() Implements ILogOut.DoIt
MsgBox("Message Received!")
End Sub
End Class
You can then use the ILogOut interface to send a message to the Windows forms window from a WPF window