🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / C# RMOS / formu öne getirme bringToFront

1-) C# RMOS - formu öne getirme bringToFront tam kod

 

İLK BUNU DENE

 

 this.WindowState = FormWindowState.Maximized;

 this.TopMost = true;

 

VEYA AŞAĞIDAKİNE BAK

 

using System;

using System.Diagnostics;

using System.Linq;

using System.Windows.Forms;

 

namespace WindowsFormsApplication4

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private const int SW_MAXIMIZE = 1;// 3 yaparsan maximized olur

        [System.Runtime.InteropServices.DllImport("user32.dll")]

        private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

        public static void bringToFront(string title)

        {

            var p = System.Diagnostics.Process.GetProcessesByName(title).FirstOrDefault();//"WINWORD"

            if (p != null)

            {

                ShowWindow(p.MainWindowHandle, SW_MAXIMIZE);

            }

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            Process p = Process.GetProcessesByName("RMOS_OCR").FirstOrDefault();

            if (p != null)

            {

                IntPtr h = p.MainWindowHandle;

                bringToFront("RMOS_OCR");

            }else

            {

                string filename = @"C:\Users\rambo\Documents\Visual Studio 2015\Projects\RMOS_OCR\RMOS_OCR\bin\Debug\RMOS_OCR.exe";

                string server = "rambo";

                string server_user = "sa";

                string server_sifre = "123";

                string ocr_db = "RM_OCR2";

                string kullaniciAd = "1";

                string sifre = "1";

                string tamDeger = server + " " + server_user + " " + server_sifre + " " + ocr_db + " " + kullaniciAd + " " + sifre;

                var proc = System.Diagnostics.Process.Start(filename, tamDeger);//her boşluk bir dizidir "rambo sa 123 RM_OCR2 1 1"

            }

            

        }

    }

}

 

 

2-) 2.yol formu öne getirme bringToFront

 

kullanımı  aşağıda yazan "Beraber" görev yöneticisindeki ismi veya formun text'i

 

bringToFront("Beraber");

// this.WindowState = FormWindowState.Maximized; // kendi formunu çağırırsan kullanırsın

 

kodları

 

        [DllImport("USER32.DLL", CharSet = CharSet.Unicode)]

        public static extern IntPtr FindWindow(String lpClassName, String lpWindowName);

 

        [DllImport("USER32.DLL")]

        public static extern bool SetForegroundWindow(IntPtr hWnd);

 

        public static void bringToFront(string title)

        {

            // Get a handle to the Calculator application.

            IntPtr handle = FindWindow(null, title);

 

            // Verify that Calculator is a running process.

            if (handle == IntPtr.Zero)

            {

                return;

            }

 

            // Make Calculator the foreground application

            SetForegroundWindow(handle);

        }

 

 

 2021 Mart 08 Pazartesi
 573