none
VB shape offset problem RRS feed

  • Question

  • When I start the form my shape isn't placed on the spot it is in the form.desing.

    I know multiple people that have this issue.

    I rebuild my program in visual studio 2017 and downloaded the power pack because it isn't included any more. but I had the same problem. the shape isn't placed on the spot it is in the form.desing.

    only solution I have found is too set the shape more too the right and higher in the dising.

    this is not a very good solution because the shape is then covering up my radio buttons.

    does someone know what the problem can be.

    https://social.msdn.microsoft.com/Forums/getfile/1194824

    Wednesday, December 20, 2017 8:24 PM

Answers

  • https://1drv.ms/f/s!AvEThw1vID63irJg016l7JhJi0HL4Q

    it is for a school. we need to adjust the shape height so it looks like a coffee cup that is being filled. this is done with a timer. it works but the shape is not on the same spot on the design as it is in the running program.

     Looking at your picture of the form in the designer window and the one of it running,  it appears that your computer's "Display" settings (Font Scaling) in the Control Panel might be set to something larger than 100%.  You have not answered my question about that yet.

     However,  i would suggest getting rid of the old outdated Shape controls and do one of the following....

     

    1.  Use two PictureBoxes instead of the old VB Shape controls.  Make one have a FixedSingle border and set it's BackColor to the Coffee color.  Then place another over top of it and set it's BackColor to the Form's BacKColor.  Then just subtract 1 from the height of it until it is 1.  1 is so, you are still covering the top border of the first PictureBox.

     You can test this in a new form project with 2 PictureBoxes and 1 Button added to the form...

    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            PictureBox1.BorderStyle = BorderStyle.FixedSingle
            PictureBox1.BackColor = Color.Peru
            PictureBox1.Bounds = New Rectangle(Button1.Left, Button1.Top - 12 - 140, Button1.Width, 140)
            PictureBox1.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right

            PictureBox2.BackColor = Me.BackColor
            PictureBox2.Bounds = New Rectangle(PictureBox1.Left + 1, PictureBox1.Top, PictureBox1.ClientSize.Width, PictureBox1.Height - 1)
            PictureBox2.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
            PictureBox2.BringToFront()

            Timer1.Interval = 30
        End Sub

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            PictureBox2.Bounds = New Rectangle(PictureBox1.Left + 1, PictureBox1.Top, PictureBox1.ClientSize.Width, PictureBox1.Height - 1)
            Timer1.Start()
        End Sub

        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            PictureBox2.Height -= 1
            If PictureBox2.Height = 1 Then Timer1.Stop()
        End Sub
    End Class

    2.  Use 1 PictureBox on the form and draw the lines and filling color directly on the PictureBox using it's Paint event....

    Public Class Form1
        Private FilledTo As Integer = 0
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            PictureBox1.BorderStyle = BorderStyle.None
            PictureBox1.BackColor = Color.Transparent
            Timer1.Interval = 30
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            FilledTo = 0
            Timer1.Start()
        End Sub
    
        Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
            e.Graphics.DrawLine(Pens.Black, 0, 0, 0, PictureBox1.Height)
            e.Graphics.DrawLine(Pens.Black, 0, PictureBox1.Height - 1, PictureBox1.Width - 1, PictureBox1.Height - 1)
            e.Graphics.DrawLine(Pens.Black, PictureBox1.Width - 1, 0, PictureBox1.Width - 1, PictureBox1.Height - 1)
            e.Graphics.FillRectangle(Brushes.BurlyWood, 1, PictureBox1.Height - 1 - FilledTo, PictureBox1.Width - 2, FilledTo)
        End Sub
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            FilledTo += 1
            Me.Invalidate(False)
            If FilledTo = PictureBox1.Height - 1 Then
                Timer1.Stop()
                Me.Text = "The Cup Is Full..."
            End If
        End Sub
    End Class

     

    3. Draw the line and filling color directly onto the Form in it's Paint event...

    Public Class Form1
        Private FilledTo As Integer = 0
        Private CoffeeCupHeight As Integer = 140 'the fixed height of the coffee cup
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.DoubleBuffered = True
            Me.ResizeRedraw = True
            Timer1.Interval = 30
            Button1.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
            Button2.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
            Button3.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            FilledTo = 0
            Timer1.Start()
        End Sub
    
        Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
            e.Graphics.DrawLine(Pens.Black, Button1.Left, Button1.Top - 12 - CoffeeCupHeight, Button1.Left, Button1.Top - 12)
            e.Graphics.DrawLine(Pens.Black, Button1.Left, Button1.Top - 12, Button1.Right, Button1.Top - 12)
            e.Graphics.DrawLine(Pens.Black, Button1.Right, Button1.Top - 12 - CoffeeCupHeight, Button1.Right, Button1.Top - 12)
            e.Graphics.FillRectangle(Brushes.BurlyWood, Button1.Left + 1, Button1.Top - 12 - FilledTo, Button1.Width - 1, FilledTo)
        End Sub
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            FilledTo += 1
            Me.Invalidate(False)
            If FilledTo = CoffeeCupHeight Then
                Timer1.Stop()
                Me.Text = "The Cup Is Full..."
            End If
        End Sub
    End Class

     

     


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Friday, December 22, 2017 8:26 PM
    • Marked as answer by fsdex Friday, December 22, 2017 11:27 PM
    Friday, December 22, 2017 8:25 PM

All replies

  • does someone know what the problem can be.

    Using the Power Pack is the problem. Now you know why it is discontinued.

    If you can show an image of what you use the shape for or the result you want to achieve we can probably give a different solution than using the power pack.

    Otherwise you will have to show the code you use with the powerpack or a simple example or a image if you can.


    PS Oh, sorry I see you gave a link.

    Can you a make a picture of what you want it to look like?

    I guess you have a rectangle shape there?

    Also is the shape set to dock or have any properties like that? Anchor? Is there any automatic properties for any other controls or the form set?


    Wednesday, December 20, 2017 8:34 PM
  • fsdex,

     Are you and the others that have this problem have your computer's "Display Settings" set to use a higher font scaling than 100%?

     

     Tom,

     Got your email.  I will get back to you later.  8)


    If you say it can`t be done then i`ll try it

    Wednesday, December 20, 2017 8:43 PM
  • Hi fsdex,

    https://social.msdn.microsoft.com/Forums/getfile/1194824
    This URL cannot be found. Please provide a correct URL.

    Regards,

    Ashidacchi

    Thursday, December 21, 2017 4:02 AM
  • When I start the form my shape isn't placed on the spot it is in the form.desing.

    I know multiple people that have this issue.

    I rebuild my program in visual studio 2017 and downloaded the power pack because it isn't included any more. but I had the same problem. the shape isn't placed on the spot it is in the form.desing.

    Hi fsdex,

    You said that you download power pack, and it isn't included any more, your mean is that you can not see these shapes in the Toolbox or other?

    And you also said that the shape isn't placed on the spot it is in the form.desing. Can you describe more info about this?

    By the way, I cannot open the page that you provide.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, December 21, 2017 8:12 AM
    Moderator
  • https://1drv.ms/f/s!AvEThw1vID63irJg016l7JhJi0HL4Q

    it is for a school. we need to adjust the shape height so it looks like a coffee cup that is being filled. this is done with a timer. it works but the shape is not on the same spot on the design as it is in the running program.

    Friday, December 22, 2017 3:19 PM
  • https://1drv.ms/f/s!AvEThw1vID63irJg016l7JhJi0HL4Q

    it is for a school. we need to adjust the shape height so it looks like a coffee cup that is being filled. this is done with a timer. it works but the shape is not on the same spot on the design as it is in the running program.

     Looking at your picture of the form in the designer window and the one of it running,  it appears that your computer's "Display" settings (Font Scaling) in the Control Panel might be set to something larger than 100%.  You have not answered my question about that yet.

     However,  i would suggest getting rid of the old outdated Shape controls and do one of the following....

     

    1.  Use two PictureBoxes instead of the old VB Shape controls.  Make one have a FixedSingle border and set it's BackColor to the Coffee color.  Then place another over top of it and set it's BackColor to the Form's BacKColor.  Then just subtract 1 from the height of it until it is 1.  1 is so, you are still covering the top border of the first PictureBox.

     You can test this in a new form project with 2 PictureBoxes and 1 Button added to the form...

    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            PictureBox1.BorderStyle = BorderStyle.FixedSingle
            PictureBox1.BackColor = Color.Peru
            PictureBox1.Bounds = New Rectangle(Button1.Left, Button1.Top - 12 - 140, Button1.Width, 140)
            PictureBox1.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right

            PictureBox2.BackColor = Me.BackColor
            PictureBox2.Bounds = New Rectangle(PictureBox1.Left + 1, PictureBox1.Top, PictureBox1.ClientSize.Width, PictureBox1.Height - 1)
            PictureBox2.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
            PictureBox2.BringToFront()

            Timer1.Interval = 30
        End Sub

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            PictureBox2.Bounds = New Rectangle(PictureBox1.Left + 1, PictureBox1.Top, PictureBox1.ClientSize.Width, PictureBox1.Height - 1)
            Timer1.Start()
        End Sub

        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            PictureBox2.Height -= 1
            If PictureBox2.Height = 1 Then Timer1.Stop()
        End Sub
    End Class

    2.  Use 1 PictureBox on the form and draw the lines and filling color directly on the PictureBox using it's Paint event....

    Public Class Form1
        Private FilledTo As Integer = 0
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            PictureBox1.BorderStyle = BorderStyle.None
            PictureBox1.BackColor = Color.Transparent
            Timer1.Interval = 30
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            FilledTo = 0
            Timer1.Start()
        End Sub
    
        Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
            e.Graphics.DrawLine(Pens.Black, 0, 0, 0, PictureBox1.Height)
            e.Graphics.DrawLine(Pens.Black, 0, PictureBox1.Height - 1, PictureBox1.Width - 1, PictureBox1.Height - 1)
            e.Graphics.DrawLine(Pens.Black, PictureBox1.Width - 1, 0, PictureBox1.Width - 1, PictureBox1.Height - 1)
            e.Graphics.FillRectangle(Brushes.BurlyWood, 1, PictureBox1.Height - 1 - FilledTo, PictureBox1.Width - 2, FilledTo)
        End Sub
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            FilledTo += 1
            Me.Invalidate(False)
            If FilledTo = PictureBox1.Height - 1 Then
                Timer1.Stop()
                Me.Text = "The Cup Is Full..."
            End If
        End Sub
    End Class

     

    3. Draw the line and filling color directly onto the Form in it's Paint event...

    Public Class Form1
        Private FilledTo As Integer = 0
        Private CoffeeCupHeight As Integer = 140 'the fixed height of the coffee cup
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.DoubleBuffered = True
            Me.ResizeRedraw = True
            Timer1.Interval = 30
            Button1.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
            Button2.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
            Button3.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            FilledTo = 0
            Timer1.Start()
        End Sub
    
        Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
            e.Graphics.DrawLine(Pens.Black, Button1.Left, Button1.Top - 12 - CoffeeCupHeight, Button1.Left, Button1.Top - 12)
            e.Graphics.DrawLine(Pens.Black, Button1.Left, Button1.Top - 12, Button1.Right, Button1.Top - 12)
            e.Graphics.DrawLine(Pens.Black, Button1.Right, Button1.Top - 12 - CoffeeCupHeight, Button1.Right, Button1.Top - 12)
            e.Graphics.FillRectangle(Brushes.BurlyWood, Button1.Left + 1, Button1.Top - 12 - FilledTo, Button1.Width - 1, FilledTo)
        End Sub
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            FilledTo += 1
            Me.Invalidate(False)
            If FilledTo = CoffeeCupHeight Then
                Timer1.Stop()
                Me.Text = "The Cup Is Full..."
            End If
        End Sub
    End Class

     

     


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Friday, December 22, 2017 8:26 PM
    • Marked as answer by fsdex Friday, December 22, 2017 11:27 PM
    Friday, December 22, 2017 8:25 PM
  • thank you for replying.

    I have checked the display scaling in the properties of the form and it is set to 100%. windows scaling from my pc is also set to 100%.

    I have tried it with the Picture Boxes and it works but I can't youse it for my task because I need to do it with chapes. it is asked in the task description, but I will say it too my teacher next lesson that there is a better way and maybe next year he will do it this way.

    I have had the same problem with textboxes and labels but they do not change location that much.

    Friday, December 22, 2017 9:35 PM
  • I was unable to reproduce the problem in VS 2010. I checked with 125% scaling and no difference. I get the exact position I have in the designer when running.

    I don't have it installed other versions.

    So I suggest dex make a new one form project and don't change the defaults. Drop a rectangle shape on the form and a button next to it, see if you have the problem. If so we should be able to duplicate it. Tell us which version of Visual Studio you use I assume as you said 2017. If you have 2010 try with that maybe.

    If you don't have problems then you can step by step add things similar to your problem project until the problem starts. Or remove things from a copy of the problem project until is stops.

    Friday, December 22, 2017 9:43 PM
  • I have asked my teacher an I have done it your way it is much better no stutter any more.

    thx for helping. you are the best.

    good community.

    Friday, December 22, 2017 10:10 PM
  • I have asked my teacher an I have done it your way it is much better no stutter any more.

    thx for helping. you are the best.

    good community.

    dex,

    Please mark Razerz post as the answer if it solved your problem to close your question. Use the Mark as Answer link below the post.

    Friday, December 22, 2017 10:40 PM
  • I have asked my teacher an I have done it your way it is much better no stutter any more.

    thx for helping. you are the best.

    good community.

     Sorry for the delay.  Anyways,  i am glad you got it working and your teacher was cool about it.

     I know it is not up to you but,  your teacher(s) should be aware that the VB Shapes are outdated and they should not teach you to use them anymore.  It is better to take an approach that uses standard .Net controls or just draw the shapes.  8)

     Please don't forget to mark the post or posts that worked for you as the answer.  Thanks.  8)


    If you say it can`t be done then i`ll try it

    Friday, December 22, 2017 11:01 PM