none
FormWindowState Code Appear to Stop 'Call' from working RRS feed

  • General discussion

  • I call on the sub "Call LoadMap()" in two buttons and in 2 events.

    It works in every instance except for in the sub "btn_ToggleScreen_Click"

    It is meant to refresh the loadmap code but doesn't... it clears the picturebox

    Can you please look at the code and make a suggestion as to where I am going wrong...

    Public Class frm_Map
    
        Public FullScreenStatus As Boolean = False
        Public BrushRed As New System.Drawing.SolidBrush(System.Drawing.Color.Red)
        Public BrushBlue As New System.Drawing.SolidBrush(System.Drawing.Color.Blue)
        Public DrawStyle = BrushRed
    
        Private Sub frm_Map_ResizeEnd(sender As Object, e As EventArgs) Handles Me.ResizeEnd
            Call LoadMap()
        End Sub
    
        Private Sub btn_LoadMap_Click(sender As Object, e As EventArgs) Handles btn_LoadMapClearMap.Click
    
            Call LoadMap()
    
        End Sub
    
        Private Sub btn_ToggleScreen_Click(sender As Object, e As EventArgs) Handles btn_ToggleScreen.Click
    
            Call CenterToScreen()
    
            If Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None And Me.WindowState = FormWindowState.Maximized Then
                FullScreenStatus = False
                Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable
                Me.WindowState = FormWindowState.Normal
                Me.Controls.Item("btn_ToggleScreen").Text = "Full Screen"
            Else
                FullScreenStatus = True
                Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
                Me.WindowState = FormWindowState.Maximized
                Me.Controls.Item("btn_ToggleScreen").Text = "Normal Screen"
            End If
    
            'Call LoadMap()
    
        End Sub
    
        Private Sub frm_Map_Resize(sender As Object, e As EventArgs) Handles Me.Resize
    
            Dim FullScreenFudgeFactor_Width As Integer : FullScreenFudgeFactor_Width = 0
            Dim FullScreenFudgeFactor_Height As Integer : FullScreenFudgeFactor_Height = 0
    
            If FullScreenStatus = True Then
                FullScreenFudgeFactor_Width = 18
                FullScreenFudgeFactor_Height = 40
            End If
    
            pbx_Map.Width = Me.Width - 150 + FullScreenFudgeFactor_Width
            pbx_Map.Height = Me.Height - 50 + FullScreenFudgeFactor_Height
    
        End Sub
    
        Private Sub LoadMap()
    
            Dim DrawEntity As System.Drawing.Graphics
            Dim DrawEntity_X As Integer
            Dim DrawEntity_Y As Integer
            Dim DrawEntity_Dia As Integer
    
            'Name, X, Y, Dia, ProbeType
            'DrillBrushColour, ProbeBrushColour
    
            DrawEntity_X = 10
            DrawEntity_Y = 20
            DrawEntity_Dia = 10
    
            DrawEntity = pbx_Map.CreateGraphics
            DrawEntity.FillEllipse(DrawStyle, DrawEntity_X, DrawEntity_Y, DrawEntity_Dia, DrawEntity_Dia)
    
        End Sub
    
        Private Sub btn_ToggleViewType_Click(sender As Object, e As EventArgs) Handles btn_ToggleViewType.Click
    
            If Me.Controls.Item("btn_ToggleViewType").Text = "View By Drill Size" Then
                Me.Controls.Item("btn_ToggleViewType").Text = "View By Probe Type"
                DrawStyle = BrushBlue
            Else
                Me.Controls.Item("btn_ToggleViewType").Text = "View By Drill Size"
                DrawStyle = BrushRed
            End If
    
            Call LoadMap()
    
        End Sub
        Private Sub btn_End_Click(sender As Object, e As EventArgs) Handles btn_Exit.Click
            End
        End Sub
    
    End Class
    


    Wednesday, October 16, 2019 11:08 AM

All replies

  • Does this code run?

        
        Public DrawStyle = BrushRed

    Strange nowhere is told what DrawStyle is or what BrushRed is. 

    I know these as properties of Drawing, but you use them as your own identifiers 

    Can you tell how you got this build?

    Also it is strange why you want to kill everything around the program and don't want it to close properly after the exit button is clicked. 


    Success
    Cor



    • Edited by Cor Ligthert Wednesday, October 16, 2019 11:36 AM
    Wednesday, October 16, 2019 11:32 AM

  • Regards Les, Livingston, Scotland


    • Edited by leshay Wednesday, October 16, 2019 2:19 PM Thanks for changing to a Code Block
    Wednesday, October 16, 2019 11:59 AM
  • .......

    It works in every instance except for in the sub "btn_ToggleScreen_Click"

    It is meant to refresh the loadmap code but doesn't... it clears the picturebox

    Can you please look at the code and make a suggestion as to where I am going wrong...

    Hi

    Is the call to LoadMap within that particular Sub actually commented out?

    Also, please change post type to Question rather than Discussion.


    Regards Les, Livingston, Scotland


    • Edited by leshay Wednesday, October 16, 2019 12:04 PM
    Wednesday, October 16, 2019 12:03 PM
  • Hi Cor...

    Yeh the code runs fine... except for the weird issue i'm having.

    Two lines above you'll see...

    Public BrushRed As New System.Drawing.SolidBrush(System.Drawing.Color.Red)

    I wrote the build from scratch; I'm more adept at vba, my vb is a little rusty.

    The exit button was just a quick kill while I test the code.

    Wednesday, October 16, 2019 12:47 PM
  • Sweet... I was wondering how folk did that.

    Took me a bit of googling to find out what you meant.

    regards

    Wednesday, October 16, 2019 12:50 PM
  • Hi Les...

    It should run from the...

    "frm_Map_ResizeEnd(sender As Object, e As EventArgs) Handles Me.ResizeEnd"

    ...event; which it does when you use the drag handles.

    But I have been trying different events and different locations for the "Call LoadMap()". As such, there is an instance of the "Call LoadMap()" commented out under the...

    "btn_ToggleScreen_Click(sender As Object, e As EventArgs) Handles btn_ToggleScreen.Click"

    ...event; that was where I initially had it as I thought that would be fine.

    Wednesday, October 16, 2019 12:58 PM
  • Hi Les...

    It should run from the...

    "frm_Map_ResizeEnd(sender As Object, e As EventArgs) Handles Me.ResizeEnd"

    ...event; which it does when you use the drag handles.

    But I have been trying different events and different locations for the "Call LoadMap()". As such, there is an instance of the "Call LoadMap()" commented out under the...

    "btn_ToggleScreen_Click(sender As Object, e As EventArgs) Handles btn_ToggleScreen.Click"

    ...event; that was where I initially had it as I thought that would be fine.

    Hi

    OK, confused here. In first post you said 'It works in every instance except for in the sub "btn_ToggleScreen_Click"' and I believe iti s commented out there - so what/where is the actual issue then?


    Regards Les, Livingston, Scotland

    Wednesday, October 16, 2019 2:18 PM
  • Stuart,

    You are not persisting the image.

    When you use create graphics like you are it gets cleared the next time you resize the control.

    Use the e.graphics drawing surface in the control paint event to draw. Then in the resize event use control.invalidate to cause the paint event to be called by the system.

    Wednesday, October 16, 2019 2:20 PM
  • The "btn_ToggleScreen_Click" resizes the form to fullscreen.

    When "Call LoadMap" is in the sub "btn_ToggleScreen_Click", it doesn't work.

    When "Call LoadMap" is in the sub "frm_Map_ResizeEnd", it works when you resize the form using the drag handles but it doesn't work when you press the "btn_ToggleScreen_Click".

    Wednesday, October 16, 2019 2:27 PM
  • Stuart, 

    By using Visual Studio, your code will not build (compile)

    So their are 2 cenario's for what I can think:

    1. You don't us Visual Studio but code in a textbox
    2. You click on run previous build (which means that you are using an old compiled program)

      Public DrawStyle = BrushRed 

    That is simply impossible to build it violates not only one thing, it violates a lot in VB. And in VBA it does not exist. 


    Success
    Cor

    Wednesday, October 16, 2019 3:14 PM
  • Hi

    So, as I understand it, the Sub LoadMap is indeed working when successfully called. This suggests that you need to put a break point ion the line Call CenterToScreen() within the  Sub btn_ToggleScreen_Click and then single step through code, I suspect the Call LoadMap is not being reached - is the Call CenterToScreen() maybe causing an exception - I can't find that Sub.

    Also, check out Tommy post above.


    Regards Les, Livingston, Scotland

    Wednesday, October 16, 2019 3:17 PM