Bonjour,
je cherche le code en vb net pour me permettre d'utiliser une variable déclarée dans ma class MainWindows dans un usercontrol
Merci pour votre aide.
Bonjour,
je cherche le code en vb net pour me permettre d'utiliser une variable déclarée dans ma class MainWindows dans un usercontrol
Merci pour votre aide.
bonjour
Ta tentative avec le code ,pour t'aider,svp !!!
Bonjour MABROUKI,
Voici mon code:
Code dans la MainWindows:
Code dans le UserControl:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 Class MainWindow Private Sub IG_Click(sender As Object, e As RoutedEventArgs) Handles IG.Click Dim ctrl = New ViewerPDF Dim Host = New WindowsFormsHost WindowsFormsHostPDF.Child = ctrl Grid_PDF.Children.Add(Host) End Sub End Class
Comment faire pour que ma variable "fichier" soit déclarer dans la MainWindows et utiliser dans le UserControl ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 Public Class ViewerPDF Private Sub ViewerPDF_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim fichier As String fichier = "c:\liste téléphonique.pdf" AxAcroPDF1.LoadFile(fichier) End Sub End Class
Merci pour ton aide.
Tu dois créer un constructeur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 Public Class ViewerPDF Sub New(FileName As String) AxAcroPDF1.LoadFile(FileName ) End Sub '(...) End Class
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 Class MainWindow Private Sub IG_Click(sender As Object, e As RoutedEventArgs) Handles IG.Click Dim ctrl = New ViewerPDF("c:\liste téléphonique.pdf") Dim Host = New WindowsFormsHost WindowsFormsHostPDF.Child = ctrl Grid_PDF.Children.Add(Host) End Sub End Class
Bonjour
Ta solution avec le "PdfViewer" (d'ou provient-il?) est archi-compliquée car si AdobeReader de Adobe est un viewer PDF gratuit et pour l'utiliser il suffit de le dropper dans le control WebBrowser de WPF ....
Pour cela tu te pourvoit d'un usercontrol wpf :
code xaml :
code behind.vb :aucun
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 <UserControl x:Class="UserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <Grid> <WebBrowser x:Name="webViewer"></WebBrowser> </Grid> </UserControl>
code xaml du Form User :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 Public Class UserControl1 Public Sub New() ' Cet appel est requis par le concepteur. InitializeComponent() ' Ajoutez une initialisation quelconque après l'appel InitializeComponent(). End Sub End Class
code behind du Form User:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 <Window x:Class="Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300" xmlns:local="clr-namespace:WpfFoudhil" > <Grid x:Name="grd"> <Grid.RowDefinitions> <RowDefinition Height="Auto"></RowDefinition> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <Button Grid.Row="0" x:Name="btn" Content="button" HorizontalAlignment="Center" VerticalAlignment="Center" Click="btn_Click"> </Button> <local:UserControl1 Grid.Row="1" x:Name="pdfWebViewer" HorizontalAlignment="Center" VerticalAlignment="Center" /> </Grid> </Window>
Tu as toutes les fonction du Reader Pdf prêtes.....
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 Imports Microsoft.Win32 Public Class Window1 Private pathPDF As String = String.Empty Private Sub btn_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) pathPDF = FileName() Me.pdfWebViewer.webViewer.Navigate(pathPDF) 'Dim uri As New Uri(pathPDF) ' si pathPDF est une adresse web 'Me.pdfWebViewer.webViewer.Navigate(uri) End Sub Private Function FileName() As String Dim fname As String = String.Empty Dim dlgOpen As New OpenFileDialog dlgOpen.Filter = "files (*.pd)|*.pdf" If dlgOpen.ShowDialog = True Then fname = dlgOpen.FileName End If Return fname End Function End Class
Bonjour r.morel,
J'ai copier coller les code que tu m'as donné mais ça marche pas je pense que j'ai oublié de faire quelque (peut-être la création du contrôleur).
Voici le message d'erreur que j'obtiens:
Merci.
Partager