PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
label1 not moving in position when zoom in, inside picturebox vb.net-VBForums
Results 1 to 8 of 8
  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2017
    Posts
    2

    label1 not moving in position when zoom in, inside picturebox vb.net

    hi guys please help me

    I have a label1 inside in picture box and panel when zoom in label1 move in position. I want to stay the label1 in position on designated position I choose in the picture box how can I do that?

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    4,499

    Re: label1 not moving in position when zoom in, inside picturebox vb.net

    You could start by showing your code.
    I have no idea how you are zooming in and positioning the label.
    If you're increasing the size of the picturebox to zoom in, then probably you would need to move the label to keep it location relative by %.

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,156

    Re: label1 not moving in position when zoom in, inside picturebox vb.net

    The Location of a Label control won't change on its own. If it's changing then it's because you're changing it. Most likely what is actually happening is that the Location is not changing but you actually do want it to, so that it stays in the same position relative to something else. All we can do is guess though, because you've provided next to no information. Please ALWAYS provide a FULL and CLEAR description of the problem, which includes exactly what you're trying to achieve, exactly how you're trying to achieve it (including relevant code) and exactly what happens when you try and how that differs from your expectations (including relevant error messages and locations). We only know what you tell us so you have to tell us everything that's relevant.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,015

    Re: label1 not moving in position when zoom in, inside picturebox vb.net

    Hi Asner,

    Welcome to the forum. You can't just drop a Label into a PictureBox in the Designer because a PictureBox isn't a Container Control - unlike say a Panel. But it's easy to do it in code: just make the picture box the Parent of the label. If you have already added the label in the Designer, its Location will now be wrong. In that case set the Left and Top properties relative to the parent coordinates, for example:
    Code:
    Label1.Parent = PictureBox1
    Label1.Left = 30
    Label1.Top = 25
    to set the Label1 at location 30,25 inside the picturebox.

    BB

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,156

    Re: label1 not moving in position when zoom in, inside picturebox vb.net

    Quote Originally Posted by boops boops View Post
    Hi Asner,

    Welcome to the forum. You can't just drop a Label into a PictureBox in the Designer because a PictureBox isn't a Container Control - unlike say a Panel. But it's easy to do it in code: just make the picture box the Parent of the label. If you have already added the label in the Designer, its Location will now be wrong. In that case set the Left and Top properties relative to the parent coordinates, for example:
    Code:
    Label1.Parent = PictureBox1
    Label1.Left = 30
    Label1.Top = 25
    to set the Label1 at location 30,25 inside the picturebox.

    BB
    In order to allow you to position the Label where you want it at design time and then simply change the Parent at run time, you can do this:
    vb.net Code:
    1. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    2.     Label1.Location = PictureBox1.PointToClient(Me.PointToScreen(Label1.Location))
    3.     Label1.Parent = PictureBox1
    4. End Sub
    Note that you can also edit the designer code file by hand to make the PictureBox the Parent of the Label. You would change this:
    vb.net Code:
    1. Me.Controls.Add(Me.Label1)
    to this:
    vb.net Code:
    1. Me.PictureBox1.Controls.Add(Me.Label1)
    The designer will not overwrite it when you make further changes because it is perfectly valid code.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2017
    Posts
    2

    Re: label1 not moving in position when zoom in, inside picturebox vb.net

    Quote Originally Posted by jmcilhinney View Post
    In order to allow you to position the Label where you want it at design time and then simply change the Parent at run time, you can do this:
    vb.net Code:
    1. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    2.     Label1.Location = PictureBox1.PointToClient(Me.PointToScreen(Label1.Location))
    3.     Label1.Parent = PictureBox1
    4. End Sub
    Note that you can also edit the designer code file by hand to make the PictureBox the Parent of the Label. You would change this:
    vb.net Code:
    1. Me.Controls.Add(Me.Label1)
    to this:
    vb.net Code:
    1. Me.PictureBox1.Controls.Add(Me.Label1)
    The designer will not overwrite it when you make further changes because it is perfectly valid code.





    here sir this is my test form codes

    Public Class testform
    Dim CurPicture As Integer = 1

    Private m_PanStartPoint As New Point


    Private _originalSize As Size = Nothing
    Private _scale As Single = 1
    Private _scaleDelta As Single = 0.0005




    Private Sub testform_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Label1.Location = PictureBox1.PointToClient(Me.PointToScreen(Label1.Location))
    Label1.Parent = PictureBox1

    'Panel Settings
    Panel1.AutoScroll = True

    'Picture Box Settings
    PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage

    'init this from here or a method depending on your needs
    If PictureBox1.Image IsNot Nothing Then
    PictureBox1.Size = Panel1.Size
    _originalSize = Panel1.Size

    End If


    Private Sub testform_MouseWheel(sender As Object, e As MouseEventArgs) Handles Me.MouseWheel


    _scaleDelta = Math.Sqrt(PictureBox1.Width * PictureBox1.Height) * 0.00005


    If e.Delta < 0 Then
    _scale -= _scaleDelta
    ElseIf e.Delta > 0 Then
    _scale += _scaleDelta
    End If





    If e.Delta <> 0 Then _
    PictureBox1.Size = New Size(CInt(Math.Round(_originalSize.Width * _scale)), _
    CInt(Math.Round(_originalSize.Height * _scale)))



    Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove

    If e.Button = Windows.Forms.MouseButtons.Left Then

    'Here we get the change in coordinates.
    Dim DeltaX As Integer = (m_PanStartPoint.X - e.X)
    Dim DeltaY As Integer = (m_PanStartPoint.Y - e.Y)

    'Then we set the new autoscroll position.
    'ALWAYS pass positive integers to the panels autoScrollPosition method
    Panel1.AutoScrollPosition = _
    New Drawing.Point((DeltaX - Panel1.AutoScrollPosition.X), _
    (DeltaY - Panel1.AutoScrollPosition.Y))
    End If
    Last edited by asner17; Dec 18th, 2017 at 01:04 PM.

  7. #7
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    4,499

    Re: label1 not moving in position when zoom in, inside picturebox vb.net

    So it is along the lines that I guessed, i.e. you change the size of the picturebox to implement zooming (the image is auto Stretched to fit).
    I don't see any mention of a label in the code.

    As stated earlier, if you have added a label at some point within the picture then you'll need to keep track of that position (unscaled).
    If you resize the picturebox by some scalefactor then you will need to scale the original location of the label by the same value so that its X,Y location remains relative to the pixel it was on unscaled.

    Of course there are better ways to do what you are attempting, most likely, such as leaving the image size alone and drawing the image in the paint event at a zoomed scale. You could draw the text on the image in a separate operation, rather than align label controls in the picturebox. Perhaps you want the text to grow with the image, perhaps not.
    Last edited by passel; Dec 18th, 2017 at 12:35 PM.

  8. #8
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,156

    Re: label1 not moving in position when zoom in, inside picturebox vb.net

    As you can see, boops and I both formatted our code for readabi8lity. Please do us the same courtesy.
    vb.net Code:
    1. Public Class testform
    2.     Dim CurPicture As Integer = 1
    3.  
    4.     Private m_PanStartPoint As New Point
    5.  
    6.     Private _originalSize As Size = Nothing
    7.     Private _scale As Single = 1
    8.     Private _scaleDelta As Single = 0.0005
    9.  
    10. Private Sub testform_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    11.  
    12. Label1.Location = PictureBox1.PointToClient(Me.PointToScreen(Label1.Location))
    13.     Label1.Parent = PictureBox1
    14.  
    15.         'Panel Settings
    16.         Panel1.AutoScroll = True
    17.  
    18.         'Picture Box Settings
    19.         PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
    20.  
    21.         'init this from here or a method depending on your needs
    22.         If PictureBox1.Image IsNot Nothing Then
    23.             PictureBox1.Size = Panel1.Size
    24.             _originalSize = Panel1.Size
    25.  
    26.         End If
    27.  
    28.  
    29. Private Sub testform_MouseWheel(sender As Object, e As MouseEventArgs) Handles Me.MouseWheel
    30.  
    31.  
    32.         _scaleDelta = Math.Sqrt(PictureBox1.Width * PictureBox1.Height) * 0.00005
    33.    
    34.  
    35.         If e.Delta < 0 Then
    36.             _scale -= _scaleDelta
    37.         ElseIf e.Delta > 0 Then
    38.             _scale += _scaleDelta
    39.         End If
    40.  
    41.  
    42.  
    43.  
    44.  
    45.         If e.Delta <> 0 Then _
    46.         PictureBox1.Size = New Size(CInt(Math.Round(_originalSize.Width * _scale)), _
    47.                                     CInt(Math.Round(_originalSize.Height * _scale)))
    48.  
    49.  
    50.  
    51.  Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
    52.  
    53.         If e.Button = Windows.Forms.MouseButtons.Left Then
    54.  
    55.             'Here we get the change in coordinates.
    56.             Dim DeltaX As Integer = (m_PanStartPoint.X - e.X)
    57.             Dim DeltaY As Integer = (m_PanStartPoint.Y - e.Y)
    58.  
    59.             'Then we set the new autoscroll position.
    60.             'ALWAYS pass positive integers to the panels autoScrollPosition method
    61.             Panel1.AutoScrollPosition = _
    62.             New Drawing.Point((DeltaX - Panel1.AutoScrollPosition.X), _
    63.                             (DeltaY - Panel1.AutoScrollPosition.Y))
    64.         End If
    Also, why did you quote my most recent post when your post has nothing to do with that? The point of quoting is so that we know exactly what your post is referring to but your reply had nothing to do with what you quoted.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width