Home Windows ecommerce Treiber Server Entwicklung Software Security Internet Hardware Nicht IT Mobile Nintendo Suchen Multimedia Virtualisierung Kopie von Navi01b Provider


FlowDocument

-->Layout WPF Controls Styles

Flow Document

Laden einer Textdatei in ein FlowDocument

WPF Code:

<Window x:Class="LoadTextFileInFlowDocumentViewerSample.Window1"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="Window1" Height="290" Width="600">

    <Canvas>

        <TextBox Height="32" HorizontalAlignment="Left" Margin="6,10,0,0" Name="FileNameTextBox"

                 VerticalAlignment="Top" Width="393" />

        <Button Content="Browse" Height="32" HorizontalAlignment="Left" Margin="405,10,0,0"

                Name="button1" VerticalAlignment="Top" Width="88" Click="button1_Click" />

     

            <FlowDocumentReader Name="FlowDocReader" Background="LightBlue"

                                Canvas.Top="50" Canvas.Left="5" Width="560"

                                Height="210">

        </FlowDocumentReader>

    </Canvas>

</Window>  

C# Code

private void button1_Click(object sender, RoutedEventArgs e)

{

    // Create OpenFileDialog

    Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();          

  

    // Set filter for file extension and default file extension

    dlg.DefaultExt = ".txt";

    dlg.Filter = "Text documents (.txt)|*.txt";

 

    // Display OpenFileDialog by calling ShowDialog method

    Nullable<bool> result = dlg.ShowDialog();

 

    // Get the selected file name and display in a TextBox

    if (result == true)

    {

        // Open document

        string filename = dlg.FileName;

        FileNameTextBox.Text = filename;

 

        Paragraph paragraph = new Paragraph();

        paragraph.Inlines.Add(System.IO.File.ReadAllText(filename));

        FlowDocument document = new FlowDocument(paragraph);

        FlowDocReader.Document = document;

    }

}

VB.NET Code

Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)

        'Create OpenFileDialog

        Dim dlg As Microsoft.Win32.OpenFileDialog = New Microsoft.Win32.OpenFileDialog()

 

        ' Set filter for file extension and default file extension

        dlg.DefaultExt = ".txt"

        dlg.Filter = "Text documents (.txt)|*.txt"

 

        ' Display OpenFileDialog by calling ShowDialog method

        If (dlg.ShowDialog() = True) Then

 

            '; Open document

            Dim filename As String = dlg.FileName

            FileNameTextBox.Text = filename

 

            Dim paragraph As Paragraph = New Paragraph()

            paragraph.Inlines.Add(System.IO.File.ReadAllText(filename))

            Dim document As FlowDocument = New FlowDocument(paragraph)

            FlowDocReader.Document = document

        End If

 

    End Sub

 

 


Ihre Werbung hier

 

Haftungsausschluss: Verwendung der Informationen auf Ihre eigene Gefahr. Wir übernehmen keinerlei Haftung. Beachten Sie auch den Haftungsausschluss.


Wenn Sie Wünsche, Anregungen, Verbesserungen, Korrekturen oder sonstige Vorschläge zu dieser FAQ haben: . Wir freuen uns auf Ihr Mail.


 Und jetzt noch ein bisschen Werbung...

Stellensuche, Jobangebote unter www.notizia.ch/stellensuche