1

このような (AutoIt で作成された) ツールチップを画面の任意の場所に作成するにはどうすればよいですか? 私は1時間探していますが、実際には何も見つかりませんでした。これは、trayicons のツールチップのような通常のツールチップであり、どこにでも配置できます。

よろしく

AutoIt ツールチップ()

4

1 に答える 1

1

Windows フォーム、ASP .NET などであるかどうかが問題になるのはなぜですか? それはおそらくあなたの選択に影響を与えるからです。

Windows フォーム アプリケーションの場合は、Windows.Forms.Form から継承する独自のクラスを作成し、いくつかのプロパティを設定してから使用できます。

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);
}
于 2012-11-23T23:09:04.973 に答える