相关疑难解决方法(0)

以编程方式单击"消息框"按钮

正如标题所示,我试图以编程方式模拟MessageBox中的按钮单击.我之前尝试通过其标题找到其句柄,并应用WM_CLOSESC_CLOSE在中关闭MessageBox SendMessage().但是,由于存在"是/否"按钮,这不起作用(X按钮呈灰色显示).

现在我想点击No按钮,如下所示 - :

List<IntPtr> result = new List<IntPtr>();
GCHandle listHandle = GCHandle.Alloc(result);
try
{
     IntPtr Window_hWnd = CloseMessageBox.FindWindowByCaption("#32770", "LastQuestion"); //Could use null as the first argument too. "#32770" represents classname Dialog.
     CloseMessageBox.EnumChildWindows(Window_hWnd, (hWnd, lParam) =>
     {
          StringBuilder sb = new StringBuilder();
          foreach (var control in GCHandle.FromIntPtr(lParam).Target as List<IntPtr>)
          {
                CloseMessageBox.GetWindowText(control, sb, 250);
                if (sb.Equals("&No"))
                {
                    CloseMessageBox.PostMessage(hWnd, CloseMessageBox.MouseDown, 0, 0);
                    CloseMessageBox.PostMessage(hWnd, CloseMessageBox.MouseUp, 0, 0);
                }
          }
          return false;
     }, GCHandle.ToIntPtr(listHandle));

 }
 catch (Exception e) …
Run Code Online (Sandbox Code Playgroud)

c# pinvoke findwindow

2
推荐指数
1
解决办法
6363
查看次数

自动关闭消息框

我有这个程序,其中我使用计时器重定向到另一页.它确实有效,但问题是当我点击取消按钮时会出现一个消息框,当用户不点击它并且计时器滴答时,消息框没有关闭.如何自动关闭消息框?

这就是它的样子..

在此输入图像描述

这是我用来重定向页面的代码

 DispatcherTimer sessionTimer = new DispatcherTimer();
    public CashDepositAccount()
    {
        InitializeComponent();
        con = new SqlConnection(ConfigurationManager.ConnectionStrings["kiosk_dbConnectionString1"].ConnectionString);
        con.Open();
        SqlCommand cmd1 = new SqlCommand("Select idle From [dbo].[Idle]", con);
        idle = Convert.ToInt32(cmd1.ExecuteScalar());

        InputManager.Current.PreProcessInput += Activity;
        activityTimer = new DispatcherTimer
        {
            Interval = TimeSpan.FromMinutes(idle),
            IsEnabled = true
        };
        activityTimer.Tick += Inactivity;

    }
    #region

    void Inactivity(object sender, EventArgs e)
    {

        navigate = "Home";
        Application.Current.Properties["navigate"] = navigate;

    }

    void Activity(object sender, PreProcessInputEventArgs e)
    {


        activityTimer.Stop();
        activityTimer.Start();


    }
Run Code Online (Sandbox Code Playgroud)

当Timer定时器重定向到主页面时,如何关闭消息框?

c# timer messagebox auto-close

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×2

auto-close ×1

findwindow ×1

messagebox ×1

pinvoke ×1

timer ×1