Results 1 to 24 of 24

Thread: [RESOLVED] Why is my Label moving ?

  1. #1

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Resolved [RESOLVED] Why is my Label moving ?

    Hi,

    I don't understand what's happening here.

    My Form1 looks like this:
    Name:  Clock1.jpg
Views: 358
Size:  41.9 KB

    The pink bit is Label1.

    The relevant code to put it on the Form is this:
    Code:
      Dim img1, img2, img3 As Bitmap
      Dim Graph As Graphics, lh, lw, lx, ly  As Integer
    
     lh = Label1.Height
     lw = Label1.Width
     lx = Label1.Location.X
     ly = Label1.Location.Y
    
      img3 = New Bitmap(lw, lh)
            Me.Label1.DrawToBitmap(img3, New Rectangle(0, 0, lw, lh))
            Graph = Graphics.FromImage(img3)
            Graph.DrawImage(img3, lx, ly, lw, lh)
    Fine that's where I originally placed it, (It's only pink to show it).
    Now I want to change Label1 height from 200, to 300.
    I do this in the designer.
    Change Label1.size from 200,200 to 200,300.
    Change absolutely nothing else, just the height. In the design page it just grows down the clock face by 100 px.
    Run the project and Form1 now looks like this:
    Name:  Clock2.jpg
Views: 349
Size:  40.2 KB

    It's my belief that...
    Code:
     Graph.DrawImage(img3, lx, ly, lw, lh)
    ...is what places the image on the form, but play as I will with the attributes lx and ly, just typing in (any) integer in place of the variables, nothing happens... the image stays as shown.

    What's happening ?


    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Why is my Label moving ?

    First of all, if were going to use this:
    vb.net Code:
    1. lx = Label1.Location.X
    2. ly = Label1.Location.Y
    then you ought to use this:
    vb.net Code:
    1. lh = Label1.Size.Height
    2. lw = Label1.Size.Width
    As you are, quite sensibly, using this:
    vb.net Code:
    1. lh = Label1.Height
    2. lw = Label1.Width
    then you you should be using this:
    vb.net Code:
    1. lx = Label1.Left
    2. ly = Label1.Top

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Why is my Label moving ?

    I think that you need to describe what it is that you're actually trying to achieve because that code is bizarre and I doubt that it does what you want it to. Let's review what those last four lines actually do:
    vb.net Code:
    1. img3 = New Bitmap(lw, lh)
    That creates a Bitmap object the same size as the Label.
    vb.net Code:
    1. Me.Label1.DrawToBitmap(img3, New Rectangle(0, 0, lw, lh))
    That draws the Label onto the previously created Bitmap.
    vb.net Code:
    1. Graph = Graphics.FromImage(img3)
    That creates a Graphics object for drawing on the previously created Bitmap.
    vb.net Code:
    1. Graph.DrawImage(img3, lx, ly, lw, lh)
    That draws the previously created Bitmap onto itself, offset by the location of the Label relative to its parent container.

    Why would you want to draw a Bitmap onto itself? Why would you want to draw the Label to a Bitmap? The Label is, presumably, already on the form so the user can already see it. What exactly is the Bitmap that you're drawing the Label onto for? This is why I would like to know what you're trying to achieve. I think that that whole section of code is completely misguided, but that's based on a guess at what you're trying to do. I would have thought that you would want to simply add the Label to the form in the designer and set its Text property in code based on the current date. That seems to be the sum total of what you should want to do with the Label.

    Maybe you are trying to solve the issue that drawing the clock hands on the form didn't actually draw over the Label and this is your misguided solution. In that case, forget all of what you have there. The two solutions to that problem would be as follows:

    1. Do away with the Label altogether and use the same Graphics object that is drawing the hands to draw the text of the date. You would call DrawString first, to draw the date text, and then (presumably) DrawImage to draw the hands of the clock over it.

    2. Handle the Paint event of the Label as well and do the same drawing on it as you are doing already on the form or some other control. You can follow the CodeBank link in my signature below and check out my thread on Drawing A Common Picture On Multiple Controls or the like.

    It also occurs to me that you might have that clock face in a PictureBox and be drawing the hands on it and you are playing with the Label this way because it's not a child of the PictureBox. The solution to that is to make it a child of the PictureBox. You can't do that in the designer because the PictureBox isn't intended to support children but it does, so you can do it in code. The way to do that is to make sure that the PictureBox is behind the Label in the z-order (which you can do in the Document Outline window) and then place both controls in the exact location you want them to be. You can then handle the Load event of the form and add this code:
    vb.net Code:
    1. Dim position = PictureBox1.PointToClient(Label1.PointToScreen(Point.Empty))
    2.  
    3. Label1.Parent = PictureBox1
    4. Label1.Location = position
    That will move the Label into the PictureBox but at the same relative position as it was in the designer. You can set the BackColor of the Label to Transparent to have the PictureBox show through its background and and you can use option 2 above to draw on both the PictureBox and the Label.

  4. #4

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Why is my Label moving ?

    Quote Originally Posted by jmcilhinney View Post
    Why would you want to draw a Bitmap onto itself? Why would you want to draw the Label to a Bitmap? The Label is, presumably, already on the form so the user can already see it. What exactly is the Bitmap that you're drawing the Label onto for? This is why I would like to know what you're trying to achieve.

    Maybe you are trying to solve the issue that drawing the clock hands on the form didn't actually draw over the Label and this is your misguided solution.
    Yes, you're guess is spot on. Before I start trying to redesign the whole of this subroutine, before your post I added a temporary label to display the actual location of Label1, you might notice that the x and y is nowhere near the expected 300,110.
    Yes, the clock face is in a picturebox, I couldn't discover how to make my clock display the hands when I put the image in the background of the form. I expect that your remarks concerning the picturebox will explain the discrepancy in location, although I still don't understand why just changing the height of the label makes so much difference.

    I think I'll keep the temporary label to assist getting the hands closer to the centre of the clock face later on.
    Code:
            lh = Label1.Height : lw = Label1.Width : lx = 300 : ly = 110
            img3 = New Bitmap(lw, lh)
            Me.Label1.DrawToBitmap(img3, New Rectangle(0, 0, lw, lh))
            Graph = Graphics.FromImage(img3)
            Graph.DrawImage(img3, lw, lh, 300, 110)
    
            Label2.Text = "W " & Label1.Width.ToString
            Label2.Text &= ". H " & Label1.Height.ToString
            Label2.Text &= ". X " & Label1.Location.X.ToString
            Label2.Text &= ". Y " & Label1.Location.Y.ToString
    Since your post I've added another label to illustrate the problem:

    Name:  Clock3.jpg
Views: 243
Size:  43.9 KB

    So... yes, total redesign of this subroutine along the lines that you suggest.

    Thanks for your help John.


    Poppa
    Last edited by Poppa Mintin; Sep 15th, 2020 at 06:47 AM.
    Along with the sunshine there has to be a little rain sometime.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Why is my Label moving ?

    Quote Originally Posted by Poppa Mintin View Post
    I still don't understand why just changing the height of the label makes so much difference.a
    Presumably because of this:
    Code:
    Graph.DrawImage(img3, lw, lh, 300, 110)

  6. #6
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Why is my Label moving ?

    From: https://docs.microsoft.com/en-us/dot...System_Single_

    public void DrawImage (System.Drawing.Image image, float x, float y, float width, float height);

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Why is my Label moving ?

    Analog clocks are fun to program, once you understand the zOrder of the components clearly...

    http://www.scproject.biz/itc.php

  8. #8

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Why is my Label moving ?

    John,

    Can your Code Bank article 'Transforming Graphics Coordinates in Windows Forms' be converted to rotate pictureboxes in stead of drawing with pens ?


    Poppa
    Along with the sunshine there has to be a little rain sometime.

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Why is my Label moving ?

    Quote Originally Posted by Poppa Mintin View Post
    rotate pictureboxes in stead of drawing with pens ?Poppa
    Pictureboxes can't be rotated. The image within the picurebox can be rotated though...

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Why is my Label moving ?

    I'm assuming that your clock face and hands are images. Attach them to a post and I'll provide a demo (if .paul. doesn't beat me to it ).

  11. #11

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Why is my Label moving ?

    Thanks John,

    Name:  Hrs.png
Views: 206
Size:  16.7 KB Attachment 178766 Attachment 178767

    Three images, I've been struggling with putting these images on the PictureBox containing the clock face, I thought it was the PictureBox which was drawn to screen, so all three PictureBoxes are the same dimension. From what you say I can go back to my original three.

    I've been trying to get the hands to rotate at the centre of a 681 x 681 PictureBox. It's been a 680 sq until I read your code bank saying make it an odd number to get a centre.
    Two of the hands, you will see have an empty point of rotation, I have a 'dot' smack in the centre of the clock face around which I've been trying to rotate the hands.

    Original images in case they're easier to use.

    Name:  Hour.png
Views: 215
Size:  15.1 KB Name:  Minute.png
Views: 206
Size:  8.5 KB Name:  Second.png
Views: 207
Size:  13.3 KB



    Poppa
    Last edited by Poppa Mintin; Sep 17th, 2020 at 06:29 AM.
    Along with the sunshine there has to be a little rain sometime.

  12. #12

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Why is my Label moving ?

    Oh !

    I missed the clock face !


    Attachment 178772


    This is in PictureBox1 which has 'Maroon' as it's BackColor, and the file as it's Image, selected to 'Stretch'.


    Poppa

    PS

    I hope these images are readable, they're none too clever when I try to see 'em, the three originals are ok but the rest are very suspect !



    Pop.
    Last edited by Poppa Mintin; Sep 17th, 2020 at 06:34 AM.
    Along with the sunshine there has to be a little rain sometime.

  13. #13
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Why is my Label moving ?

    Quote Originally Posted by jmcilhinney View Post
    I'm assuming that your clock face and hands are images. Attach them to a post and I'll provide a demo (if .paul. doesn't beat me to it ).
    I already did several examples years ago.
    https://www.vbforums.com/showthread....=1#post4684863
    If you click on the minute hand or hour hand radio buttons, you get a second form where you can change the position, and resize the images, and rotate the images from that form, by dragging on the readout value displays.

    Also a VB6 version in this thread, but that wouldn't be applicable here.

    p.s. I see I already linked you to the VB.Net example in October of last year. https://www.vbforums.com/showthread....=1#post5420847
    I guess you're still working on the issue of the label over the hands from that thread. Sorta sounded like it was resolved then...

    Above in this thread (post #4), you reversed the position and size parameters, i.e. you should have passed x, y, h, w, but you passed h, w, x, y (so you were using size as your position and position as your size).
    Both jmc and OptionBase1 were pointing that out in posts #5 and 6.
    Last edited by passel; Sep 18th, 2020 at 10:29 PM.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  14. #14
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Why is my Label moving ?

    Quote Originally Posted by Poppa Mintin View Post
    ...
    Three images, I've been struggling with putting these images on the PictureBox containing the clock face, I thought it was the PictureBox which was drawn to screen, so all three PictureBoxes are the same dimension. From what you say I can go back to my original three.

    I've been trying to get the hands to rotate at the centre of a 681 x 681 PictureBox. It's been a 680 sq until I read your code bank saying make it an odd number to get a centre.
    Two of the hands, you will see have an empty point of rotation, I have a 'dot' smack in the centre of the clock face around which I've been trying to rotate the hands.
    ...
    Poppa
    To put the dot in the center, and rotate around it, just determine what the white dot's x,y value is in the image you have. Let's say it is 100,450 for the hour hand.
    To draw the hour hand with the white dot at the center of rotation, there are several ways you can do it, but the way that is in the code I posted is you first do a TranslateTransform to position the (0,0) point of the coordinate system to the center of rotation.
    You have a 681x681 box, so the center would be 340,340, so you translate 0,0 to there.
    Now, if you want the center white dot to be drawn there, then the upper left corner of the bitmap would be at -100,-450 relative to that point, so that is where you draw the image of the hour hand.
    Regardless of how you rotate, you always draw the hour hand image using the same coordinates, so that is simple.
    You just have to do the RotateTransform before you draw the hand.

    Code:
    Dim gc As GraphicContainer = e.Grahics.BeginContainer  'save our current matrix
    e.Graphics.TranslateTransform(340, 340)  'move (0,0) to center of the clock
    e.Graphics.RotateTransform(angle)   'the current angle of the hour hand
    e.Graphics.DrawImage(hourHandImage, -100, -450)  'draw the hand so pixel (100, 450) is at 0,0
    e.Graphics.EndContainer(gc)
    The (-100, -450) could be off by 1, since the corner of the image is at 0,0. I didn't check, but that is the basic way I position the hands and rotate them.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  15. #15

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Why is my Label moving ?

    I'd like to check that my understanding of this method is correct.
    Please confirm or correct my understanding.

    Name:  Rotate Hand.jpg
Views: 194
Size:  35.8 KB

    Using the code below, the hour hand is set to rotate as though it were the seconds hand for testing purposes, I get an approximately half size hour hand rotating around the centre of the clock but...
    The pivot point of the hand is at about where I'd expect the tip of the hand to be, on the plus side, the hand is pointing in the right direction. But clearly I have still got something wrong.
    Code:
        ReadOnly handH As Image = New Bitmap(Me.GetType(), "Hours.png")
        ReadOnly handM As Image = New Bitmap(Me.GetType(), "Minutes.png")
        ReadOnly handS As Image = New Bitmap(Me.GetType(), "Seconds.png")
        Public Graph As Graphics
        Public img1, img2, img3 As Bitmap
        Public hrs, min,  sec As Integer
    And in subroutine Timer1.Tick every second.
    Code:
            sec = Now.Second
            min = Now.Minute
            hrs = Now.Hour
            '   Hour hand.      HandH
            img1 = New Bitmap(PictureBox1.Width, PictureBox1.Height)
            Graph = Graphics.FromImage(img1)
            img2 = DirectCast(img1.Clone, Bitmap)
            Graph = Graphics.FromImage(img2)
            Graph.SmoothingMode = SmoothingMode.HighQuality
            Graph.TranslateTransform(341, 341)   'Locate at centre of PictureBox1.
            Graph.RotateTransform(sec * 6)
            Graph.DrawImage(handH, -150, -79)    'Rotate image at this point.
            PictureBox1.Image = img2
    Poppa
    Along with the sunshine there has to be a little rain sometime.

  16. #16

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Why is my Label moving ?

    Quote Originally Posted by passel View Post
    Code:
    Dim gc As GraphicContainer = e.Grahics.BeginContainer  'save our current matrix
    Thanks Passel,

    When I try to change my drawing code to use your suggestion, I'm struggling to find how to define 'GraphicContainer' because intellisense doesn't like it.

    Yours is a different approach to the one I've been using which is as shown above.

    I tried changing my coordinates to those which you suggest, (341, 341 for the point about which to rotate, and -150, -79 for the image rotation point) but I get the result reported above.


    Poppa
    Along with the sunshine there has to be a little rain sometime.

  17. #17
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Why is my Label moving ?

    Simples. Translate transform to the centre of your image.
    RotateTransform for hours. Draw your hour hand.
    ResetTransform.
    Translate transform to the centre of your image.
    RotateTransform for minutes. Draw your minute hand.
    ResetTransform.
    Translate transform to the centre of your image.
    RotateTransform for seconds. Draw your second hand.
    ResetTransform.

  18. #18

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Why is my Label moving ?

    Hi,
    Here's something else I don't understand.
    I've drawn a picture for each of the three clock hands.

    They're named Hours.png (118, 607px), Minutes.png (55, 689px) and Seconds.png (98, 1200px).
    They're copied into my resources. they're copied into global image variables as handH, handM and handS respectively.
    Code:
        ReadOnly handH As Image = New Bitmap(Me.GetType(), "Hours.png")
        ReadOnly handM As Image = New Bitmap(Me.GetType(), "Minutes.png")
        ReadOnly handS As Image = New Bitmap(Me.GetType(), "Seconds.png")
    Because my hour hand doesn't seem to be obeying the rules (Or because I've missunderstood the rules) I've added a Label2 to my form:
    Code:
            Dim hhs = handH.Size
            Dim hms = handM.Size
            Dim hss = handS.Size
            Label2.Text = hss.ToString & hms.ToString & hhs.ToString
    Running the project, Label2 tells me that:
    handH.Size = 239 Wide, 645 High.
    handM.Size = 111 Wide, 741 High.
    handS.Size = 98 Wide, 1200 High.
    I've tried halving the hour hand width (because the pivot point for all hands is in the centre of the width) and making a guess based on the percentage difference for the hour hand height centre-line and run the code again but the results are even worse. I don't see the hour hand at all.

    I don't understand why the sizes are so different. Using the Label2 again, the PictureBox1 dimensions are correct, but they would be wouldn't they.


    Poppa

    PS.

    OH Bugger !

    I just discovered the DPI has changed on the two wrong pictures.

    Pop.
    Last edited by Poppa Mintin; Sep 18th, 2020 at 06:03 PM.
    Along with the sunshine there has to be a little rain sometime.

  19. #19
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Why is my Label moving ?

    Quote Originally Posted by Poppa Mintin View Post
    I'd like to check that my understanding of this method is correct.
    Please confirm or correct my understanding.

    Name:  Rotate Hand.jpg
Views: 194
Size:  35.8 KB

    ...
    Your understanding is incorrect.
    The rotation point of the hand bitmap that you want is at (150, 721).
    That means the upper left corner of the bitmap is (-150, -721) relative to that point {not (-150, -79)}.

    In your bitmap notation, you're saying you're moving the (0,0) of hand bitmap to bring the center of rotation to the center of the clock, but that is not quite the way I look at it.
    You want to draw the small bitmap so that the pixel at (150,721) of the small bitmap ends up being at 0,0 of your client coordinate system.
    Whatever point (X,Y) in your small bitmap you want to be drawn at (0,0) of your coordinates system, you have to draw it at (-X, -Y).

    When you start off, the (0,0) pixel coordinate of the picturebox is the upper left corner of the picturebox.
    If you considered this a graph, then the whole drawing area is the lower right quadrant of the graph (the +X, +Y) coordinates.
    The other three quadrants upperleft (-X, +Y), lowerleft (-X,-Y), upperright (+X, -Y) are outside the client area.
    When you do a RotateTransform, it is rotating the coordinate system around the 0,0 point, so by default, you are rotating the coordinate system around the upper left point of your client area if you haven't translated the coordinate system to move the (0,0) point to somewhere else.

    In our case, the TransformTranslate is moving the (0,0) coordinate of the picturebox, so after the translate, the 0,0 pixel is in the center of the picturebox, and your X coordinates run from -340 to +340 (if you translated to 340,340. Since you translate to 341,341, I think your coordinates go from -341 to 339).

    Likewise, the Y axis runs from -340 (or -341 in your case) at the top, to 340 (339) at the bottom.
    Since 0,0 is now in the center, if I drew a rectangle (x=0, y=0, w=11, h=11), the upper left corner of the rectangle would be in the center, so the rectangle would lie fully in the lower right quandrant of the client area, with its top edge aligned with the X axis, and the left edge aligned with the Y axis, of the two axis that cross in the center of the client area.

    If I wanted the square centered in the client area, I would draw it offset negatively by 1/2 (-5,-5, 11, 11).
    That would draw the rectangle (square) from -5 to 5 in X and -5 to 5 in Y, so it would have 0,0 at its center.

    You do the same with each of your hands. You place the point you want to be the center of rotation at the center, and you do that by offsetting the upper top,left corner negatively by that same amount.
    Last edited by passel; Sep 18th, 2020 at 10:25 PM.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  20. #20

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Why is my Label moving ?

    Quote Originally Posted by passel View Post
    In our case, the TransformTranslate is moving the (0,0) coordinate of the picturebox, so after the translate, the 0,0 pixel is in the center of the picturebox, and your X coordinates run from -340 to +340 (if you translated to 340,340. Since you translate to 341,341, I think your coordinates go from -341 to 339).
    Hi Passel, I'd like to explain my use of 341 instead in 340 just to get that out of the way.

    PictureBox1's size is 681 x 681, so... at 341 there are 340 pixels to the left of 341, 340 pixels to the right of 341, 340 pixels above 341 and 340 pixels below 341.
    So I reckon 341 to be the centre.


    Poppa
    Along with the sunshine there has to be a little rain sometime.

  21. #21

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Why is my Label moving ?

    Ok, another important discovery, new to me anyway, and not anything I've seen elsewhere.

    The DPI of the image makes a huge difference. By default I always work with 600 DPI, when I checked to see the DPI of the original images I found they weren't my usual, maybe because I'd started with a photo' of our grandfather clock to get ornamental hands.

    Anyway, as I mentioned in an earlier post the hour hand I was seeing was only about half the size I expected and now that I've looked at it I find that it's DPI (for an unknown reason) was 236.222 !
    I changed the DPI to my usual 600 and now the hand on the clock was tiny !
    So, I changed it to 100 and ran the app. again, now the hand was (just) too big, I've now settled on 120 with no need to ScaleTransform.

    Poppa
    Along with the sunshine there has to be a little rain sometime.

  22. #22
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Why is my Label moving ?

    Quote Originally Posted by Poppa Mintin View Post
    Ok, another important discovery, new to me anyway, and not anything I've seen elsewhere.

    The DPI of the image makes a huge difference. By default I always work with 600 DPI, when I checked to see the DPI of the original images I found they weren't my usual, maybe because I'd started with a photo' of our grandfather clock to get ornamental hands.

    Anyway, as I mentioned in an earlier post the hour hand I was seeing was only about half the size I expected and now that I've looked at it I find that it's DPI (for an unknown reason) was 236.222 !
    I changed the DPI to my usual 600 and now the hand on the clock was tiny !
    So, I changed it to 100 and ran the app. again, now the hand was (just) too big, I've now settled on 120 with no need to ScaleTransform.

    Poppa
    It'd be better to convert all of your images to the same DPI, then resize to the actual sizes your need. You can do that in an image editor before adding them to your app.

  23. #23
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Why is my Label moving ?

    Quote Originally Posted by Poppa Mintin View Post
    Hi Passel, I'd like to explain my use of 341 instead in 340 just to get that out of the way.

    PictureBox1's size is 681 x 681, so... at 341 there are 340 pixels to the left of 341, 340 pixels to the right of 341, 340 pixels above 341 and 340 pixels below 341.
    So I reckon 341 to be the centre.


    Poppa
    You're forgetting, I assume, that the first pixel coordinate is 0 (zero) (0,0). The second pixel in x and y is (1,1), etc.
    At 341, there are 341 to the left (0 = first pixel, 1 = second pixel, 340 = three hundred forty first pixel.

    A 681 pixel wide client area's coordinates run 0 to 680, so you have 340 on the left (0 to 339), 340 is the center pixel, and 340 on the right (341 to 680).
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  24. #24

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Why is my Label moving ?

    Ah!
    Yes of course, I'm still looking at the grid of my picture editor.

    Well... That's cleared that up.

    Anyway, what I did in the end was to add a couple of temporary TextBoxes to the clock from which I could adjust the position of each hand in turn whilst the app. was running to get 'em exactly right.

    Whilst I was doing that... I found out why the label (that caused the trouble in the first place) was moving (for the same reason that I've had all these problems) and fixed that too.

    QED

    Thanks guys, a great help as usual.

    Poppa
    Along with the sunshine there has to be a little rain sometime.

Posting Permissions

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



Click Here to Expand Forum to Full Width