8 Replies - 300 Views - Last Post: 04 January 2018 - 11:45 AM Rate Topic: -----

#1 JoeBobJr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 23-December 17

How do I fix borders being drawn in wrong places?

Posted 04 January 2018 - 08:42 AM

There isn't enough room for me to make a detailed enough question for the topic. The question is...

How do I fix borders that are being drawn in wrong places of my app after the form leaves the monitor and returns?

I don't know how else to ask this question.

I'm using a borderless form, borderless controls. I'm drawing a dashed border around these controls to make them look nice using the OnPaint override event to paint these borders. The problem I'm having is when I drag my form past the boundary of the monitor or any monitor for that matter, as soon as I get the app back within the screen resolution it draws a ton of borders across my app as shown in the picture.

I set up a timer that ticks every 15 seconds and all it does is Me.Refresh() and it works. I honestly don't know if refreshing the form this often is a bad thing since I'm not the greatest coder. I've never read any books, watched tutorials, or any of that to learn how to code. I learn from hands on examples so it takes me a little longer to learn than most so I apologize if my questions aren't very clear I'm doing the best I can do.

I've tried to use the Move event also to refresh the form on move but then it makes the form blink like crazy so that didn't work. I've tried all sorts of stuff trying to fix this problem with no luck. I ran into the code below that tells if the form is within the screen resolution of the monitor but I'm not sure how to edit it so that it checks if the app leaves the monitor and comes back. I would like some help to edit this code to do what I'm looking for if its possible.

An example of what is actually happening is below.

Posted Image

Public Function IsOnScreen(ByVal form As Form) As Boolean
        Dim screens() As Screen = Screen.AllScreens

        For Each scrn As Screen In screens
            Dim formRectangle As Rectangle = New Rectangle(form.Left, form.Top, form.Width, form.Height)

            If scrn.WorkingArea.Contains(formRectangle) Then
                Return True
            End If
        Next

        Return False
    End Function



Is This A Good Question/Topic? 0
  • +

Replies To: How do I fix borders being drawn in wrong places?

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13658
  • View blog
  • Posts: 54,521
  • Joined: 12-June 08

Re: How do I fix borders being drawn in wrong places?

Posted 04 January 2018 - 08:52 AM

What's the onpaint look like? Seems like that would be the crux of the issue there.

Quote

I've never read any books, watched tutorials, or any of that to learn how to code. I learn from hands on examples so it takes me a little longer to learn than most so I apologize if my questions aren't very clear I'm doing the best I can do.

Side question - have you considered picking up a book or taking a class? Typically it saves a bundle of time.
Was This Post Helpful? 0
  • +
  • -

#3 JoeBobJr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 23-December 17

Re: How do I fix borders being drawn in wrong places?

Posted 04 January 2018 - 08:56 AM

View Postmodi123_1, on 04 January 2018 - 08:48 AM, said:

What's the onpaint look like? Seems like that would be the crux of the issue there.


Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        ' This is the override paint event that will allow us to draw all our borders
        addBorders(e)
    End Sub

Public Sub addBorders(ByVal e As PaintEventArgs)
    For Each ctl As Control In Me.Controls
        Select Case True
            Case TypeOf (ctl) Is TextBox
                ctl.AutoSize = False
                ctl.Height = 19
                Dim borderRectangle As Rectangle = New Rectangle(ctl.Location, ctl.Size)
                borderRectangle.Inflate(1, 1)
                ControlPaint.DrawBorder(e.Graphics, borderRectangle, ctl.ForeColor, ButtonBorderStyle.Dashed)
            Case TypeOf (ctl) Is ComboBox, TypeOf (ctl) Is Button
                Dim borderRectangle As Rectangle = New Rectangle(ctl.Location, ctl.Size)
                borderRectangle.Inflate(1, 1)
                ControlPaint.DrawBorder(e.Graphics, borderRectangle, ctl.ForeColor, ButtonBorderStyle.Dashed)
                ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, ctl.ForeColor, ButtonBorderStyle.Dashed)
            End Select
        Next
    End Sub



I'm mainly trying to do it with the override event so that I don't have to put this type of code in every single onpaint event for each control which would kind of suck. If that's the only way I'm willing to do that. I just feel like some editing of my code might fix the issue here.

Quote

Side question - have you considered picking up a book or taking a class? Typically it saves a bundle of time.


Yes I tried many times to pick up a book and I have a hard time reading so I read something many times and still don't understand what I just read so I end up just throwing the book across the room. I've been able to do some learning from youtube videos but then I run into something like this where there aren't any videos showing what I need. I researched this problem for 3 days now trying to find a way to fix it. I'm stuck. I honestly hate asking questions. I prefer to figure it out on my own.

This post has been edited by JoeBobJr: 04 January 2018 - 09:04 AM

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13658
  • View blog
  • Posts: 54,521
  • Joined: 12-June 08

Re: How do I fix borders being drawn in wrong places?

Posted 04 January 2018 - 09:07 AM

Great googlie-mooglie. So you have that and decided to have a timer to kick off a refresh ever X minutes as well? Way down the wrong rabbit hole.

Have you considered the simpler solution of having specific images with the border and using that as a form's background image?
Was This Post Helpful? 0
  • +
  • -

#5 JoeBobJr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 23-December 17

Re: How do I fix borders being drawn in wrong places?

Posted 04 January 2018 - 09:12 AM

View Postmodi123_1, on 04 January 2018 - 09:07 AM, said:

Great googlie-mooglie. So you have that and decided to have a timer to kick off a refresh ever X minutes as well? Way down the wrong rabbit hole.

Have you considered the simpler solution of having specific images with the border and using that as a form's background image?


Yes I've considering using something like a panel which I read works for a borderless form to add a border. How does that work for the textboxes though? Does adding the textboxes on the panel allow borders to be placed around them also? From what I've been seeing the buttons at the top of the form aren't even redrawing when the form leaves and comes back. It seems to only be happening with the textbox borders or the form border. The button borders seem to always stay intact in their right location.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13658
  • View blog
  • Posts: 54,521
  • Joined: 12-June 08

Re: How do I fix borders being drawn in wrong places?

Posted 04 January 2018 - 09:16 AM

*shrug* It's hard to tell with only seeing glimpets of what's going on.. and especially hard to guess given a lack of programming baseline... so maybe?

Side note you can't have a random free floating panel with out a container for it like a form.

Taking a wild guess and maybe this may help.
http://www.dreaminco...an-application/
Was This Post Helpful? 0
  • +
  • -

#7 JoeBobJr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 23-December 17

Re: How do I fix borders being drawn in wrong places?

Posted 04 January 2018 - 09:20 AM

View Postmodi123_1, on 04 January 2018 - 09:16 AM, said:

*shrug* It's hard to tell with only seeing glimpets of what's going on.. and especially hard to guess given a lack of programming baseline... so maybe?

Side note you can't have a random free floating panel with out a container for it like a form.

Taking a wild guess and maybe this may help.
http://www.dreaminco...an-application/


I found the problem! It's the last line of code in the code I provided that draws the border around the form. I placed it in that location because I believe I was trying to use it in the Form_OnPaint event and it wasn't working because I'm using the Override event. Maybe I should add

TypeOf (ctl) Is Form



To the second Case in the code and maybe it will draw the border. Honestly I feel like I've already tried this and it didn't work hence the reason I placed it where it is.

EDIT: I just tested it and that's correct adding the Form code in does not draw the border on the form.

Case TypeOf (ctl) Is ComboBox, TypeOf (ctl) Is Button, TypeOf (ctl) Is Form
    Dim borderRectangle As Rectangle = New Rectangle(ctl.Location, ctl.Size)
    borderRectangle.Inflate(1, 1)
    ControlPaint.DrawBorder(e.Graphics, borderRectangle, ctl.ForeColor, ButtonBorderStyle.Dashed)



The form is left borderless while all other controls get the border.

Private Sub frmMain_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
   ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, Me.ForeColor, ButtonBorderStyle.Dashed)
End Sub



This code also does not work obviously because of the override event. I have no idea why the TypeOf (ctl) Is Form is not working though.

This post has been edited by JoeBobJr: 04 January 2018 - 09:26 AM

Was This Post Helpful? 0
  • +
  • -

#8 JoeBobJr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 23-December 17

Re: How do I fix borders being drawn in wrong places?

Posted 04 January 2018 - 09:45 AM

I believe I see the problem. First I believe that a form is not a control. My code searches all controls not forms. I will have to figure out how to use a loop to search for the forms and then draw borders I think?
Was This Post Helpful? 0
  • +
  • -

#9 JoeBobJr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 23-December 17

Re: How do I fix borders being drawn in wrong places?

Posted 04 January 2018 - 11:45 AM

I'm answering my own question because I've finally got it working.

First of all I changed how I was drawing the border around the form.
    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        ' This is the override paint event that will allow us to draw all our borders
        addBorders(e)
        If e.ClipRectangle.X = 0 Then
            Dim dashValues As Single() = {3, 1, 3, 1}
            Dim p As New Pen(btnExit.ForeColor, 1)
            p.DashPattern = dashValues
            e.Graphics.DrawRectangle(p, 0, 0, Me.Width - 1, Me.Height - 1)
        End If
    End Sub


Which worked perfect! There was still a small issue with going off the screen it would still mess the border up some so I added a Me.Refresh() code on the form_mouseup event so when the form is dropped it refreshes and fixes the problem.

    Private Sub frmMain_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp
        Me.Refresh()
    End Sub


It's not exactly what I would have liked to have but it works way better this way than the other way.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1