2012-11-23 4 views
1

어떻게 화면의 아무 곳 (AutoIt을에서 만든)이 같은 툴팁을 만들 수 있습니까? 나는 한 시간을 찾고 아무 것도 발견하지 못했습니다. 트레이시 콘의 툴팁과 같은 일반적인 툴팁으로 어디서나 배치 할 수 있습니다.화면 어디에서나 툴팁을 만드는 방법은 무엇입니까?

감사 등

AutoIt Tooltip()

+0

MessageBox.Show는 내 스크립트를 차단하고 있으며이 도구 팁은 디버깅 및/또는 로깅에 적합합니다. – VixinG

+0

C#으로 태그를 지정했지만 Windows 앱입니다./ASP .NET/WPF 또는 무엇? – PeteGO

+1

아마 ASP.NET –

답변

1

왜 Windows Forms의 여부 상관이야, ASP .NET? 아마 당신의 선택에 영향을 미치기 때문입니다.

는 윈도우하면,중인 Windows.Forms.Form에서 상속 자신의 클래스를 만드는 몇 가지 속성을 설정하고 해당 사용할 수 Forms 응용 프로그램의 경우.

public class MyTooltip : Form 
{ 
    public int Duration { get; set; } 

    public MyTooltip(int x, int y, int width, int height, string message, int duration) 
    { 
     this.FormBorderStyle = FormBorderStyle.None; 
     this.ShowInTaskbar = false; 
     this.Width = width; 
     this.Height = height; 
     this.Duration = duration; 
     this.Location = new Point(x, y); 
     this.StartPosition = FormStartPosition.Manual; 
     this.BackColor = Color.LightYellow; 

     Label label = new Label(); 
     label.Text = message; 
     label.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; 
     label.Dock = DockStyle.Fill; 

     this.Padding = new Padding(5); 
     this.Controls.Add(label); 
    } 

    protected override void OnShown(System.EventArgs e) 
    { 
     base.OnShown(e); 

     TaskScheduler ui = TaskScheduler.FromCurrentSynchronizationContext(); 

     Task.Factory.StartNew(() => CloseAfter(this.Duration, ui)); 
    } 

    private void CloseAfter(int duration, TaskScheduler ui) 
    { 
     Thread.Sleep(duration * 1000); 

     Form form = this; 

     Task.Factory.StartNew(
      () => form.Close(), 
      CancellationToken.None, 
      TaskCreationOptions.None, 
      ui); 
    } 
} 

당신은 다음과 같이 사용할 수 있습니다 :

대신 그 다음 더 좋은 효과를 닫을 사라질 때까지 당신이 전혀 기간을 원하는 가정 폼의 불투명도를 줄일 수 닫는
private void showButton_Click(object sender, EventArgs e) 
    { 
     var tooltip = new MyTooltip(
      (int)this.xBox.Value, 
      (int)this.yBox.Value, 
      50, 
      50, 
      "This is my custom tooltip message.", 
      (int)durationBox.Value); 

     tooltip.Show(); 
    } 

.

또한 투명도 색상으로 놀러와 모양의 도구 설명을하는 등 배경 이미지를 사용할 수 있습니다.

편집 : 여기

는 CloseAfter 방법은 툴팁 양식을 페이드 수있는 방법에 대한 간단한 데모입니다.

private void CloseAfter(int duration, TaskScheduler ui) 
{ 
    Thread.Sleep(duration * 1000); 

    Form form = this; 

    for (double i = 0.95; i > 0; i -= 0.05) 
    { 
     Task.Factory.StartNew(
      () => form.Opacity = i, 
      CancellationToken.None, 
      TaskCreationOptions.None, 
      ui); 

     Thread.Sleep(50); 
    } 

    Task.Factory.StartNew(
     () => form.Close(), 
     CancellationToken.None, 
     TaskCreationOptions.None, 
     ui); 
} 
+0

감사합니다. 사용하게 될 것입니다. – VixinG