Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public partial class Form1 : Form
    {

        public int xcoordinate = 0;
        public int ycoordinate = 0;
        public int ESD_no = 2;
        public int IntertripESD = 0;
        public bool MenuClickdone = false;
        //private Bitmap MyImage;

        public event System.Windows.Forms.MouseEventHandler MouseClick;
        public void ShowMyimage(string WorkingDirectory, int xsize,int ysize)
                    {
           // WorkingDirectory = @"C:\PhotoXv";
            WorkingDirectory = @"C:\Users\abuhmammACER\source\repos\PhotoXv\xv_close.png";
            Bitmap xv_close = new Bitmap(WorkingDirectory);
            // xv_close = Image.FromFile(@"C:\PhotoXv\xv_close.png");
           // Image xv_open = Image.FromFile(WorkingDirectory + @"\xv_open.png");
           //// if (MyImage !=null )
           // {
            //    MyImage.Dispose();
           // }
            int sourceWidth = xv_close.Width;
            int sourceHeight = xv_close.Height;
            

            //Bitmap bmPhoto = new Bitmap(sourceWidth,sourceHeight);
            Graphics GraphicPhoto = Graphics.FromImage(xv_close);

            GraphicPhoto.DrawImage(xv_close, xsize, ysize,sourceWidth,sourceHeight);
            //GraphicPhoto.Save("output.png", ImageFormat.Png);
           // GraphicPhoto.Save( ImageFormat.Png);
        }


private void button1_Click(object sender, EventArgs e)
        {
            //this.Paint += new PaintEventHandler(Image_fun);
            
            ShowMyimage(@"C:\Users\abuhmammACER\source\repos\PhotoXv\xv_close.png", 40, 50);
           // f1_paint(object sender, PaintEventArgs e);
        }




during button click i want to call any function like ShowMYimage() but when i call nthing happen also if I edit value there no action but if I call other form
form1 f=new form();
f.show();
the form apper
pleas any soultion for that
summry i want draw image through any event like menu click but I am not able to do that

What I have tried:

i want draw image  through any event like menu click but I am not able to do that
Posted
Updated 21-Jul-20 11:13am

1 solution

First off, that is C# code, not C++ - they are very different languages which share some common syntax. It is important that you tag questions correctly, or you will reduce the number of potential answerers significantly.

You can do it directly in a button click handler, but ... it's a bad idea. Why I say that is that such drawings aren't persistent: as soon as anything else requires your form to be redrawn your new changes will be discarded - and that includes you changing the size of your form, minimising it, maximising it, or even another app moving over it's surface.
To do that, you get a graphics context from the system, draw onto that, and then dispose of the context.
How to: Create Graphics Objects for Drawing - Windows Forms | Microsoft Docs[^] shows you how.

What you should be doing is drawing in the Paint event handler, and forcing a repaint by Invalidating the control / form on which you want to draw: Control.Invalidate Method (System.Windows.Forms) | Microsoft Docs[^]
 
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