Results 1 to 11 of 11

Thread: Program doesnt close

  1. #1

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407

    Exclamation Program doesnt close

    When i click the X on my program..the program doesnt close even though it should..why does it do that (i dont want to post all of the code...there isnt much anyway...)?


    Also..in VB6 i was able to click on the combomenu at the top and choose Form1 and then the combomenu to the right i was able to choose Unload..so it would make a Private Sub Form1_Unload for me..why cant i do that in vb.net?

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780
    When i click the X on my program..the program doesnt close even though it should..why does it do that (i dont want to post all of the code...there isnt much anyway...)?


    ^ It does, you have changed something in your code. No idea until you paste some of it.


    Also..in VB6 i was able to click on the combomenu at the top and choose Form1 and then the combomenu to the right i was able to choose Unload..so it would make a Private Sub Form1_Unload for me..why cant i do that in vb.net?


    ^ You can, you drop down the left box and choose Base Class Events, then click the right box and et voila. By the way, there is no such event as Unload, its now called Closing.

  3. #3

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407
    Form1 code...(i was messin with the region stuff...it's pretty cool lol)

    VB Code:
    1. Public Class Form1
    2.     Inherits System.Windows.Forms.Form
    3.  
    4. #Region " Windows Form Designer generated code "
    5.  
    6.     Public Sub New()
    7.         MyBase.New()
    8.  
    9.         'This call is required by the Windows Form Designer.
    10.         InitializeComponent()
    11.  
    12.         'Add any initialization after the InitializeComponent() call
    13.  
    14.     End Sub
    15.  
    16.     'Form overrides dispose to clean up the component list.
    17.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    18.         If disposing Then
    19.             If Not (components Is Nothing) Then
    20.                 components.Dispose()
    21.             End If
    22.         End If
    23.         MyBase.Dispose(disposing)
    24.     End Sub
    25.  
    26.     'Required by the Windows Form Designer
    27.     Private components As System.ComponentModel.IContainer
    28.  
    29.     'NOTE: The following procedure is required by the Windows Form Designer
    30.     'It can be modified using the Windows Form Designer.  
    31.     'Do not modify it using the code editor.
    32.     Friend WithEvents ListView1 As System.Windows.Forms.ListView
    33.     Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
    34.     Friend WithEvents Label1 As System.Windows.Forms.Label
    35.     Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
    36.     Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
    37.     Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
    38.     Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
    39.     Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
    40.     Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem
    41.     Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem
    42.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    43.         Me.components = New System.ComponentModel.Container()
    44.         Dim ListViewItem1 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New System.Windows.Forms.ListViewItem.ListViewSubItem() {New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "Client", System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)))}, 1)
    45.         Dim ListViewItem2 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New System.Windows.Forms.ListViewItem.ListViewSubItem() {New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "Server", System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)))}, 0)
    46.         Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
    47.         Me.ListView1 = New System.Windows.Forms.ListView()
    48.         Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
    49.         Me.Label1 = New System.Windows.Forms.Label()
    50.         Me.MainMenu1 = New System.Windows.Forms.MainMenu()
    51.         Me.MenuItem1 = New System.Windows.Forms.MenuItem()
    52.         Me.MenuItem2 = New System.Windows.Forms.MenuItem()
    53.         Me.MenuItem3 = New System.Windows.Forms.MenuItem()
    54.         Me.MenuItem4 = New System.Windows.Forms.MenuItem()
    55.         Me.MenuItem5 = New System.Windows.Forms.MenuItem()
    56.         Me.MenuItem6 = New System.Windows.Forms.MenuItem()
    57.         Me.SuspendLayout()
    58.         '
    59.         'ListView1
    60.         '
    61.         Me.ListView1.Alignment = System.Windows.Forms.ListViewAlignment.SnapToGrid
    62.         ListViewItem1.Tag = ""
    63.         Me.ListView1.Items.AddRange(New System.Windows.Forms.ListViewItem() {ListViewItem1, ListViewItem2})
    64.         Me.ListView1.LargeImageList = Me.ImageList1
    65.         Me.ListView1.Location = New System.Drawing.Point(16, 40)
    66.         Me.ListView1.MultiSelect = False
    67.         Me.ListView1.Name = "ListView1"
    68.         Me.ListView1.Size = New System.Drawing.Size(168, 64)
    69.         Me.ListView1.StateImageList = Me.ImageList1
    70.         Me.ListView1.TabIndex = 5
    71.         '
    72.         'ImageList1
    73.         '
    74.         Me.ImageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit
    75.         Me.ImageList1.ImageSize = New System.Drawing.Size(32, 32)
    76.         Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
    77.         Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
    78.         '
    79.         'Label1
    80.         '
    81.         Me.Label1.Location = New System.Drawing.Point(16, 16)
    82.         Me.Label1.Name = "Label1"
    83.         Me.Label1.Size = New System.Drawing.Size(184, 16)
    84.         Me.Label1.TabIndex = 6
    85.         Me.Label1.Text = "Double click on an option to start:"
    86.         '
    87.         'MainMenu1
    88.         '
    89.         Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem5, Me.MenuItem1})
    90.         '
    91.         'MenuItem1
    92.         '
    93.         Me.MenuItem1.Index = 1
    94.         Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2, Me.MenuItem3, Me.MenuItem4})
    95.         Me.MenuItem1.Text = "Help"
    96.         '
    97.         'MenuItem2
    98.         '
    99.         Me.MenuItem2.Index = 0
    100.         Me.MenuItem2.Text = "How To"
    101.         '
    102.         'MenuItem3
    103.         '
    104.         Me.MenuItem3.Index = 1
    105.         Me.MenuItem3.Text = "-"
    106.         '
    107.         'MenuItem4
    108.         '
    109.         Me.MenuItem4.Index = 2
    110.         Me.MenuItem4.Text = "About"
    111.         '
    112.         'MenuItem5
    113.         '
    114.         Me.MenuItem5.Index = 0
    115.         Me.MenuItem5.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem6})
    116.         Me.MenuItem5.Text = "File"
    117.         '
    118.         'MenuItem6
    119.         '
    120.         Me.MenuItem6.Index = 0
    121.         Me.MenuItem6.Text = "Exit"
    122.         '
    123.         'Form1
    124.         '
    125.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    126.         Me.ClientSize = New System.Drawing.Size(208, 118)
    127.         Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label1, Me.ListView1})
    128.         Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
    129.         Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
    130.         Me.MaximizeBox = False
    131.         Me.Menu = Me.MainMenu1
    132.         Me.Name = "Form1"
    133.         Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
    134.         Me.Text = "Connect..."
    135.         Me.ResumeLayout(False)
    136.  
    137.     End Sub
    138.  
    139. #End Region
    140. #Region " Form1 Declarations "
    141.  
    142. #End Region
    143.  
    144. #Region " Form1 Code "
    145.  
    146.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    147.  
    148.     End Sub
    149.  
    150.  
    151.  
    152. #Region " ListView1 Double Click Function "
    153.     Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
    154.         If ListView1.Items(0).Selected = True Then
    155.             ListView1.Items(1).Selected = False
    156.             Me.Hide()
    157.             frm2.Show()
    158.         End If
    159.         If ListView1.Items(1).Selected = True Then
    160.             ListView1.Items(0).Selected = False
    161.             Me.Hide()
    162.             frm4.Show()
    163.         End If
    164.  
    165.     End Sub
    166. #End Region
    167.  
    168.  
    169. #Region " Menu Functions "
    170.     Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem6.Click
    171.         End
    172.     End Sub
    173. #End Region
    174. #End Region
    175. End Class

    and the Module Code..

    VB Code:
    1. Module Module1
    2.     Public frm1 As New Form1()
    3.     Public frm2 As New Form2()
    4.     Public frm4 As New Form4()
    5.     Public Declare Function GetTickCount Lib "kernel32" () As Long
    6.     Public Sub Pause(ByVal Interval As Long)
    7.         Dim Start
    8.         Start = GetTickCount
    9.         Do While GetTickCount < Start + Interval
    10.             Application.DoEvents()
    11.         Loop
    12.     End Sub
    13. End Module

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Open new project , paste your controls , functions and subs from the old proj to the new one .

  5. #5
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780
    Change your END function to Close.

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Where do you see that ?

  7. #7
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780
    #Region " Menu Functions "
    Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem6.Click
    End
    End Sub
    #End Region
    #End Region
    End Class

  8. #8
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    But that still works .
    You can use: Application.Exit()

  9. #9
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    The problem may be with your ListView. You need to set focus off of the ListView before any changes are made to it (in your ListView1 click event that you have posted). This is a bug that for whatever reason, disables the close(x). I ran into this using a TreeView.

    Not sure if it is the same with the ListView - but it might be worth a shot - and might save some time.

  10. #10
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    that happens to ALL controls..there was some posts made some time ago talking about known .NET bugs and that is one of that..if u do a search over here u'll probably find it
    \m/\m/

  11. #11
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    You may also want to look into removing the creation of instances of your forms until you need them. In your module you create an instance of all of your forms, which are then in a hidden state until you show them or close them. That may have an effect on closing your program, because you still have forms in memory.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width