VB Notepad Problem

Status
Niet open voor verdere reacties.

CalviN13

Gebruiker
Lid geworden
22 nov 2009
Berichten
41
Hoi allemaal,

Ik heb een Notepad gemaakt maar als ik op een file klik (.txt)
dan opent notepad wel maar text kom niet maar als ik het via
notepad zelf open (openfiledialog) doet hij het wel
kan iemand me de code geven omdat te fixe

P.S Als iemand de code heeft a.u.b kopier mij code
en plak hem op de goede plaats ik heb geen idee
waar die zou moeten(bedankt!!)

NotePad Code:
Code:
Public Class Form1
    Dim I As Integer = 1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Edit As New RichTextBox
        TabControl1.TabPages.Add(1, "Document " & i)
        TabControl1.SelectTab(i - 1)
        Edit.Name = "TE"
        Edit.Dock = DockStyle.Fill
        TabControl1.SelectedTab.Controls.Add(Edit)
        i = i + 1
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Edit As New RichTextBox
        TabControl1.TabPages.Add(1, "Document " & i)
        TabControl1.SelectTab(i - 1)
        Edit.Name = "TE"
        Edit.Dock = DockStyle.Fill
        TabControl1.SelectedTab.Controls.Add(Edit)
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If TabControl1.TabCount = 1 Then

        Else
            TabControl1.TabPages.RemoveAt(TabControl1.SelectedIndex)
            TabControl1.SelectTab(TabControl1.TabPages.Count - 1)
            i = i - 1
        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim OpenFileDialog1 As New OpenFileDialog
        Dim AllText As String = "", LineOfText As String = ""
        OpenFileDialog1.Filter = "All Files|*.*"
        OpenFileDialog1.ShowDialog()
        Try
            FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)
            Do Until EOF(1)
                LineOfText = LineInput(1)
                AllText = AllText & LineOfText & vbCrLf
            Loop
            CType(TabControl1.SelectedTab.Controls.Item(0), RichTextBox).Text = AllText
        Catch

        Finally
            FileClose(1)
        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim SaveFileDialog1 As New SaveFileDialog
        SaveFileDialog1.Filter = "Rich Text Files|*.rtf|Text Documents|*.txt|HTML Files|*.html|Batch Files|*.bat"
        SaveFileDialog1.ShowDialog()
        FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output)
        PrintLine(1, CType(TabControl1.SelectedTab.Controls.Item(0), RichTextBox).Text)
        FileClose(1)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim FS As New FontDialog
        FS.ShowDialog()
        CType(TabControl1.SelectedTab.Controls.Item(0), RichTextBox).Font = FS.Font
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Dim FC As New ColorDialog
        FC.ShowDialog()
        CType(TabControl1.SelectedTab.Controls.Item(0), RichTextBox).ForeColor = FC.Color
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        Dim AB As New PrintDialog
        Try
            AB.ShowDialog()
            TabControl1.Text = AB.PrintToFile
        Catch ex As Exception
        End Try
    End Sub

    Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged

    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        End
    End Sub
End Class


Alvast Erg Bedankt!
 
Laatst bewerkt:
Hey,

Ik heb iets gevonden op het net
maar ik denkt dat het er niet echt simple uit ziet
dus ik weet niet of het werkt of wat dan ook.
maar hier is de code je moet maar even kijken en testen :)

Dummy1912

PHP:
Imports System
Imports System.IO
Imports System.Text
Imports System.Runtime.InteropServices
Imports Microsoft.Win32

Public NotInheritable Class FileAssociation
    Private Declare Ansi Function FindExecutable Lib "shell32" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal Result As StringBuilder) As Integer
    
    ' HKEY_CURRENT_USER
    Private Shared ReadOnly HKCU_APP_FULLNAME As String = "Software\Microsoft\Windows\ShellNoRoam\MUICache"
    
    Const MAX_PATH As Integer = 260, ERROR_FILE_NO_ASSOCIATION As Integer = 31, ERROR_FILE_NOT_FOUND As Integer = 2, ERROR_PATH_NOT_FOUND As Integer = 3, ERROR_FILE_SUCCESS As Integer = 32, ERROR_BAD_FORMAT As Integer = 11
    
    
    Public Shared Function GetFileAssociation(ByVal fileName As String) As String
        Dim result As New StringBuilder(MAX_PATH)
        
        'lpFile: name of the file of interest
        'lpDirectory: location of lpFile
        'sResult: path and name of executable associated with lpFile
        Dim success As Integer = FindExecutable(Path.GetFileName(fileName), Path.GetDirectoryName(fileName) + "\"c, result)
        
        Select Case success
            Case ERROR_FILE_NO_ASSOCIATION
                Throw New InvalidOperationException("No association found")
            
            Case ERROR_FILE_NOT_FOUND
                Throw New FileNotFoundException("File not found")
            
            Case ERROR_PATH_NOT_FOUND
                Throw New DirectoryNotFoundException("Path not found")
            
            Case ERROR_BAD_FORMAT
                Throw New InvalidOperationException("Bad format")
            
            Case ERROR_FILE_SUCCESS
                Exit Select
        End Select
        
        Return result.ToString()
    End Function
    
    
    Public Shared Function GetFileAssociationFull(ByVal fileName As String) As String
        Dim fileAssoc As String
        Dim regKey As RegistryKey
        
        Try
            fileAssoc = GetFileAssociation(fileName)
            
            If fileAssoc IsNot Nothing AndAlso Not fileAssoc.Equals(String.Empty) Then
                ' Find out if a key named HKCU_APP_FULLNAME exists in
                ' HKEY_CURRENT_USER If it exists, open it
                regKey = Registry.CurrentUser.OpenSubKey(HKCU_APP_FULLNAME)
                
                If regKey IsNot Nothing Then
                    ' Read the Full Application Name, if present
                    If regKey.GetValue(fileAssoc) IsNot Nothing Then
                        fileAssoc = regKey.GetValue(fileAssoc).ToString()
                    End If
                    
                    ' Release the resources that the registry variable was
                    regKey.Close()
                        
                                    End If
            End If
        Catch e As Exception
            fileAssoc = String.Empty
        End Try
        
        Return fileAssoc
    End Function
    
End Class
 
Hey,

Ik heb iets gevonden op het net
maar ik denkt dat het er niet echt simple uit ziet
dus ik weet niet of het werkt of wat dan ook.
maar hier is de code je moet maar even kijken en testen :)

Dummy1912

PHP:
Imports System
Imports System.IO
Imports System.Text
Imports System.Runtime.InteropServices
Imports Microsoft.Win32

Public NotInheritable Class FileAssociation
    Private Declare Ansi Function FindExecutable Lib "shell32" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal Result As StringBuilder) As Integer
    
    ' HKEY_CURRENT_USER
    Private Shared ReadOnly HKCU_APP_FULLNAME As String = "Software\Microsoft\Windows\ShellNoRoam\MUICache"
    
    Const MAX_PATH As Integer = 260, ERROR_FILE_NO_ASSOCIATION As Integer = 31, ERROR_FILE_NOT_FOUND As Integer = 2, ERROR_PATH_NOT_FOUND As Integer = 3, ERROR_FILE_SUCCESS As Integer = 32, ERROR_BAD_FORMAT As Integer = 11
    
    
    Public Shared Function GetFileAssociation(ByVal fileName As String) As String
        Dim result As New StringBuilder(MAX_PATH)
        
        'lpFile: name of the file of interest
        'lpDirectory: location of lpFile
        'sResult: path and name of executable associated with lpFile
        Dim success As Integer = FindExecutable(Path.GetFileName(fileName), Path.GetDirectoryName(fileName) + "\"c, result)
        
        Select Case success
            Case ERROR_FILE_NO_ASSOCIATION
                Throw New InvalidOperationException("No association found")
            
            Case ERROR_FILE_NOT_FOUND
                Throw New FileNotFoundException("File not found")
            
            Case ERROR_PATH_NOT_FOUND
                Throw New DirectoryNotFoundException("Path not found")
            
            Case ERROR_BAD_FORMAT
                Throw New InvalidOperationException("Bad format")
            
            Case ERROR_FILE_SUCCESS
                Exit Select
        End Select
        
        Return result.ToString()
    End Function
    
    
    Public Shared Function GetFileAssociationFull(ByVal fileName As String) As String
        Dim fileAssoc As String
        Dim regKey As RegistryKey
        
        Try
            fileAssoc = GetFileAssociation(fileName)
            
            If fileAssoc IsNot Nothing AndAlso Not fileAssoc.Equals(String.Empty) Then
                ' Find out if a key named HKCU_APP_FULLNAME exists in
                ' HKEY_CURRENT_USER If it exists, open it
                regKey = Registry.CurrentUser.OpenSubKey(HKCU_APP_FULLNAME)
                
                If regKey IsNot Nothing Then
                    ' Read the Full Application Name, if present
                    If regKey.GetValue(fileAssoc) IsNot Nothing Then
                        fileAssoc = regKey.GetValue(fileAssoc).ToString()
                    End If
                    
                    ' Release the resources that the registry variable was
                    regKey.Close()
                        
                                    End If
            End If
        Catch e As Exception
            fileAssoc = String.Empty
        End Try
        
        Return fileAssoc
    End Function
    
End Class
ik krijg 13 errors
kheb ermee lopen rommelen maar het werkt niet :(

Andere ideeën ?
 
das raar ik heb geen error's :)
heb het ook even getest maar hoe het moet werken weet ik niet :(

nee momenteel niet ben nog aan het zoeken.
is niet makkelijk

Hoop dat snel hier iemand met een makkelijker oplossing komt ;)

Dummy1912
 
das raar ik heb geen error's :)
heb het ook even getest maar hoe het moet werken weet ik niet :(

nee momenteel niet ben nog aan het zoeken.
is niet makkelijk

Hoop dat snel hier iemand met een makkelijker oplossing komt ;)

Dummy1912

Oh oke raar maar wel erg bedankt voor de hulp :thumb:
 
@ CalviN13,

Hey

Ok found it

sorry voor het engels :)
ok eerst moet je een load event maken
dan plaats deze code erin

PHP:
'dus zo
 Private Sub Notepad_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        My.Computer.Registry.ClassesRoot.CreateSubKey(".txt").SetValue("", "txtfile", Microsoft.Win32.RegistryValueKind.String)
        My.Computer.Registry.ClassesRoot.CreateSubKey("txtfile\shell\open\command").SetValue("", Application.ExecutablePath & " ""%1"" ", Microsoft.Win32.RegistryValueKind.String)
        richtextbox.Text = My.Computer.FileSystem.ReadAllText(My.Application.CommandLineArgs(0).ToString)
        For Each s As String In My.Application.CommandLineArgs
            Console.WriteLine(s)
        Next
end sub

als je dan eerst jou notepad op default zet in windows
dan kies je uw txt bestand en dubble klik het en normaal gezien
zal het moeten werken met deze.

uit goeie bron vernomen.

Laat je weten of het is gelukt ok.

Bedankt
Dummy1912

P.s

Het werkt prima heb het zelf getest :)
 
Laatst bewerkt:
@ CalviN13,

Hey

Ok found it

sorry voor het engels :)
ok eerst moet je een load event maken
dan plaats deze code erin

PHP:
'dus zo
 Private Sub Notepad_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        My.Computer.Registry.ClassesRoot.CreateSubKey(".txt").SetValue("", "txtfile", Microsoft.Win32.RegistryValueKind.String)
        My.Computer.Registry.ClassesRoot.CreateSubKey("txtfile\shell\open\command").SetValue("", Application.ExecutablePath & " ""%1"" ", Microsoft.Win32.RegistryValueKind.String)
        richtextbox.Text = My.Computer.FileSystem.ReadAllText(My.Application.CommandLineArgs(0).ToString)
        For Each s As String In My.Application.CommandLineArgs
            Console.WriteLine(s)
        Next
end sub

als je dan eerst jou notepad op default zet in windows
dan kies je uw txt bestand en dubble klik het en normaal gezien
zal het moeten werken met deze.

uit goeie bron vernomen.

Laat je weten of het is gelukt ok.

Bedankt
Dummy1912

P.s

Het werkt prima heb het zelf getest :)
\

Nu weet ik het weer dit was de code Hartstikke bednkt man

Alleen 1 probleem
in plaats van RichTextBox1.text heb ik TabControl1.XXXX
wat moet er dan bij die xxxx :p
sorry ik ben echt vreselijk lui :p
 
@ Calvin13,

als je nu eens de regel gebruikt van de from_load
zie ik staan TabControl1.SelectedTab.Controls.Add(Edit)

missh kan je dat gebruiken
je kan altijd een beetje spelen met de code van de tabcontrol.
maar ik zie wel dat je een richtextbox gebruikt in je code.

maar leg eens uit wat er staat in die tabcontrol?
en waar dat je dan wilt dat die file wordt ingeladen.

Dummy1912
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan