Luc001 77 Posting Whiz

Hi,

Why you changed everything?
Here's how it should look like and after testing works like it should.

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If MsgBox("Are you sure you want to exit?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Exit") = MsgBoxResult.Yes Then
        Else
            e.Cancel = True
        End If

    End Sub

    Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        If Keys.Escape Then
            Me.Close()
        Else
        End If
    End Sub
Luc001 77 Posting Whiz

Hi,

Change this part of code:

Private Sub frmMain_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        If Keys.Escape Then
            Me.Close()
        Else
        End If
    End Sub
Luc001 77 Posting Whiz

i have managed to connect vb.net to Microsoft database access but now i am struggling with the code to authentication log in. when i log in to the form i want it to display the user name in the label in vb.net form.

Hi,

After the authentication log in was succesfull your application ( second form) will open.
Here's an example to show how you can do it with just 2 forms.
Create a new testapplication and add 2 forms, in form1 add a Button1 and textbox1 and in form2 a Label1, then try this:

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Form2 As New Form2
        Form2.Label1.Text = TextBox1.Text
        Form2.Show()
    End Sub

    
End Class
Luc001 77 Posting Whiz

Hi,

I think you can't, because your making a printscreen and that will be printing.

What you need is the create a bitmap that only prints the client area.
here's an example:

Private Declare Auto Function BitBlt Lib "gdi32.dll" (ByVal _
    hdcDest As IntPtr, ByVal nXDest As Integer, ByVal _
    nYDest As Integer, ByVal nWidth As Integer, ByVal _
    nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc _
    As Integer, ByVal nYSrc As Integer, ByVal dwRop As _
    System.Int32) As Boolean
Private Const SRCCOPY As Integer = &HCC0020

' Variables used to print.
Private m_PrintBitmap As Bitmap
Private WithEvents m_PrintDocument As PrintDocument

' Print the picture.
Private Sub btnPrint_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnPrint.Click
    ' Copy the form's image into a bitmap.
    m_PrintBitmap = GetFormImage()

    ' Make a PrintDocument and print.
    m_PrintDocument = New PrintDocument
    m_PrintDocument.Print()
End Sub

Private Function GetFormImage() As Bitmap
    ' Get this form's Graphics object.
    Dim me_gr As Graphics = Me.CreateGraphics

    ' Make a Bitmap to hold the image.
    Dim bm As New Bitmap(Me.ClientSize.Width, _
        Me.ClientSize.Height, me_gr)
    Dim bm_gr As Graphics = me_gr.FromImage(bm)
    Dim bm_hdc As IntPtr = bm_gr.GetHdc

    ' Get the form's hDC. We must do this after 
    ' creating the new Bitmap, which uses me_gr.
    Dim me_hdc As IntPtr = me_gr.GetHdc

    ' BitBlt the form's image onto the Bitmap.
    BitBlt(bm_hdc, 0, 0, Me.ClientSize.Width, _
        Me.ClientSize.Height, _
        me_hdc, 0, 0, SRCCOPY)
    me_gr.ReleaseHdc(me_hdc)
    bm_gr.ReleaseHdc(bm_hdc)

    ' Return the result.
    Return bm
End Function

' Print the form …
Luc001 77 Posting Whiz

Hi,

I've tryed the code and works like it should, that means if you start then the counting is running until the time 60 sec. is passed and the messagebox will pop up. If you stop, the labels are showing the time left.

Public Class Form1
    Private CountDownTime As Date

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        btnStartStop.Text = "Start"
    End Sub

    Private Sub btnStartStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartStop.Click
        If btnStartStop.Text = "Start" Then
            CountDownTime = Now.AddMinutes(1) 'changed the "span" to 1 for testing            
            Dim ts As TimeSpan = CountDownTime.Subtract(Now)
            Min.Text = ts.Minutes.ToString
            Sec.Text = ts.Seconds.ToString
            Timer1.Start()
            btnStartStop.Text = "Stop"
        Else
            Timer1.Stop()
            btnStartStop.Text = "Start"
        End If
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If CountDownTime < Now Then
            Timer1.Stop()
            MessageBox.Show("You have run out of time.")
            btnStartStop.Text = "Start"
        Else

            Dim ts As TimeSpan = CountDownTime.Subtract(Now)
            Min.Text = ts.Minutes.ToString
            Sec.Text = ts.Seconds.ToString

        End If
    End Sub

End Class
Luc001 77 Posting Whiz

Hi,

You can try something like this:

Dim myReport as new ReportDocument()
myReport.Load("C:\myReport.rpt")
'Pass database and Parameter info here
myReport.PrinttoPrinter(1,true,0,0) 'This prints one copy of all pages to the default printer, and collates them
Luc001 77 Posting Whiz

Hi All to members,

My name is Luc and I'm very interested in VB. Net.
I think that in this forum, I'll see a lot of unsolved projects to try out and learn from them.
To become a better programmer.

Thanks in advance for all the help.

Greets,

Luc001

Luc001 77 Posting Whiz

Hi,

You can try this in a button event:

For Each ctrl As Control In GroupBox1.Controls

            CType(ctrl, RadioButton).Checked = False

        Next