Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am use this function to draw multi valve image in the screen but when run the application in different resolution the image position change
the application work only with 1920x 1080 resolution when you change the resolution the image will be in different position in the screen
how I can fix the image position in the form without change the resolution
C#
public void xvcloseevent(object sender, PaintEventArgs e)
{
    try {
        Screen scr = Screen.PrimaryScreen;
        int temphigh = scr.Bounds.Height;
        int tempwidth = scr.Bounds.Width;

        Assembly asm = Assembly.GetExecutingAssembly();
        Stream stm = asm.GetManifestResourceStream("FirstprojectDCS.FilesProjectsDcs.xv_close.png");
        
         Bitmap xv_close = new Bitmap(stm);
        
            Stream stm2 = asm.GetManifestResourceStream("FirstprojectDCS.FilesProjectsDcs.FV_CLOSE.png");
        Bitmap Fv_close = new Bitmap(stm2);
        
        
        Stream stm3 = asm.GetManifestResourceStream("FirstprojectDCS.FilesProjectsDcs.FV_CLOSE_V_L.png");
        Bitmap Fv_close_v_l = new Bitmap(stm3);
       
        Stream stm4 = asm.GetManifestResourceStream("FirstprojectDCS.FilesProjectsDcs.FV_CLOSE _V_L2.png");
        Bitmap Fv_close_V_L2 = new Bitmap(stm4);

        Pen Mypen = new Pen(Color.Red,1);
        xv_close.SetResolution(96.0F, 96.0F);
        Fv_close.SetResolution(96.0F, 96.0F);
        Fv_close_v_l.SetResolution(96.0F, 96.0F);
        Fv_close_V_L2.SetResolution(96.0F, 96.0F);
        //  xv_close.SetResolution(96.0F, 96.0F);
// change the resultion HD resolution
     //   ResolutionChange();

        // Get Graphics Object
        Graphics g = e.Graphics;
    int sourceWidth = xv_close.Width;
    int sourceHeight = xv_close.Height;
    // Method under System.Drawing.Graphics


    if (ESD_no == 2 || ESD_no == 2013)
    {
        //label2.Visible = false;
        if (ESD_no == 2)
        {
            g.DrawString("ESD-002 action Deoxo Rx Shduwn", new Font("Verdana", 20),
        new SolidBrush(Color.Tomato), 40, 40);
        }
        else if (ESD_no == 2013)
        {
            g.DrawString("ESD-201 cause 3 	1620-XPB-023A- Deoxo Reactor Depressurizing Local Pushbutton", new Font("Verdana", 17),
            new SolidBrush(Color.Tomato), 40, 40);

            g.DrawString("ESD-201 cause 3 action Deoxo Rx Shduwn", new Font("Verdana", 17),
            new SolidBrush(Color.Tomato), 40, 70);
        }
            //xv15
        //   xcoordinate = 122- Math.Abs( 1536-(tempwidth));
          //ycoordinate =(145 -Math.Abs( (846-(temphigh))))-10;
xcoordinate = 122;// - Math.Abs(1536 - tempwidth);
        ycoordinate = 145-26;// - Math.Abs(10 - (846 - temphigh));

            g.DrawImage(xv_close, xcoordinate, ycoordinate, sourceWidth, sourceHeight);
        g.DrawEllipse(Mypen, xcoordinate - 60, ycoordinate - 60, 160, 120);
        // g.DrawImage(Image.FromFile(@"C:\PhotoXv\xv_close.png"), new Point(xcoordinate, ycoordinate));
        //xv 001
        //xcoordinate = 238;
        //ycoordinate = 453 - 26;
        //g.DrawImage(Image.FromFile(@"C:\PhotoXv\xv_close.png"), new Point(xcoordinate, ycoordinate));
        //g.DrawImage(xv_close, xcoordinate, ycoordinate, sourceWidth, sourceHeight);
        xcoordinate = 834;
        ycoordinate = 307 - 26;
        g.DrawImage(xv_close, xcoordinate, ycoordinate, sourceWidth, sourceHeight);
        g.DrawEllipse(Mypen, xcoordinate - 60, ycoordinate - 60, 160, 120);
        // g.DrawImage(xv_close, xcoordinate, ycoordinate, sourceWidth, sourceHeight);

        xcoordinate = 946;
        ycoordinate = 307 - 26;
        g.DrawImage(xv_close, xcoordinate, ycoordinate, sourceWidth, sourceHeight);
        g.DrawEllipse(Mypen, xcoordinate - 60, ycoordinate - 60, 160, 120);
        //xv 10
        xcoordinate = 507;
        ycoordinate = 639 - 26;
        g.DrawImage(xv_close, xcoordinate, ycoordinate, sourceWidth, sourceHeight);
        g.DrawEllipse(Mypen, xcoordinate - 60, ycoordinate - 60, 160, 120);
        //xv 12
        xcoordinate = 730;
        ycoordinate = 460 - 26;
        g.DrawImage(xv_close, xcoordinate, ycoordinate, sourceWidth, sourceHeight);
        g.DrawEllipse(Mypen, xcoordinate - 60, ycoordinate - 60, 160, 120);
        // xv016
        xcoordinate = 1033;
        ycoordinate = 146 - 26;
        g.DrawImage(xv_close, xcoordinate, ycoordinate, sourceWidth, sourceHeight);
        g.DrawEllipse(Mypen, xcoordinate - 60, ycoordinate - 60, 160, 120);
        //xv017
        xcoordinate = 1142;
        ycoordinate = 143 - 26;
        g.DrawImage(xv_close, xcoordinate, ycoordinate, sourceWidth, sourceHeight);
        g.DrawEllipse(Mypen, xcoordinate - 60, ycoordinate - 60, 160, 120);
        if (IntertripESD == 3)
        {// esd-00 2 intertrip esd-003 
            g.DrawString("ESD-003 intertrip with ESD-002 N2 PURGING ", new Font("Verdana",10),
   new SolidBrush(Color.DarkGreen), 1281-80, 119-90);
            xcoordinate = 1290;
            ycoordinate = 114 - 26;


What I have tried:

I am use this function to draw multi valve image in the screen but when run the application in different resolution the image position change

the application work only with 1920x 1080 resolution when you change the resolution the image will be in different position in the screen

how I can fix the image position in the form without change the resolution
Posted
Updated 7-Sep-20 21:17pm
v2
Comments
[no name] 7-Sep-20 21:17pm    
You don't change the "resolution"; you change the "scaling" (or zoom) by altering one of the side dimensions.

1 solution

Assuming the image you create has a 16:9 aspect ratio (1920, 1080) ...

Create the image: insert it into a PictureBox whose bounds have the same aspect ratio as the image, but whose size is adjusted to fit (be visible in) the current screen resolution, and use the 'Zoom PictureBoxSizeMode enumeration setting on the PictureBox.SizeMode property.

see: [^], [^], [^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900