簡體   English   中英

打開一個新窗體並將其置於最前面,同時主窗體在后台運行

[英]Open a new form and bring it to the front whilst the main form is running in the backround

我的代碼截取了屏幕截圖,當它識別出某些單詞時,應該打開一個新表單,但它只會在主表單位於最前面時打開並被帶到最前面。 我希望能夠最小化表格,當它檢測到一個詞時,我希望它能夠將新表格帶到屏幕前面,或者能夠將所有 forms 帶到前面。 我目前的代碼如下

 public void OpenAutoNotes(string Word,string Text, string Note,string Name)
    {
        if (Find(Word, Text))
        {
            AutoNotes AddNote = new AutoNotes(Note, Name);
            AddNote.Show();
            AddNote.BringToFront();
            
        }
    }

Find() function 工作完美,它打開表單,但表單保持最小化或落后於當前 window

我調用要打開的表單的方法是使用計時器,計時器的每個滴答聲都會運行 OpenAutoNotes() function 檢查是否找到單詞。 這里是相關代碼的rest

public void InitTimer()
    {
        timer = new Timer();
        timer.Tick += new EventHandler(timer_Tick);
        timer.Interval = 3000;
        timer.Start();
    }
    private void timer_Tick(object sender, EventArgs e)
    {
        if (SwitchScan == true)
        {
            SearchKeyWords();
        }
    }
    public void SearchKeyWords()
    {
        Bitmap CurrentImage = SelectImageCapture(499, 499, 540, 200, 0, 0);
        pictureBox1.Image = CurrentImage;
        string MessageText = ImageToText(CurrentImage);
        
        OpenAutoNotes("car", MessageText, "Needs car rented", "TestforText");
        OpenAutoNotes("Car", MessageText, "Needs car rented", "TestforText");
        OpenAutoNotes("cot", MessageText, "Needs a cot", "TestforText");
        OpenAutoNotes("Cot", MessageText, "Needs a cot", "TestforText");
       
    }

真正簡單的改變,希望這可以幫助別人,因為我在這里找不到任何有類似問題的東西

if (Find(Word, Text))
        {
            AutoNotes AddNote = new AutoNotes(Note, Name);
            AddNote.TopMost = true;
            AddNote.Show();
            
            
            
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM