relative position in different resolutions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MarwaAlSagheer
    New Member
    • Nov 2008
    • 36

    relative position in different resolutions

    How can i get relative position in different resolutions using c# ??
  • vekipeki
    Recognized Expert New Member
    • Nov 2007
    • 229

    #2
    You can read this link for automatic scaling: http://msdn.microsoft.com/en-us/libr...05(VS.80).aspx.

    If you want to have your controls positioned and resized dynamically as you resize the parent form, then it is a different thing, because that is not related to the screen resolution, but rather the size of the parent form.

    In that case you should use layout panels, and anchor your controls to their container panels. You can achieve relative positioning using FlowLayoutPanel or TableLayoutPane l. Also, by using any control's Anchor property, you can anchor control's sides (top/bottom/left/right) to a parent control, to make it resize together with the parent control.

    Check this link for an example of using the TableLayoutPane l: http://msdn.microsoft.com/en-us/library/991eahec.aspx

    Comment

    • MarwaAlSagheer
      New Member
      • Nov 2008
      • 36

      #3
      Thanks for your advice , but i need to Know how to get relative position in different resolutions using c# ? Do you have any idea ??

      Comment

      • vekipeki
        Recognized Expert New Member
        • Nov 2007
        • 229

        #4
        If you want to get the screen resolution programmaticall y, you can use:

        Code:
        System.Drawing.Rectangle resolution = Screen.GetWorkingArea(someForm);
        where 'someForm' is a form that is located on the display you are interested in (don't forget the possibility of multiple displays).

        But it would help if you would describe in detail what you are trying to accomplish.

        Comment

        • MarwaAlSagheer
          New Member
          • Nov 2008
          • 36

          #5
          This is the problem

          I have Form display in Full Screen Mode; I used Scale Method built in .Net to Scale all controls in the form at the Form Load

          SizeF MaximizeScalFac tor = new SizeF((float) Screen.PrimaryS creen.Bounds.Wi dth / 800, (float) Screen.PrimaryS creen.Bounds.He ight / 600);
          button1.Scale(M aximizeScalFact or);
          All controls used at form (button ,richtextbox,li stbox,label) was Scale correctly expect FlashControl it was Scale but it's position changed . So I try to calculate all relative position depend on the screen resolution.

          Comment

          • MarwaAlSagheer
            New Member
            • Nov 2008
            • 36

            #6
            What about PointToScreen & PointToClient?? ? Is it useful in case of getting relative position in different resolutions?

            Comment

            • vekipeki
              Recognized Expert New Member
              • Nov 2007
              • 229

              #7
              No, they are not related to screen resolution. They simply convert point coordinates between your client control and screen (by translating them).

              For example, if you have a panel inside a form, and then a text box inside that panel, text box location will be relative to the top-left point of the parent panel ("client coordinates"). Panel location will be relative to the top-left origin of the parent form. Using PointToScreen you would be able to convert all those points into a single coordinate system (relative to the screen top-left corner).

              Comment

              • MarwaAlSagheer
                New Member
                • Nov 2008
                • 36

                #8
                OK, but this code not gives me relation position? Its only get screen resolution.
                1. System.Drawing. Rectangle resolution = Screen.GetWorki ngArea(someForm );
                If I have point (479, 9) at screen resolution 1024,786
                IS this Equation true to get this point at another resolution?
                (472*Newresolua tion.x, 9* Newresoluation. y) or NO??

                Comment

                • vekipeki
                  Recognized Expert New Member
                  • Nov 2007
                  • 229

                  #9
                  So, if your x coordinate is 400px in 800x600 resolution, and you want it to be 512px in 1024x768 resolution, then the way to get the new coordinate is obviously:

                  a) 400px / 800px = 1/2
                  b) 1/2 * 1024px = 512px

                  So, first divide with the old resolution, and then multiply with new resolution.

                  Comment

                  • MarwaAlSagheer
                    New Member
                    • Nov 2008
                    • 36

                    #10
                    and applay this to Y coordinate also to have point in new resoluation .

                    i mean the answer of my question
                    How can i get relative position in different resolutions using c# ??


                    By this equation :

                    a) Old point.x / OldResoluation. x = R

                    b) R * newResoluation. x = relativeXpositi on

                    and so on for Y .


                    if Yes , Thanx aloooot :)

                    Comment

                    Working...