Welcome Guest [Log In] [Register]
Viewing Single Post From: Note program
Hacker-X
Dedicated Member
[ *  *  *  * ]
You should end up having something like this at the end of the tutorial:
Posted Image


Lets start by creating a textbox with these settings:
Anchor: Top, Bottom, Left, Right
Multiline: True
ScrollBars: Vertical

Add a font dialog.

Add a timer with these settings:
Name: TmrListen
Interval: 10

Make a label with these settings:
Name: Label1
Anchor: Top, Left
Text: Notes

Next we'll make a checkbox with these settings:
Anchor: Top, Right
Text: Make me topmost

To hide our form we'll need a button with these settings:
Name: Button4
Anchor: Top, Right
Text: Hide

To minimize our form we'll need another button with these settings:
Name: Button2
Anchor: Top, Right
Text: -

In order to close our form we'll need an additional button with these settings:
Name: Button1
Anchor: Top, Right
Text: X

To change font we'll need to add one last button, with these settings:
Name: Button3
Anchor: Bottom, Left
Text: Change Font

We'll need a label, with these settings:
Name: Label2
Anchor: Bottom, Right
Text: Opacity

And the final control, a trackbar, with these settings:
Anchor: Bottom, Right
Maximum: 100
Tickfrequency: 20
Tickstyle: TopLeft
Value: 100

Change the form settings to:
BackColor: White
Controlbox: False
FormBorderStyle: Sizeable
Showintaskbar: False
Text: (None)


On to the code:
This API is used to listen for keys to be pressed. We have to use the integer data type otherwise we'll cause a PInvoke error.
Code:
 

   Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Integer) As Integer


This'll allow the form to close when the close button is clicked.
Code:
 

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Me.Close()
   End Sub


This code will change the form opacity when the trackbar moves.
Code:
 

   Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
       Me.Opacity = (TrackBar1.Value / 100)
   End Sub


This will let the form move when you click on the form.
Code:
 

   Const WM_NCHITTEST As Integer = &H84
   Const HTCLIENT As Integer = &H1
   Const HTCAPTION As Integer = &H2

   Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
       Select Case m.Msg
           Case WM_NCHITTEST
               MyBase.WndProc(m)
               If m.Result = HTCLIENT Then m.Result = HTCAPTION
           Case Else
               MyBase.WndProc(m)
       End Select
   End Sub


Minimizes the form.
Code:
 

   Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
       Me.WindowState = FormWindowState.Minimized
   End Sub


Make the font dialog pop-up.
Code:
 

   Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
       FontDialog1.ShowDialog()
       FontDialog1.ShowEffects = True
       FontDialog1.MinSize = 8
       FontDialog1.MaxSize = 15
       FontDialog1.FontMustExist = True
       FontDialog1.AllowVectorFonts = True
       If Windows.Forms.DialogResult.OK Then
           TextBox1.Font = FontDialog1.Font
       End If
   End Sub


Assign the timer to listen for keys.
(If you want to change the key combination then scroll down to the end of the tutorial.)
Code:
 

   Private Sub TmrListen_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TmrListen.Tick
       If GetAsyncKeyState(17) And GetAsyncKeyState(16) And GetAsyncKeyState(18) Then
           Me.Show()
       End If
   End Sub


Pops-up a message box telling the user what key combination to use to show the form again.
Code:
 

   Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
       MessageBox.Show("Press control + shift + alt to show the window again.", "Hide window", MessageBoxButtons.OK, MessageBoxIcon.Information)
       TmrListen.Enabled = True
       Me.Hide()
   End Sub


Decides whether or not to make the form topmost or not.
Code:
 

   Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
       If CheckBox1.Checked = True Then
           Me.TopMost = True
       Else
           Me.TopMost = False
       End If
   End Sub


Put a check in the "Make me topmost" checkbox on form load.
Code:
 

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       CheckBox1.Checked = True
   End Sub




Changing the key combination.
If you want to use different key combinations then navigate your browser to http://www.xamlon.com/docs/swfnative/SwfNative.KeyCode.html to get the correct keycode.

Here's an example,
Code:
 

   Private Sub TmrListen_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TmrListen.Tick
       If GetAsyncKeyState(13) Then
           Me.Show()
       End If
   End Sub


The GetAsyncKeyState is calling the API and in order to use this API we must specify what key using keycodes.

If you want multiple keys to show the note program we just made you can use the OR, or AND operators.

Not bad for 10 minutes of work, right?
Offline Profile Quote Post
Note program · Visual Basic