질문하기질문하기
 

답변됨Image of control

  • 2009년 11월 3일 화요일 오후 7:12higgernaut 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Is there any way to save an image of a control?

    I have a graph that I am using from a package, but I made a custom control that would hover with your mouse and tell you the Y values according to the mouse's position relative to X on this pre-made graph control. If you click on the control, it will "paste" my control onto the graph. The graph can be exported as a .bmp, but since my control is not part of the graph, it does not get exported.


    Thanks.
    • 편집됨higgernaut 2009년 11월 4일 수요일 오후 9:48
    •  

답변

  • 2009년 11월 3일 화요일 오후 7:31Tamer OzMVP사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨코드 있음

    Hi,

    You can use the following method.

            public Image GetImageOfControl(Control c)
            {
                Rectangle rc = new Rectangle(this.PointToScreen(c.Location), c.Size);
                Image i = new Bitmap(rc.Width, rc.Height);
                Graphics g = Graphics.FromImage(i);
                g.CopyFromScreen(rc.Left, rc.Top, 0, 0, rc.Size);
                g.Dispose();
                return i;
            }
    
    • 답변으로 표시됨higgernaut 2009년 11월 3일 화요일 오후 7:33
    •  

모든 응답

  • 2009년 11월 3일 화요일 오후 7:31Tamer OzMVP사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨코드 있음

    Hi,

    You can use the following method.

            public Image GetImageOfControl(Control c)
            {
                Rectangle rc = new Rectangle(this.PointToScreen(c.Location), c.Size);
                Image i = new Bitmap(rc.Width, rc.Height);
                Graphics g = Graphics.FromImage(i);
                g.CopyFromScreen(rc.Left, rc.Top, 0, 0, rc.Size);
                g.Dispose();
                return i;
            }
    
    • 답변으로 표시됨higgernaut 2009년 11월 3일 화요일 오후 7:33
    •  
  • 2009년 11월 4일 수요일 오후 9:47higgernaut 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    That did the trick! Just needed the tiniest bit of retooling for C++.


    Thanks!