2011-11-25 2 views
6

나는 윈도우 폼을 사용하여 C# 프로젝트를 작업 중이다. 나와 내가 속한 그룹은 사용자가 이미지 위에 마우스를 올려 놓으면 우리 카드의 경우 카드의 큰 이미지가 마우스 화살표 옆에 나타납니다. 도구 설명이 효과적입니다. 난 당신이 모든 곳을 찾고 내가 시도이 작업을 수행하는 도구 팁을 사용할 수 있다고 생각하지 않습니다 , 어떤 조언이나 예Windows 이미지의 마우스 오버시 이미지 표시?

답변

7

그것은 이미지와 함께 OwnerDrawn 도구 설명을 만드는 방법을 보여줍니다.

+0

+1 @MarkHall 위대한 팁! –

2

할 수있는 간단한 방법이 숨기는 것입니다 대단히 감사합니다 좋은 것/그림 상자를 표시 지정된 위치에. 또 다른 방법은 GDI API를 사용하여 이미지를 그립니다 (페인트) &을로드하는 것입니다. 당신이 Code Project Article

보고 할 수 있습니다

4

답장을 보내 주셔서 감사합니다. 내가하고 싶은 것은 특정 영역을 마우스로 올렸을 때 해당 영역에 대한 다른 이미지가 툴팁과 동일한 방식으로 팝업된다는 것입니다. 그래서 약간의 연구가 끝나고 나 자신의 툴팁 클래스를 만드는 방법을 알아 냈습니다.

여기 예가 나와 있습니다.

public partial class Form1 : Form 
{ 

    public Form1() 
    { 
     InitializeComponent(); 

     CustomToolTip tip = new CustomToolTip(); 
     tip.SetToolTip(button1, "text"); 
     tip.SetToolTip(button2, "writing"); 
     button1.Tag = Properties.Resources.pelican; // pull image from the resources file 
     button2.Tag = Properties.Resources.pelican2;  
    } 
} 

class CustomToolTip : ToolTip 
{ 
    public CustomToolTip() 
    { 
     this.OwnerDraw = true; 
     this.Popup += new PopupEventHandler(this.OnPopup); 
     this.Draw +=new DrawToolTipEventHandler(this.OnDraw); 
    } 

    private void OnPopup(object sender, PopupEventArgs e) // use this event to set the size of the tool tip 
    { 
     e.ToolTipSize = new Size(600, 1000); 
    } 

    private void OnDraw(object sender, DrawToolTipEventArgs e) // use this to customzie the tool tip 
    { 
     Graphics g = e.Graphics; 

     // to set the tag for each button or object 
     Control parent = e.AssociatedControl; 
     Image pelican = parent.Tag as Image; 

     //create your own custom brush to fill the background with the image 
     TextureBrush b = new TextureBrush(new Bitmap(pelican));// get the image from Tag 

     g.FillRectangle(b, e.Bounds); 
     b.Dispose(); 
    } 
} 

}

관련 문제