Mega problem, lukker windows formen i forbindelse med linieskift
Jeg har et mega problem, mit færdig program lukker indtastningsformen når jeg trykker på enter i forbindelse med linie skift i en multiline textbox.Det underlige er at første gang man bruger formen så virker det fint. når man lukker formen i forbindelse med at der gemmes på databasen. Når man så åbner igen så når man kun til der hvor man skal skifte linie med et tryk på enter. så gemmer den det der er indtastet og lukker formen, dvs man får ikke skrevet alle de ting som skal skrives.
man skal så igennem proceduren i en rediger form 2 gange, så virker indtastningsformen igen uden problemer.
jeg vedhæfter koden til indtastnings formen, rediger formen, og mit modul.
// dette er indtastningsformen
Dim løber As New Enkeltloeber
Private Sub frmsinkelreg_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
e.Cancel = True
Me.Hide()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
løber.nr = TextBox1.Text
løber.navn = TextBox2.Text
løber.adr = TextBox3.Text
løber.får = TextBox4.Text
løber.tshirt = TextBox5.Text
løber.btid = TextBox6.Text
Try
SQLinsert("insert into Almen(nr,navn,adresse,får,tshirt,btid) values (" & løber.nr & ", '" & løber.navn & "', '" & løber.adr & "', '" & løber.får & "', '" & løber.tshirt & "', '" & løber.btid & "')")
Catch ex As System.Data.OleDb.OleDbException
MsgBox("Der findes Allerede en løber med dette nummer", MsgBoxStyle.Critical)
End Try
Me.Hide()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Hide()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
PrintDocument1.Print()
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim pfont, ffont, dfont As Font
pfont = New Font("arial", 8, FontStyle.Regular)
ffont = New Font("arial", 12, FontStyle.Bold)
dfont = New Font("arial", 10, FontStyle.Bold)
e.Graphics.DrawString(TextBox2.Text, ffont, Brushes.Black, 90, 70)
e.Graphics.DrawString(TextBox3.Text, ffont, Brushes.Black, 90, 100)
e.Graphics.DrawString("Hej ", ffont, Brushes.Black, 87, 215)
e.Graphics.DrawString(TextBox2.Text, ffont, Brushes.Black, 120, 215)
e.Graphics.DrawString("Tak for din tilmelding til Stjernemarathon 2004", pfont, Brushes.Black, 87, 245)
e.Graphics.DrawString(" Startgruppe: Single-marathon Herrer", dfont, Brushes.Black, 420, 235)
e.Graphics.DrawString("Vi har registreret dig med følgende oplysninger:", pfont, Brushes.Black, 87, 270)
e.Graphics.DrawString("Start nr: ", pfont, Brushes.Black, 87, 290)
e.Graphics.DrawString(TextBox1.Text, pfont, Brushes.Black, 140, 290)
e.Graphics.DrawString("Navn: ", pfont, Brushes.Black, 87, 310)
e.Graphics.DrawString(TextBox2.Text, pfont, Brushes.Black, 140, 310)
e.Graphics.DrawString("Fødselsår: ", pfont, Brushes.Black, 275, 290)
e.Graphics.DrawString(TextBox4.Text, pfont, Brushes.Black, 345, 290)
e.Graphics.DrawString("Adresse: ", pfont, Brushes.Black, 87, 330)
e.Graphics.DrawString(TextBox3.Text, pfont, Brushes.Black, 140, 330)
e.Graphics.DrawString("T-Shirt: ", pfont, Brushes.Black, 275, 310)
e.Graphics.DrawString(TextBox5.Text, pfont, Brushes.Black, 345, 310)
e.Graphics.DrawString("Bedste Tid: ", pfont, Brushes.Black, 275, 330)
e.Graphics.DrawString(TextBox6.Text, pfont, Brushes.Black, 345, 330)
End Sub
Sub clearfelter()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
End Sub
End Class
// dette er rediger formen
Dim løber As New Enkeltloeber
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents Label6 As System.Windows.Forms.Label
Friend WithEvents TextBox6 As System.Windows.Forms.TextBox
Friend WithEvents TextBox5 As System.Windows.Forms.TextBox
Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents PrintDocument1 As System.Drawing.Printing.PrintDocument
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TextBox3 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.Label3 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.Button4 = New System.Windows.Forms.Button
Me.Label6 = New System.Windows.Forms.Label
Me.TextBox6 = New System.Windows.Forms.TextBox
Me.TextBox5 = New System.Windows.Forms.TextBox
Me.TextBox4 = New System.Windows.Forms.TextBox
Me.Label5 = New System.Windows.Forms.Label
Me.Label4 = New System.Windows.Forms.Label
Me.PrintDocument1 = New System.Drawing.Printing.PrintDocument
Me.SuspendLayout()
'
'TextBox3
'
Me.TextBox3.Location = New System.Drawing.Point(80, 56)
Me.TextBox3.Multiline = True
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.Size = New System.Drawing.Size(200, 144)
Me.TextBox3.TabIndex = 7
Me.TextBox3.Text = ""
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(80, 32)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(200, 20)
Me.TextBox2.TabIndex = 6
Me.TextBox2.Text = ""
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(80, 8)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(200, 20)
Me.TextBox1.TabIndex = 5
Me.TextBox1.Text = ""
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(88, 288)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(64, 24)
Me.Button1.TabIndex = 8
Me.Button1.Text = "Gem"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(216, 288)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(64, 24)
Me.Button2.TabIndex = 9
Me.Button2.Text = "Annuller"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(152, 288)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(64, 24)
Me.Button3.TabIndex = 10
Me.Button3.Text = "Slet"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(8, 64)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(64, 24)
Me.Label3.TabIndex = 13
Me.Label3.Text = "Adresse"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(8, 32)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(64, 24)
Me.Label2.TabIndex = 12
Me.Label2.Text = "Navn"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(8, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(72, 16)
Me.Label1.TabIndex = 11
Me.Label1.Text = "Nr"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(24, 288)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(64, 24)
Me.Button4.TabIndex = 14
Me.Button4.Text = "Print"
'
'Label6
'
Me.Label6.Location = New System.Drawing.Point(8, 256)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(72, 24)
Me.Label6.TabIndex = 21
Me.Label6.Text = "Bedste tid"
'
'TextBox6
'
Me.TextBox6.Location = New System.Drawing.Point(80, 256)
Me.TextBox6.Name = "TextBox6"
Me.TextBox6.Size = New System.Drawing.Size(200, 20)
Me.TextBox6.TabIndex = 20
Me.TextBox6.Text = ""
'
'TextBox5
'
Me.TextBox5.Location = New System.Drawing.Point(80, 232)
Me.TextBox5.Name = "TextBox5"
Me.TextBox5.Size = New System.Drawing.Size(200, 20)
Me.TextBox5.TabIndex = 17
Me.TextBox5.Text = ""
'
'TextBox4
'
Me.TextBox4.Location = New System.Drawing.Point(80, 208)
Me.TextBox4.Name = "TextBox4"
Me.TextBox4.Size = New System.Drawing.Size(200, 20)
Me.TextBox4.TabIndex = 16
Me.TextBox4.Text = ""
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(8, 232)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(72, 24)
Me.Label5.TabIndex = 19
Me.Label5.Text = "T-shirt"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(8, 208)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(64, 24)
Me.Label4.TabIndex = 18
Me.Label4.Text = "Fødselsår"
'
'PrintDocument1
'
'
'frmopdaterenkelher
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(288, 318)
Me.Controls.Add(Me.Label6)
Me.Controls.Add(Me.TextBox6)
Me.Controls.Add(Me.TextBox5)
Me.Controls.Add(Me.TextBox4)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Button4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox3)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Name = "frmopdaterenkelher"
Me.Text = "Opdater herre"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub frmopdaterenkelher_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
e.Cancel = True
Me.Hide()
End Sub
Sub indlæsløber(ByVal nr As Integer)
Dim resultat As New DataSet
resultat = SQLselect("select navn,adresse,får,tshirt,btid from Almen where nr =" & nr)
TextBox1.Text = nr
Try
TextBox2.Text = resultat.Tables(0).Rows(0).Item(0)
Catch ex As Exception
TextBox2.Text = ""
End Try
Try
TextBox3.Text = resultat.Tables(0).Rows(0).Item(1)
Catch ex As Exception
TextBox3.Text = ""
End Try
Try
TextBox4.Text = resultat.Tables(0).Rows(0).Item(2)
Catch ex As InvalidCastException
TextBox4.Text = ""
End Try
Try
TextBox5.Text = resultat.Tables(0).Rows(0).Item(3)
Catch ex As InvalidCastException
TextBox5.Text = ""
End Try
Try
TextBox6.Text = resultat.Tables(0).Rows(0).Item(4)
Catch ex As Exception
TextBox6.Text = ""
End Try
løber.nr = nr
Me.Hide()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
løber.adr = TextBox3.Text
løber.navn = TextBox2.Text
løber.får = TextBox4.Text
løber.tshirt = TextBox5.Text
løber.btid = TextBox6.Text
SQLupdate("update almen set adresse='" & løber.adr & "',navn='" & løber.navn & "',får='" & løber.får & "',tshirt='" & løber.tshirt & "',btid='" & løber.btid & "' where nr=" & løber.nr)
Me.Hide()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim svar As String
svar = MsgBox("Vil du slette Løberen", MsgBoxStyle.Question.YesNo, "Slet")
If svar = vbYes Then
SQLdelete("delete * from almen where nr =" & løber.nr)
End If
Me.Hide()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Hide()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
PrintDocument1.Print()
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim pfont, ffont, dfont As Font
pfont = New Font("arial", 8, FontStyle.Regular)
ffont = New Font("arial", 12, FontStyle.Bold)
dfont = New Font("arial", 10, FontStyle.Bold)
e.Graphics.DrawString(TextBox2.Text, ffont, Brushes.Black, 90, 70)
e.Graphics.DrawString(TextBox3.Text, ffont, Brushes.Black, 90, 100)
e.Graphics.DrawString("Hej ", ffont, Brushes.Black, 87, 215)
e.Graphics.DrawString(TextBox2.Text, ffont, Brushes.Black, 120, 215)
e.Graphics.DrawString("Tak for din tilmelding til Stjernemarathon 2004", pfont, Brushes.Black, 87, 245)
e.Graphics.DrawString(" Startgruppe: Single-marathon Herrer", dfont, Brushes.Black, 420, 235)
e.Graphics.DrawString("Vi har registreret dig med følgende oplysninger:", pfont, Brushes.Black, 87, 270)
e.Graphics.DrawString("Start nr: ", pfont, Brushes.Black, 87, 290)
e.Graphics.DrawString(TextBox1.Text, pfont, Brushes.Black, 140, 290)
e.Graphics.DrawString("Navn: ", pfont, Brushes.Black, 87, 310)
e.Graphics.DrawString(TextBox2.Text, pfont, Brushes.Black, 140, 310)
e.Graphics.DrawString("Fødselsår: ", pfont, Brushes.Black, 275, 290)
e.Graphics.DrawString(TextBox4.Text, pfont, Brushes.Black, 345, 290)
e.Graphics.DrawString("Adresse: ", pfont, Brushes.Black, 87, 330)
e.Graphics.DrawString(TextBox3.Text, pfont, Brushes.Black, 140, 330)
e.Graphics.DrawString("T-Shirt: ", pfont, Brushes.Black, 275, 310)
e.Graphics.DrawString(TextBox5.Text, pfont, Brushes.Black, 345, 310)
e.Graphics.DrawString("Bedste Tid: ", pfont, Brushes.Black, 275, 330)
e.Graphics.DrawString(TextBox6.Text, pfont, Brushes.Black, 345, 330)
End Sub
End Class
// dette er mit modul
Imports System
Imports System.Data
Imports System.Data.OleDb
Module Module1
Public main As New frmmain
Public sinkelreg As New frmsinkelreg
Public Parherrer As New frmparherrer
Public Parkvinder As New frmparkvinder
Public Parmix As New frmparmix
Public virksomhedluk As New frmvirksomhedluk
Public virksomhedåben As New frmvirksomhedåben
Public sinkelregkvinder As New frmsinkelregkvinder
Public søgparher As New frmSøgparher
Public søgparkvind As New frmSøgparkvind
Public søgparmix As New frmSøgparmix
Public søgkvinder As New frmsøgkvinder
Public søgenkelt As New frmsøgenkelt
Public søgvirkåben As New frmsøgvirkåben
Public søgvirkluk As New frmsøgvirkluk
Public opdaterparherrer As New frmopdaterparherrer
Public opdaterparkvinder As New frmopdaterparkvinder
Public opdaterparmix As New frmopdaterparmix
Public opdatervirksomåbn As New frmopdatervirksomåbn
Public opdatervirkluk As New frmopdatervirkluk
Public opdaterenkelher As New frmopdaterenkelher
Public opdaterenkelkvin As New frmopdaterenkelkvin
Public indtasttidherrer As New frmIndtastherrer
Public indtasttiddamer As New frmIndtasttiddamer
Public indtasttid As New frmIndtasttid
Public indtasttidparkvinder As New frmIndtasttidparkvinder
Public indtasttidparmix As New frmIndtasttidparmix
Public indtasttidvirkåben As New frmIndtasttidvirkåben
Public indtasttidvirkluk As New frmIndtasttidvirkluk
Public printlabels As New frmPrintlabels
Public valgafstartliste As New frmValgafstartliste
Public resultatliste As New frmResultatliste
Dim forbindelse As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath & "\HG.mdb")
Public Sub SQLinsert(ByVal Data As String)
'forbindelse.Close()
forbindelse.Open()
Dim kommando As New OleDbCommand(Data, forbindelse)
kommando.ExecuteNonQuery()
forbindelse.Close()
End Sub
Public Sub SQLdelete(ByVal Data As String)
'forbindelse.Close()
forbindelse.Open()
Dim kommando As New OleDbCommand(Data, forbindelse)
kommando.ExecuteNonQuery()
forbindelse.Close()
End Sub
Public Sub SQLupdate(ByVal Data As String)
'forbindelse.Close()
forbindelse.Open()
Dim kommando As New OleDbCommand(Data, forbindelse)
kommando.ExecuteNonQuery()
forbindelse.Close()
End Sub
Public Function SQLselect(ByVal Data As String) As DataSet
'forbindelse.Close()
forbindelse.Open()
Dim tempset As New DataSet
Dim Adapter As New OleDbDataAdapter(Data, forbindelse)
tempset.Reset()
Adapter.Fill(tempset)
SQLselect = tempset
forbindelse.Close()
'tempset.Reset()
End Function
End Module
jeg håber at nogen kan give mig svar hurtigt da programmet skal bruges nu faktisk i går.
