1 Replies - 1031 Views - Last Post: 25 September 2012 - 11:01 AM Rate Topic: -----

#1 klturi421  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-May 11

Bind F12 key with IF Else statement

Posted 24 September 2012 - 12:41 PM

Im trying to figure out how to have an IF ELSE statement to allow borderless mode to be activated or deactivated based on the current state and the keypress.

This is the code that I have so far:
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None

Im not sure what the alternative style is at the moment (not currently at my VB workstation, just doing some research else where) but I will determine that here in a little bit once im there. Anyway. I basically want to be able to press F12 and have it activate or deactivate but not sure how to write the statement. Any help would be great. Im still searching and if I come across an answer Ill be sure to answer it myself here to close it out.

Is This A Good Question/Topic? 0
  • +

Replies To: Bind F12 key with IF Else statement

#2 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 314
  • View blog
  • Posts: 1,296
  • Joined: 12-September 12

Re: Bind F12 key with IF Else statement

Posted 25 September 2012 - 11:01 AM

First, set the KeyPreview property. I chose to do it in the Form.Load routine. I am assuming you want the form itself to change border styles.
    Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Me.KeyPreview = True
    End Sub

Then, add the code to capture the key and act on it.

    Private Sub Form1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.F12 Then
            If Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None Then
                Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Fixed3D
                Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
            End If
        End If
    End Sub

Hope this helps.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1