在主窗体的OnShow中显示模式窗体时,主窗体不显示? [英] Main Form not displaying when showing modal form in main form's OnShow?

查看:121
本文介绍了在主窗体的OnShow中显示模式窗体时,主窗体不显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个应用程序,其中Main Form在Main Form的FormShow事件上调用子窗体.将显示子表单",并提供两个选项供您选择.如果在子表单上选择了第一个选项",则会显示一条消息,并在该主表单之后显示.现在,当应用程序第一次运行时,在子窗体Meassage上选择选项之后,将显示.但是我想以主窗体为背景显示消息.因此,对此有任何解决方案.下面是FormShow代码.

I have created one application in which Main Form Calls Sub Form on FormShow event of Main Form. Sub Form is displayed and gives two options to choose. If First option on sub form is selected then then a Message is displayed and after that Main form will be displayed. Now when application runs on first time then after option selected on subform Meassage will be displayed. But i want to display message with Main Form as Background. So any solution to this. below is the FormShow code.

Procedure TMainForm.FormShow(Sender:TObject);
begin
  if (SubForm.ShowModal = mrOK) and bOption1 then
  begin
    ShowMessage('Enter the value');
  end;
end;

推荐答案

如果我理解正确,那么您的问题是,当消息框显示时,您的主窗体仍然不可见.

If I understand correctly then your problem is that when the message box show up your main form is still invisible.

如果是这种情况,那么您有两个选择:

If this is the case then you have two options:

  1. 不在主表单的OnShow事件中显示您的SubForm,但稍后再显示
  2. ShowModal返回后不立即显示消息,但稍后会显示
  1. Don't show your SubForm from the OnShow event of the main form, but at a later time
  2. Don't show the message directly after ShowModal returns, but at a later time

对于第2点,您可以使用与我建议的方法类似的方法

For point number 2 you can use a similar approach as I suggested here, using PostMessage. So your code would look somethind like this:

procedure TMainForm.FormShow(Sender:TObject);
begin
  if (SubForm.ShowModal = mrOK) and bOption1 then
  begin
    PostMessage(Self.Handle, WM_SHOWMYDIALOG, 0, 0);
  end;
end;

WM_SHOWMYDIALOG的处理程序然后显示实际消息.此方法也可以用于第1点,请参见 ain的答案.

The handler of WM_SHOWMYDIALOG then displays the actual message. This approach can also work for point 1, see ain's answer.

PostMessage将一条消息发布到您的应用程序的消息队列中,该消息队列将在主窗体完成显示之后进行处理.

PostMessageposts a message to your application's message queue which will be processed after the main form finished becoming visible.

这篇关于在主窗体的OnShow中显示模式窗体时,主窗体不显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆