By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,335 Members | 2,218 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,335 IT Pros & Developers. It's quick & easy.

Click event in an If to check if already clicked...

P: 2
Hello,

I have a custom maximize box made for my application. I want it to be so that when I click it once then it maximizes, but if I click it again, it returns to the previous size. My code:
Expand|Select|Wrap|Line Numbers
  1.     Private Sub PictureBox3_Click(sender As Object, e As EventArgs) Handles PictureBox3.Click
  2.         Me.WindowState = FormWindowState.Maximized
  3.         If WindowState = FormWindowState.Maximized Then
  4.             If PictureBox3.click() Then Close()
  5.         End If
  6.     End Sub
Error: is an event handler and cannot be called directly, use "raiseevent" instead.
Aug 3 '15 #1
Share this Question
Share on Google+
2 Replies


P: 2
Ok, i put if event and it seems ok but says expression expected. WTH?
Aug 3 '15 #2

!NoItAll
100+
P: 296
I don't think you can do:
Expand|Select|Wrap|Line Numbers
  1. If PictureBox3.click() then Close
First off PictureBox3.click is a method and it does not return a boolean.
Second - calling Picturebox3.click inside PictureBox3_click (which handles Picutebox3.click) is recursive and bound to just get you into trouble...
Instead try...
Expand|Select|Wrap|Line Numbers
  1. Private Sub PictureBox3_Click(sender As Object, e As EventArgs) Handles PictureBox3.Click
  2.         Static bClicked as Boolean = False
  3.         if bClicked = False then
  4.             bClicked = True
  5.             Me.WindowState = FormWindowState.Maximized
  6.         End if
  7.     End Sub
  8.  
Of course you have no way to then minimize or normalize the form. Instead I would recommend you set it up as a toggle...
Expand|Select|Wrap|Line Numbers
  1. Private Sub PictureBox3_Click(sender As Object, e As EventArgs) Handles PictureBox3.Click
  2.         If Me.WindowState = FormWindowState.Maximized Then
  3.             Me.WindowState = FormWindowState.Normal
  4.         Else
  5.             Me.WindowState = FormWindowState.Maximized
  6.         End If
  7. End Sub
  8.  
This sets up a nice toggle between normal and maximized.
Aug 19 '15 #3

Post your reply

Sign in to post your reply or Sign up for a free account.