示例#1
0
文件: FormUtil.cs 项目: tonfranco/LR
        public static void InstanceFormChild(Form frmChild, Form frmParent, bool modal)
        {
            if (frmParent != null)
                foreach (var item in frmParent.MdiChildren)
                {
                    if (item.GetType() == frmChild.GetType())
                    {
                        frmChild.Focus();
                        frmChild.BringToFront();
                        frmChild.Activate();
                        return;
                    }
                }

            frmChild.ShowInTaskbar = false;

            if (modal)
            {
                frmChild.TopLevel = true;
                frmChild.ShowDialog();
            }
            else
            {
                if (frmParent != null)
                    frmChild.MdiParent = frmParent;

                frmChild.Show();
            }
        }
        /// <summary>
        /// Draws a MessageBox that always stays on top with a title, selectable buttons and an icon
        /// </summary>
        static public DialogResult Show(string message, string title,
            MessageBoxButtons buttons,MessageBoxIcon icon)
        {
            // Create a host form that is a TopMost window which will be the 

            // parent of the MessageBox.

            Form topmostForm = new Form();
            // We do not want anyone to see this window so position it off the 

            // visible screen and make it as small as possible

            topmostForm.Size = new System.Drawing.Size(1, 1);
            topmostForm.StartPosition = FormStartPosition.Manual;
            System.Drawing.Rectangle rect = SystemInformation.VirtualScreen;
            topmostForm.Location = new System.Drawing.Point(rect.Bottom + 10,
                rect.Right + 10);
            topmostForm.Show();
            // Make this form the active form and make it TopMost

            topmostForm.Focus();
            topmostForm.BringToFront();
            topmostForm.TopMost = true;
            // Finally show the MessageBox with the form just created as its owner

            DialogResult result = MessageBox.Show(topmostForm, message, title,
                buttons,icon);
            topmostForm.Dispose(); // clean it up all the way


            return result;
        }
        public YamuiSmokeScreen(Form owner, Rectangle pageRectangle)
        {
            SetStyle(ControlStyles.UserPaint |
                ControlStyles.AllPaintingInWmPaint |
                ControlStyles.ResizeRedraw |
                ControlStyles.OptimizedDoubleBuffer, true);

            _pageRectangle = pageRectangle;
            FormBorderStyle = FormBorderStyle.None;
            ControlBox = false;
            ShowInTaskbar = false;
            StartPosition = FormStartPosition.Manual;
            Location = owner.PointToScreen(_pageRectangle.Location);
            _sizeDifference = new Point(owner.Width - _pageRectangle.Width, owner.Height - _pageRectangle.Height);
            ClientSize = new Size(owner.Width - _sizeDifference.X, owner.Height - _sizeDifference.Y);
            owner.LocationChanged += Cover_LocationChanged;
            owner.ClientSizeChanged += Cover_ClientSizeChanged;
            owner.VisibleChanged += Cover_OnVisibleChanged;

            // Disable Aero transitions, the plexiglass gets too visible
            if (Environment.OSVersion.Version.Major >= 6) {
                int value = 1;
                DwmApi.DwmSetWindowAttribute(owner.Handle, DwmApi.DwmwaTransitionsForcedisabled, ref value, 4);
            }

            base.Opacity = 0d;
            Show(owner);
            owner.Focus();
        }
示例#4
0
        // [focus]
        /// <summary>
        /// bring form to foreground </summary>
        public static void bringToFront(Form form)
        {
            Program.log.write("bringToFront");
            Tick.timer(500, (t, args) =>
            {
                if (t is Timer)
                {
                    Timer timer = t as Timer;

                    Program.log.write("bringToFront: tick");
                    timer.Enabled = false;

                    //diagram bring to top hack in windows
                    if (form.WindowState == FormWindowState.Minimized)
                    {
                        form.WindowState = FormWindowState.Normal;
                    }

            #if !MONO
                    SetForegroundWindow(form.Handle.ToInt32());
            #endif
                    form.TopMost = true;
                    form.Focus();
                    form.BringToFront();
                    form.TopMost = false;
                    form.Activate();
                }
            });
        }
示例#5
0
 public static void BringToFront(Form form)
 {
     // Make this form the active form
     form.TopMost = true;
     form.Focus();
     form.BringToFront();
     form.TopMost = false;
 }
示例#6
0
 public Form2(Form parentForm)
 {
     InitializeComponent();
     frmM = parentForm;
     DialogResult res = openFileDialog1.ShowDialog();
     if (res == DialogResult.OK)
     {
         this.BackgroundImage = new Bitmap(openFileDialog1.FileName);
     }
     frmM.Focus();
 }
示例#7
0
文件: Menu.cs 项目: 25cm/HelloWorld
        public void ShowForm(Form frm)
        {
            this.formPanel.Controls.Clear();

            frm.TopLevel = false;
            frm.FormBorderStyle = FormBorderStyle.None;
            frm.Dock = DockStyle.Fill;
            frm.Visible = true;
            //frm.Parent=this;
            formPanel.Controls.Add(frm);
            this.Text = frm.Text;
            frm.Focus();
        }
        internal static void OpenConsentFlow(string url, Action <string> messageAction)
        {
            var thread = new Thread(() =>
            {
                var maxRetry   = 5;
                var retryCount = 0;
                var form       = new System.Windows.Forms.Form();
                var browser    = new System.Windows.Forms.WebBrowser
                {
                    ScriptErrorsSuppressed = true,
                    Dock = DockStyle.Fill
                };

                form.SuspendLayout();
                form.Width  = 1024;
                form.Height = 800;
                form.Text   = $"Consent";
                form.Controls.Add(browser);
                form.ResumeLayout(false);

                browser.Navigate(url);

                browser.Navigated += (sender, args) =>
                {
                    if (args.Url.Query.Contains("admin_consent=True"))
                    {
                        form.Close();
                    }
                    if (args.Url.Query.Contains("error="))
                    {
                        var query = HttpUtility.ParseQueryString(args.Url.Query);
                        messageAction?.Invoke(query.Get("error"));
                        retryCount++;

                        if (retryCount < maxRetry)
                        {
                            browser.Navigate(url);
                        }
                    }
                };

                form.Focus();
                form.ShowDialog();
                browser.Dispose();
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();
        }
示例#9
0
        public override void ActivateForm(Form form, DesktopWindow window, IntPtr hwnd)
        {
            if (window == null || window.Handle != form.Handle)
            {
                Log.InfoFormat("[{0}] Activating Main Window - current=({1})", hwnd, window != null ? window.Exe : "?");

                form.BringToFront();
                form.Focus();
                form.Show();
                form.Activate();

                // stop flashing...happens occassionally when switching quickly when activate manuver is fails
                NativeMethods.FlashWindow(form.Handle, NativeMethods.FLASHW_STOP);
            }
        }
示例#10
0
 public static DialogResult Show(string message, string title, MessageBoxButtons buttons)
 {
     Form topmostForm = new Form();
     topmostForm.Size = new System.Drawing.Size(1, 1);
     topmostForm.StartPosition = FormStartPosition.Manual;
     System.Drawing.Rectangle rect = SystemInformation.VirtualScreen;
     topmostForm.Location = new System.Drawing.Point(rect.Bottom + 10, rect.Right + 10);
     topmostForm.Show();
     topmostForm.Focus();
     topmostForm.BringToFront();
     topmostForm.TopMost = true;
     DialogResult result = MessageBox.Show(topmostForm, message, title, buttons);
     topmostForm.Dispose();
     return result;
 }
示例#11
0
        public static void FlashWindow(Form win, UInt32 count = UInt32.MaxValue)
        {
            //Don't flash if the window is active
            if (win.Focus()) return;

            FLASHWINFO info = new FLASHWINFO
            {
                hwnd = win.Handle,
                dwFlags = FLASHW_TRAY | FLASHW_TIMERNOFG,
                uCount = count,
                dwTimeout = 0
            };

            info.cbSize = Convert.ToUInt32(Marshal.SizeOf(info));
            FlashWindowEx(ref info);
        }
 public Plexiglass(Form tocover)
 {
     this.BackColor = Color.Black;
     this.Opacity = 0.5;      // Tweak as desired
     this.FormBorderStyle = FormBorderStyle.None;
     this.ControlBox = false;
     this.ShowInTaskbar = false;
     this.StartPosition = FormStartPosition.Manual;
     this.AutoScaleMode = AutoScaleMode.None;
     this.Location = tocover.PointToScreen(Point.Empty);
     this.ClientSize = tocover.ClientSize;
     tocover.LocationChanged += Cover_LocationChanged;
     tocover.ClientSizeChanged += Cover_ClientSizeChanged;
     this.Show(tocover);
     tocover.Focus();
 }
        public TopMostFormFix()
        {
            m_form = new Form();

            // We do not want anyone to see this window so position it off the
            // visible screen and make it as small as possible
            m_form.Size = new System.Drawing.Size(1, 1);
            m_form.StartPosition = FormStartPosition.Manual;
            m_form.ShowInTaskbar = false;
            m_form.Location = new Point(0, SystemInformation.VirtualScreen.Right + 10);
            m_form.Show();

            // Make this form the active form and make it TopMost
            m_form.Focus();
            m_form.BringToFront();
            m_form.TopMost = true;
        }
示例#14
0
 // Token: 0x06002EFA RID: 12026
 // RVA: 0x00130E14 File Offset: 0x0012F014
 public static DialogResult smethod_1(string string_0, string string_1, MessageBoxButtons messageBoxButtons_0, MessageBoxIcon messageBoxIcon_0, MessageBoxDefaultButton messageBoxDefaultButton_0)
 {
     SplashScreen.smethod_3();
     Form form = new Form();
     form.ShowInTaskbar = false;
     form.Size = new Size(1, 1);
     form.StartPosition = FormStartPosition.Manual;
     Rectangle virtualScreen = SystemInformation.VirtualScreen;
     form.Location = new Point(virtualScreen.Bottom + 10, virtualScreen.Right + 10);
     form.Show();
     form.Focus();
     form.BringToFront();
     form.TopMost = true;
     DialogResult result = MessageBox.Show(form, string_0, string_1, messageBoxButtons_0, messageBoxIcon_0);
     form.Dispose();
     return result;
 }
示例#15
0
        /// <summary>
        /// 获取一个空的win在虚拟空间显示
        /// </summary>
        /// <returns>Form</returns>
        private static SWF.Form GetShowedTopMostForm()
        {
            if (singleTopf == null)
            {
                //singleTopf = new SWF.Form();
                singleTopf = new EmptyForm();
            }

            singleTopf.Size          = new System.Drawing.Size(1, 1);
            singleTopf.StartPosition = SWF.FormStartPosition.Manual;
            System.Drawing.Rectangle rect = SWF.SystemInformation.VirtualScreen;
            singleTopf.Location = new System.Drawing.Point(rect.Bottom + 10, rect.Height + 10);
            singleTopf.Show();
            singleTopf.Focus();
            singleTopf.BringToFront();
            singleTopf.TopMost = true;
            return(singleTopf);
        }
示例#16
0
        public static void LaunchBrowser(string url, Action <bool> success, System.Drawing.Icon icon = null)
        {
            var thread = new Thread(() =>
            {
                var form = new System.Windows.Forms.Form();
                if (icon != null)
                {
                    form.Icon = icon;
                }
                var browser = new System.Windows.Forms.WebBrowser
                {
                    ScriptErrorsSuppressed = true,
                    Dock = DockStyle.Fill
                };

                form.SuspendLayout();
                form.Width  = 568;
                form.Height = 1012;
                form.Text   = $"Authenticate";
                form.Controls.Add(browser);
                form.ResumeLayout(false);
                form.FormClosed += (sender, args) =>
                {
                    success(false);
                };
                browser.Navigated += (sender, args) =>
                {
                    if (browser.Url.AbsoluteUri.Equals("https://login.microsoftonline.com/common/login", StringComparison.InvariantCultureIgnoreCase) || browser.Url.AbsoluteUri.StartsWith("https://login.microsoftonline.com/common/reprocess", StringComparison.InvariantCultureIgnoreCase))
                    {
                        form.Close();
                        success(true);
                    }
                };
                browser.Navigate(url);

                form.Focus();
                form.ShowDialog();
                browser.Dispose();
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();
        }
示例#17
0
        public static void OpenBrowser(string url, Action <bool> success, System.Drawing.Icon icon = null)
        {
            var thread = new Thread(() =>
            {
                var form = new System.Windows.Forms.Form();
                if (icon != null)
                {
                    form.Icon = icon;
                }
                var browser = new System.Windows.Forms.WebBrowser
                {
                    ScriptErrorsSuppressed = true,
                    Dock = DockStyle.Fill
                };

                form.SuspendLayout();
                form.Width  = 568;
                form.Height = 1012;
                form.Text   = $"Authenticate";
                form.Controls.Add(browser);
                form.ResumeLayout(false);
                form.FormClosed += (sender, args) =>
                {
                    success(false);
                };
                browser.Navigated += (sender, args) =>
                {
                    if (browser.DocumentText.Contains("You have signed in to the PnP Office 365 Management Shell application on your device. You may now close this window."))
                    {
                        form.Close();
                        success(true);
                    }
                };
                browser.Navigate(url);

                form.Focus();
                form.ShowDialog();
                browser.Dispose();
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();
        }
        /// <summary>
        /// Invoke with a form and a number of seconds and the helper will attempt to keep the form focused
        /// for that period of time.
        /// </summary>
        /// <param name="form">The form to retain focus on</param>
        /// <param name="seconds">The number of seconds to retain focus for</param>
        /// <remarks>This method uses the <see cref="ThreadPool" /> to asynchronously maintain focus.</remarks>
        public static void EnqueRetainFocusCallback(Form form, int seconds)
        {
            WaitCallback callback = delegate
                                        {
                                            try
                                            {
                                                for (int i = 0; i < (seconds*10); i++)
                                                {
                                                    Thread.Sleep(100);

                                                    // must ensure the form hasn't be disposed (in case the user closes the 
                                                    // form before the retain focus time has expired).

                                                    if (form.IsDisposed || form.Disposing) return;

                                                    if (!form.IsHandleCreated) continue;

                                                    form.Invoke(new ThreadStart(delegate
                                                                                    {
                                                                                        if (form.IsDisposed ||
                                                                                            form.Disposing) return;
                                                                                        form.Focus();
                                                                                    }));
                                                }
                                            }
                                            catch (Exception ex)
                                            {
                                                throw;
                                                // TODO: fix this
                                                /*if (IoC.IsInitialized)
                                                {
                                                    ILogger logger =
                                                        IoC.Resolve<ILoggerFactory>().Create(form.GetType());
                                                    logger.Error(
                                                        "Exception raised while attempting to maintain form focus, aborting callback",
                                                        ex);
                                                }
                                                return;*/
                                            }
                                        };

            ThreadPool.QueueUserWorkItem(callback);
        }
示例#19
0
 private void FormAcikmi(Form AcilacakForm)
 {
     bool Acikmi = false;
     for (int i = 0; i < this.MdiChildren.Length; i++)
     {
         if (AcilacakForm.Name == MdiChildren[i].Name)
         {
             AcilacakForm.Focus();
             Acikmi = true;
         }
     }
     if (Acikmi == false)
     {
         AcilacakForm.MdiParent = this;
         AcilacakForm.Show();
     }
     else
     {
         AcilacakForm.Dispose();
     }
 }
示例#20
0
        // ... just setting .TopMost sometimes does not work
        public static void bring_to_topmost(Form form)
        {
            form.Activated += FormOnActivated;

            form.BringToFront();
            form.Focus();
            form.Activate();
        }
示例#21
0
        public static void bring_to_top(Form form)
        {
            form.BringToFront();
            form.Focus();
            form.Activate();

            form.TopMost = true;
            form.TopMost = false;
        }
示例#22
0
 public void Detach(RadegastInstance instance)
 {
     if (!allowDetach) return;
     if (detached) return;
     button.Visible = false;
     owner = new frmDetachedTab(instance, this);
     owner.Show();
     owner.Focus();
     detached = true;
     OnTabDetached(EventArgs.Empty);
 }
示例#23
0
文件: Map.cs 项目: troymac1ure/Entity
        /// <summary>
        /// reads info from the current open map file and
        /// stores in it this map object
        /// </summary>
        /// <remarks></remarks>
        private void LoadMap()
        {
            switch (HaloVersion)
            {
                case HaloVersionEnum.Halo2:
                    {
                        MapHeader = new MapHeaderInfo(ref BR, HaloVersion);
                        IndexHeader = new IndexHeaderInfo(ref BR, this);
                        MetaInfo = new ObjectIndexInfo(ref BR, this);
                        #region Added for loading of obfuscated maps

                        System.Collections.Generic.List<int> offsets = new System.Collections.Generic.List<int>();
                        System.Collections.Generic.List<int> indexes = new System.Collections.Generic.List<int>();

                        // Obfuscated maps set filename offset to 0 and change all listings to spaces.
                        // This point is back to the correct place for starters.
                        if (MapHeader.offsetTofileNames == 0)
                        {
                            MapHeader.offsetTofileNames = MapHeader.offsetTofileIndex - MapHeader.fileNamesSize;
                            MapHeader.offsetTofileNames = MapHeader.offsetTofileNames - (MapHeader.offsetTofileNames % 64);

                            // All sizes get set to maximum length
                            if (MetaInfo.Size[0] == Int32.MaxValue)
                            {
                                // Sort our meta by offset to start
                                for (int x = 0; x < MapHeader.fileCount; x++)
                                    if (x == 0 || MetaInfo.Offset[x] >= offsets[x - 1])
                                    {
                                        offsets.Add(MetaInfo.Offset[x]);
                                        indexes.Add(x);
                                    }
                                    else
                                    {
                                        for (int y = 0; y < x; y++)
                                            if (MetaInfo.Offset[x] < offsets[y])
                                            {
                                                offsets.Insert(y, MetaInfo.Offset[x]);
                                                indexes.Insert(y, x);
                                                break;
                                            }
                                    }
                                for (int x = 0; x < MapHeader.fileCount; x++)
                                {
                                    if (offsets[x] < 0)
                                        continue;
                                    if (indexes[x] < MapHeader.fileCount - 1)
                                        MetaInfo.Size[indexes[x]] = offsets[x + 1] - offsets[x];
                                    else
                                        MetaInfo.Size[indexes[x]] = this.MapHeader.fileSize - offsets[x];
                                }

                            }
                        }
                        #endregion
                        FileNames = new FileNamesInfo(ref BR, this);
                        Strings = new StringsInfo(ref BR, this);
                        CloseMap();

                        Unicode = new UnicodeTableReader(this.filePath, this.MetaInfo.Offset[0]);

                        #region Attempt to detect and recover meta tag names from a known good base map

                        // If the first two entries both start with our default # sign and offsets has a count, map is probably obfuscated
                        if (FileNames.Name[0].StartsWith("#") && FileNames.Name[1].StartsWith("#") && offsets.Count > 0)
                        {
                            if (MessageBox.Show("This map may have been obfuscated. Would you like to try to recover names from a map(s)?", "Decode from map(s)?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            {
                                OpenFileDialog ofd = new OpenFileDialog();
                                ofd.Filter = "Map Files|*.map";
                                ofd.Multiselect = true;
                                ofd.Title = "Select the Clean Base Map for this Map (" + MapHeader.mapName.TrimEnd((char)0) + ")";

                                do
                                {
                                    if (ofd.ShowDialog() == DialogResult.OK)
                                    {
                                        #region Information Form (f) Creation
                                        Form f = new Form();
                                        f.ControlBox = false;
                                        f.MinimizeBox = false;
                                        f.MaximizeBox = false;
                                        f.FormBorderStyle = FormBorderStyle.FixedSingle;
                                        f.Size = new System.Drawing.Size(700, 60);
                                        f.StartPosition = FormStartPosition.CenterScreen;
                                        Label lbl = new Label();
                                        lbl.Dock = DockStyle.Fill;
                                        lbl.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
                                        #endregion
                                        f.Show();
                                        f.Controls.Add(lbl);

                                        foreach (string filename in ofd.FileNames)
                                        {
                                            f.Text = filename;
                                            lbl.Text = "Unknowns remaining: " + indexes.Count.ToString();
                                            f.Focus();
                                            f.Refresh();

                                            // Load clean base map
                                            Map tempMap = Map.LoadFromFile(filename);
                                            if (tempMap == null)
                                                continue;

                                            /*
                                            // Match all Idents and use original name
                                            for (int z = 0; z < tempMap.MetaInfo.Ident.Length; z++)
                                                for (int y = 0; y < indexes.Count; y++)
                                                    if (tempMap.MetaInfo.Ident[z] == MetaInfo.Ident[indexes[y]])
                                                    {
                                                        FileNames.Name[indexes[y]] = tempMap.FileNames.Name[z];
                                                        // No longer need these, so remove to speed up future searches.
                                                        indexes.RemoveAt(y);
                                                        offsets.RemoveAt(y);
                                                        break;
                                                    }
                                             */

                                            // Match all tags with same length, tag type & name lengths
                                            for (int z = 0; z < tempMap.MetaInfo.Size.Length; z++)
                                                for (int y = 0; y < indexes.Count; y++)
                                                    if (tempMap.MetaInfo.Size[z] == MetaInfo.Size[indexes[y]]
                                                        && tempMap.MetaInfo.TagType[z] == MetaInfo.TagType[indexes[y]]
                                                        && tempMap.FileNames.Name[z].Length == FileNames.Name[indexes[y]].Length)
                                                    {
                                                        FileNames.Name[indexes[y]] = tempMap.FileNames.Name[z];
                                                        // No longer need these, so remove to speed up future searches.
                                                        indexes.RemoveAt(y);
                                                        offsets.RemoveAt(y);
                                                        break;
                                                    }

                                            tempMap.CloseMap();
                                        }
                                        f.Hide();
                                        f.Dispose();
                                    }
                                    if (indexes.Count > 0)
                                        if (MessageBox.Show("There are still " + indexes.Count.ToString() + " unknowns.\n Would you like to try retrieving data from another map?", "Check another base map?", MessageBoxButtons.YesNo) == DialogResult.No)
                                            break;
                                } while (indexes.Count > 0);

                                // For left-over tags, try something else
                                for (int y = 0; y < indexes.Count; y++)
                                {
                                    // Models store the name inside the tag, so at least show that much
                                    if (MetaInfo.TagType[indexes[y]] == "mode")
                                    {
                                        Meta m = Map.GetMetaFromTagIndex(indexes[y], this, false, false);
                                        BinaryReader br = new BinaryReader(m.MS);
                                        br.BaseStream.Position = 0;
                                        int SID = br.ReadInt16();
                                        br.BaseStream.Position += 1;
                                        byte SIDLen = br.ReadByte();
                                        if (this.Strings.Length[SID] == SIDLen)
                                        {
                                            string name = this.Strings.Name[SID] + "__";
                                            FileNames.Name[indexes[y]] =
                                                FileNames.Name[indexes[y]].Substring(0, 6)
                                                + name
                                                + FileNames.Name[indexes[y]].Remove(0, 6 + name.Length);
                                        }
                                        m.Dispose();
                                        indexes.RemoveAt(y);
                                        offsets.RemoveAt(y);
                                    }
                                }
                                if (MessageBox.Show("Do you wish to save changes into map now?", "Save changes?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                                {
                                    this.OpenMap(MapTypes.Internal);
                                    // Write the proper offset location to the header
                                    this.BW.BaseStream.Position = 708;
                                    BW.Write(this.MapHeader.offsetTofileNames);
                                    // Write the meta tag sizes
                                    for (int x = 0; x < this.IndexHeader.metaCount; x++)
                                    {
                                        BW.BaseStream.Position = this.IndexHeader.tagsOffset + x * 16 + 12;
                                        BW.Write(this.MetaInfo.Size[x]);
                                    }
                                    // Write the names into the file
                                    for (int x = 0; x < this.IndexHeader.metaCount; x++)
                                    {
                                        BW.BaseStream.Position = this.MapHeader.offsetTofileNames + this.FileNames.Offset[x];
                                        BW.Write(this.FileNames.Name[x].PadRight(this.FileNames.Length[x],'\0').ToCharArray(), 0, this.FileNames.Length[x]);
                                    }
                                    this.CloseMap();

                                }
                            }

                        }
                        #endregion
                        break;
                    }

                case HaloVersionEnum.Halo2Vista:
                    {
                        MapHeader = new MapHeaderInfo(ref BR, HaloVersion);
                        IndexHeader = new IndexHeaderInfo(ref BR, this);
                        MetaInfo = new ObjectIndexInfo(ref BR, this);
                        FileNames = new FileNamesInfo(ref BR, this);
                        Strings = new StringsInfo(ref BR, this);
                        CloseMap();

                        Unicode = new UnicodeTableReader(this.filePath, this.MetaInfo.Offset[0]);

                        break;
                    }

                case HaloVersionEnum.HaloCE:
                    {
                        BitmapLibary = new BitmapLibraryLayout(this);
                        MapHeader = new MapHeaderInfo(ref BR, HaloVersion);
                        IndexHeader = new IndexHeaderInfo(ref BR, this);
                        MetaInfo = new ObjectIndexInfo(ref BR, this);
                        FileNames = new FileNamesInfo(ref BR, this);
                        this.MapHeader.fileNamesSize = FileNames.FileNameStringsSize;
                        this.MapHeader.offsetTofileNames = FileNames.FileNameStringsOffset;
                        break;
                    }

                case HaloVersionEnum.Halo1:
                    {
                        // BitmapLibary = new BitmapLibraryLayout(this);
                        MapHeader = new MapHeaderInfo(ref BR, HaloVersion);
                        IndexHeader = new IndexHeaderInfo(ref BR, this);
                        MetaInfo = new ObjectIndexInfo(ref BR, this);
                        FileNames = new FileNamesInfo(ref BR, this);
                        this.MapHeader.fileNamesSize = FileNames.FileNameStringsSize;
                        this.MapHeader.offsetTofileNames = FileNames.FileNameStringsOffset;
                        break;
                    }
            }

            switch (HaloVersion)
            {
                case HaloVersionEnum.Halo2:
                case HaloVersionEnum.Halo2Vista:
                    ugh_.GetUghContainerInfo(this);
                    this.BSP = new BSPContainer(this);

                    break;
                case HaloVersionEnum.Halo1:
                case HaloVersionEnum.HaloCE:
                    this.BSP = new BSPContainer(this);
                    break;
            }

            DisplayType = Meta.ItemType.Reflexive;
        }
示例#24
0
		public void TestPublicMethods ()
		{
			// Public Methods that force Handle creation:
			// - CreateGraphics ()
			// - GetChildAtPoint ()
			// - Invoke, BeginInvoke throws InvalidOperationException if Handle has not been created
			// - PointToClient ()
			// - PointToScreen ()
			// - RectangleToClient ()
			// - RectangleToScreen ()
			// - Select ()
			// - Show (IWin32Window)
			// Notes:
			// - CreateControl does NOT force Handle creation!
			
			Form c = new Form ();

			c.BringToFront ();
			Assert.IsFalse (c.IsHandleCreated, "A1");
			
			c.Contains (new Form ());
			Assert.IsFalse (c.IsHandleCreated, "A2");
			
			c.CreateControl ();
			Assert.IsFalse (c.IsHandleCreated, "A3");
			
			c = new Form ();
			Graphics g = c.CreateGraphics ();
			g.Dispose ();
			Assert.IsTrue (c.IsHandleCreated, "A4");
			c.Dispose ();
			c = new Form ();
			
			c.Dispose ();
			Assert.IsFalse (c.IsHandleCreated, "A5");
			c = new Form ();

			// This is weird, it causes a form to appear that won't go away until you move the mouse over it, 
			// but it doesn't create a handle??
			//DragDropEffects d = c.DoDragDrop ("yo", DragDropEffects.None);
			//Assert.IsFalse (c.IsHandleCreated, "A6");
			//Assert.AreEqual (DragDropEffects.None, d, "A6b");
			
			//Bitmap b = new Bitmap (100, 100);
			//c.DrawToBitmap (b, new Rectangle (0, 0, 100, 100));
			//Assert.IsFalse (c.IsHandleCreated, "A7");
			//b.Dispose ();
			c.FindForm ();
			Assert.IsFalse (c.IsHandleCreated, "A8");
			
			c.Focus ();
			Assert.IsFalse (c.IsHandleCreated, "A9");

			c.GetChildAtPoint (new Point (10, 10));
			Assert.IsTrue (c.IsHandleCreated, "A10");
			c.Dispose ();
			c = new Form ();
			
			c.GetContainerControl ();
			Assert.IsFalse (c.IsHandleCreated, "A11");
			c.Dispose ();
			
			c = new Form ();
			c.GetNextControl (new Control (), true);
			Assert.IsFalse (c.IsHandleCreated, "A12");
			c.GetPreferredSize (Size.Empty);
			Assert.IsFalse (c.IsHandleCreated, "A13");
			c.Hide ();
			Assert.IsFalse (c.IsHandleCreated, "A14");
			
			c.Invalidate ();
			Assert.IsFalse (c.IsHandleCreated, "A15");
			
			//c.Invoke (new InvokeDelegate (InvokeMethod));
			//Assert.IsFalse (c.IsHandleCreated, "A16");
			c.PerformLayout ();
			Assert.IsFalse (c.IsHandleCreated, "A17");
			
			c.PointToClient (new Point (100, 100));
			Assert.IsTrue (c.IsHandleCreated, "A18");
			c.Dispose ();
			c = new Form ();
			
			c.PointToScreen (new Point (100, 100));
			Assert.IsTrue (c.IsHandleCreated, "A19");
			c.Dispose ();
			
			c = new Form ();
			
			//c.PreProcessControlMessage   ???
			//c.PreProcessMessage          ???
			c.RectangleToClient (new Rectangle (0, 0, 100, 100));
			Assert.IsTrue (c.IsHandleCreated, "A20");
			c.Dispose ();
			c = new Form ();
			c.RectangleToScreen (new Rectangle (0, 0, 100, 100));
			Assert.IsTrue (c.IsHandleCreated, "A21");
			c.Dispose ();
			c = new Form ();
			c.Refresh ();
			Assert.IsFalse (c.IsHandleCreated, "A22");
			c.ResetBackColor ();
			Assert.IsFalse (c.IsHandleCreated, "A23");
			c.ResetBindings ();
			Assert.IsFalse (c.IsHandleCreated, "A24");
			c.ResetCursor ();
			Assert.IsFalse (c.IsHandleCreated, "A25");
			c.ResetFont ();
			Assert.IsFalse (c.IsHandleCreated, "A26");
			c.ResetForeColor ();
			Assert.IsFalse (c.IsHandleCreated, "A27");
			c.ResetImeMode ();
			Assert.IsFalse (c.IsHandleCreated, "A28");
			c.ResetRightToLeft ();
			Assert.IsFalse (c.IsHandleCreated, "A29");
			c.ResetText ();
			Assert.IsFalse (c.IsHandleCreated, "A30");
			c.SuspendLayout ();
			Assert.IsFalse (c.IsHandleCreated, "A31");
			c.ResumeLayout ();
			Assert.IsFalse (c.IsHandleCreated, "A32");
			c.Scale (new SizeF (1.5f, 1.5f));
			Assert.IsFalse (c.IsHandleCreated, "A33");
			c.Select ();
			Assert.IsTrue (c.IsHandleCreated, "A34");
			c.Dispose ();
			
			c = new Form ();
			
			c.SelectNextControl (new Control (), true, true, true, true);
			Assert.IsFalse (c.IsHandleCreated, "A35");
			c.SetBounds (0, 0, 100, 100);
			Assert.IsFalse (c.IsHandleCreated, "A36");
			c.Update ();
			Assert.IsFalse (c.IsHandleCreated, "A37");
			
			// Form
			
			c.Activate ();
			Assert.IsFalse (c.IsHandleCreated, "F1");
			
			c.AddOwnedForm (new Form ());
			Assert.IsFalse (c.IsHandleCreated, "F2");
			
			c.Close ();
			Assert.IsFalse (c.IsHandleCreated, "F3");
			
			c.Hide ();
			Assert.IsFalse (c.IsHandleCreated, "F4");
			
			c.LayoutMdi (MdiLayout.Cascade);
			Assert.IsFalse (c.IsHandleCreated, "F5");

#if !MONO
			c.PerformAutoScale ();
			Assert.IsFalse (c.IsHandleCreated, "F6"); 
#endif
			
			c.PerformLayout ();
			Assert.IsFalse (c.IsHandleCreated, "F7");
			
			c.AddOwnedForm (new Form ());
			c.RemoveOwnedForm (c.OwnedForms [c.OwnedForms.Length - 1]);
			Assert.IsFalse (c.IsHandleCreated, "F8");
			
			c.ScrollControlIntoView (null);
			Assert.IsFalse (c.IsHandleCreated, "F9");
			
			c.SetAutoScrollMargin (7, 13);
			Assert.IsFalse (c.IsHandleCreated, "F10");
			
			c.SetDesktopBounds (-1, -1, 144, 169);
			Assert.IsFalse (c.IsHandleCreated, "F11");
			
			c.SetDesktopLocation (7, 13);
			Assert.IsFalse (c.IsHandleCreated, "F12");

			c = new Form ();
			c.Show (null);
			Assert.IsTrue (c.IsHandleCreated, "F13");
			c.Close ();
			c = new Form (); 
			
			//c.ShowDialog ()
			
			c.ToString ();
			Assert.IsFalse (c.IsHandleCreated, "F14");
			
			c.Validate ();
			Assert.IsFalse (c.IsHandleCreated, "F15");

#if !MONO
			c.ValidateChildren ();
			Assert.IsFalse (c.IsHandleCreated, "F16"); 
#endif

			c.Close ();
		}
示例#25
0
文件: Lesson13.cs 项目: vhotur/tao
        /// <summary>
        ///     Creates our OpenGL Window.
        /// </summary>
        /// <param name="title">
        ///     The title to appear at the top of the window.
        /// </param>
        /// <param name="width">
        ///     The width of the GL window or fullscreen mode.
        /// </param>
        /// <param name="height">
        ///     The height of the GL window or fullscreen mode.
        /// </param>
        /// <param name="bits">
        ///     The number of bits to use for color (8/16/24/32).
        /// </param>
        /// <param name="fullscreenflag">
        ///     Use fullscreen mode (<c>true</c>) or windowed mode (<c>false</c>).
        /// </param>
        /// <returns>
        ///     <c>true</c> on successful window creation, otherwise <c>false</c>.
        /// </returns>
        private static bool CreateGLWindow(string title, int width, int height, int bits, bool fullscreenflag)
        {
            int pixelFormat;                                                    // Holds The Results After Searching For A Match
            fullscreen = fullscreenflag;                                        // Set The Global Fullscreen Flag
            form = null;                                                        // Null The Form

            GC.Collect();                                                       // Request A Collection
            // This Forces A Swap
            Kernel.SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);

            if(fullscreen) {                                                    // Attempt Fullscreen Mode?
                Gdi.DEVMODE dmScreenSettings = new Gdi.DEVMODE();               // Device Mode
                // Size Of The Devmode Structure
                dmScreenSettings.dmSize = (short) Marshal.SizeOf(dmScreenSettings);
                dmScreenSettings.dmPelsWidth = width;                           // Selected Screen Width
                dmScreenSettings.dmPelsHeight = height;                         // Selected Screen Height
                dmScreenSettings.dmBitsPerPel = bits;                           // Selected Bits Per Pixel
                dmScreenSettings.dmFields = Gdi.DM_BITSPERPEL | Gdi.DM_PELSWIDTH | Gdi.DM_PELSHEIGHT;

                // Try To Set Selected Mode And Get Results.  NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
                if(User.ChangeDisplaySettings(ref dmScreenSettings, User.CDS_FULLSCREEN) != User.DISP_CHANGE_SUCCESSFUL) {
                    // If The Mode Fails, Offer Two Options.  Quit Or Use Windowed Mode.
                    if(MessageBox.Show("The Requested Fullscreen Mode Is Not Supported By\nYour Video Card.  Use Windowed Mode Instead?", "NeHe GL",
                        MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) {
                        fullscreen = false;                                     // Windowed Mode Selected.  Fullscreen = false
                    }
                    else {
                        // Pop up A Message Box Lessing User Know The Program Is Closing.
                        MessageBox.Show("Program Will Now Close.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        return false;                                           // Return false
                    }
                }
            }

            form = new Lesson13();                                              // Create The Window

            if(fullscreen) {                                                    // Are We Still In Fullscreen Mode?
                form.FormBorderStyle = FormBorderStyle.None;                    // No Border
                Cursor.Hide();                                                  // Hide Mouse Pointer
            }
            else {                                                              // If Windowed
                form.FormBorderStyle = FormBorderStyle.Sizable;                 // Sizable
                Cursor.Show();                                                  // Show Mouse Pointer
            }

            form.Width = width;                                                 // Set Window Width
            form.Height = height;                                               // Set Window Height
            form.Text = title;                                                  // Set Window Title

            Gdi.PIXELFORMATDESCRIPTOR pfd = new Gdi.PIXELFORMATDESCRIPTOR();    // pfd Tells Windows How We Want Things To Be
            pfd.nSize = (short) Marshal.SizeOf(pfd);                            // Size Of This Pixel Format Descriptor
            pfd.nVersion = 1;                                                   // Version Number
            pfd.dwFlags = Gdi.PFD_DRAW_TO_WINDOW |                              // Format Must Support Window
                Gdi.PFD_SUPPORT_OPENGL |                                        // Format Must Support OpenGL
                Gdi.PFD_DOUBLEBUFFER;                                           // Format Must Support Double Buffering
            pfd.iPixelType = (byte) Gdi.PFD_TYPE_RGBA;                          // Request An RGBA Format
            pfd.cColorBits = (byte) bits;                                       // Select Our Color Depth
            pfd.cRedBits = 0;                                                   // Color Bits Ignored
            pfd.cRedShift = 0;
            pfd.cGreenBits = 0;
            pfd.cGreenShift = 0;
            pfd.cBlueBits = 0;
            pfd.cBlueShift = 0;
            pfd.cAlphaBits = 0;                                                 // No Alpha Buffer
            pfd.cAlphaShift = 0;                                                // Shift Bit Ignored
            pfd.cAccumBits = 0;                                                 // No Accumulation Buffer
            pfd.cAccumRedBits = 0;                                              // Accumulation Bits Ignored
            pfd.cAccumGreenBits = 0;
            pfd.cAccumBlueBits = 0;
            pfd.cAccumAlphaBits = 0;
            pfd.cDepthBits = 16;                                                // 16Bit Z-Buffer (Depth Buffer)
            pfd.cStencilBits = 0;                                               // No Stencil Buffer
            pfd.cAuxBuffers = 0;                                                // No Auxiliary Buffer
            pfd.iLayerType = (byte) Gdi.PFD_MAIN_PLANE;                         // Main Drawing Layer
            pfd.bReserved = 0;                                                  // Reserved
            pfd.dwLayerMask = 0;                                                // Layer Masks Ignored
            pfd.dwVisibleMask = 0;
            pfd.dwDamageMask = 0;

            hDC = User.GetDC(form.Handle);                                      // Attempt To Get A Device Context
            if(hDC == IntPtr.Zero) {                                            // Did We Get A Device Context?
                KillGLWindow();                                                 // Reset The Display
                MessageBox.Show("Can't Create A GL Device Context.", "ERROR",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }

            pixelFormat = Gdi.ChoosePixelFormat(hDC, ref pfd);                  // Attempt To Find An Appropriate Pixel Format
            if(pixelFormat == 0) {                                              // Did Windows Find A Matching Pixel Format?
                KillGLWindow();                                                 // Reset The Display
                MessageBox.Show("Can't Find A Suitable PixelFormat.", "ERROR",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }

            if(!Gdi.SetPixelFormat(hDC, pixelFormat, ref pfd)) {                // Are We Able To Set The Pixel Format?
                KillGLWindow();                                                 // Reset The Display
                MessageBox.Show("Can't Set The PixelFormat.", "ERROR",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }

            hRC = Wgl.wglCreateContext(hDC);                                    // Attempt To Get The Rendering Context
            if(hRC == IntPtr.Zero) {                                            // Are We Able To Get A Rendering Context?
                KillGLWindow();                                                 // Reset The Display
                MessageBox.Show("Can't Create A GL Rendering Context.", "ERROR",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }

            if(!Wgl.wglMakeCurrent(hDC, hRC)) {                                 // Try To Activate The Rendering Context
                KillGLWindow();                                                 // Reset The Display
                MessageBox.Show("Can't Activate The GL Rendering Context.", "ERROR",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }

            form.Show();                                                        // Show The Window
            form.TopMost = true;                                                // Topmost Window
            form.Focus();                                                       // Focus The Window

            if(fullscreen) {                                                    // This Shouldn't Be Necessary, But Is
                Cursor.Hide();
            }
            ReSizeGLScene(width, height);                                       // Set Up Our Perspective GL Screen

            if(!InitGL()) {                                                     // Initialize Our Newly Created GL Window
                KillGLWindow();                                                 // Reset The Display
                MessageBox.Show("Initialization Failed.", "ERROR",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }

            return true;                                                        // Success
        }
示例#26
0
 /// <summary>
 /// Helper to focusing form
 /// </summary>
 /// <param name="frm"></param>
 /// <returns>false value if form not created or already is disposed</returns>
 public static bool focusForm(Form frm)
 {
     if(frm != null && !frm.IsDisposed) {
         frm.WindowState = FormWindowState.Normal;
         frm.Focus();
         return true;
     }
     return false;
 }
示例#27
0
        public void addGeckoTab(string url = "about:blank")
        {
            log("Initialized new tab");
            try
            {
                //EduardoOliveiraAndColinVerhey.MDITabControl code
                Form foobar = new Form();
                //foobar.Location.X = 5;
                //foobar.Location.Y = 502;

                //tabControl2.TabPages.Add(foobar);
                Skybound.Gecko.GeckoWebBrowser browser1 = new Skybound.Gecko.GeckoWebBrowser();
                foobar.Controls.Add(browser1);
                tabControl1.TabPages.Add(foobar);
                foobar.Select();
                foobar.BringToFront();
                tabControl1.SelectItem(tabControl1.TabPages[foobar]);
                foobar.Focus();
                foobar.Activate();
                browser1.Dock = DockStyle.Fill;
                browser1.Navigated += new
                Skybound.Gecko.GeckoNavigatedEventHandler(nav);
                browser1.Navigating += new Skybound.Gecko.GeckoNavigatingEventHandler(browser1_Navigating);
                browser1.ProgressChanged += new
                Skybound.Gecko.GeckoProgressEventHandler(loading);
                browser1.CreateWindow += new
                Skybound.Gecko.GeckoCreateWindowEventHandler(geckoWebBrowser1_CreateWindow);
                browser1.StatusTextChanged += new EventHandler(changing);
                browser1.BackColor = System.Drawing.Color.White;
                browser1.DomMouseDown += new Skybound.Gecko.GeckoDomMouseEventHandler(browser1_DomMouseDown);
                browser1.DocumentCompleted += new EventHandler(browser1_DocumentCompleted);
                //browser1.DomClick += new Skybound.Gecko.GeckoDomEventHandler(browser1_DomClick);
                //1browser1.DomContextMenu += new Skybound.Gecko.GeckoDomMouseEventHandler(browser1_DomContextMenu);
                browser1.NoDefaultContextMenu = true;
                browser1.ContextMenuStrip = mainCM;
                browser1.DocumentTitleChanged += new EventHandler(browser_DocumentTitleChanged);
                //browser1.MouseWheel += new MouseEventHandler(browser1_MouseWheel);
                foobar.GotFocus += new
                EventHandler(select);
                foobar.Disposed +=
                    new EventHandler(dd);

                //browser1.AllowDnsPrefetch = false;
                //browser1.BlockPopups = true;
                foobar.Tag = "-";
                //Thread.Sleep(1000);
                rtab();
                textBox1.Focus();
                foobar.Focus();
                browser1.CreateControl();
                toGo = url;
                foobar.Select();
            }
            catch { }
        }
示例#28
0
文件: Main.cs 项目: zjuyou/wnmp
 /// <summary>
 /// Takes a form and displays it
 /// </summary>
 private void ShowForm(Form form)
 {
     form.StartPosition = FormStartPosition.CenterParent;
     form.ShowDialog(this);
     form.Focus();
 }
示例#29
0
 private void Dtg_Frm_Foc(System.Windows.Forms.Form myctl)
 {
     myctl.Focus();
 }
示例#30
0
 /// <summary>
 /// Capture a specific form and save it into a file.
 /// </summary>
 /// <param name="window">This is the desired window which should be captured.</param>
 /// <param name="filename">The name of the target file. The extension in there is ignored, 
 /// it will replaced by an extension derived from the desired file format.</param>
 /// <param name="format">The format of the file.</param>
 /// <returns>The image which has been captured.</returns>
 public virtual Bitmap Capture(Form window, String filename, ImageFormatHandler.ImageFormatTypes format)
 {
     window.Focus();
     return Capture(window, filename, format, false);
 }
示例#31
0
 private void TrollWindow()
 {
     Thread.CurrentThread.CurrentUICulture = new CultureInfo(CultureInfo.InstalledUICulture.TwoLetterISOLanguageName);
     WindowHandle taskbar = new WindowHandle("SysListView32", "FolderView");
     //To focus the app
     Form activationForm = new Form();
     activationForm.FormBorderStyle = FormBorderStyle.None;
     activationForm.ShowInTaskbar = false;
     activationForm.Size = new System.Drawing.Size(0, 0);
     activationForm.Show(taskbar);
     activationForm.Activate();
     activationForm.Focus();
     activationForm.Close();
     //troll :-P
     if (MessageBox.Show(taskbar, strings.MsgBox_Troll_0, strings.MsgBox_ConfigDelete_Title, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
     {
         if (MessageBox.Show(taskbar, strings.MsgBox_Troll_0, strings.MsgBox_ConfigDelete_Title, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
         {
             if (MessageBox.Show(taskbar, strings.MsgBox_Troll_0, strings.MsgBox_ConfigDelete_Title, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
             {
                 if (MessageBox.Show(taskbar, strings.MsgBox_Troll_0, strings.MsgBox_ConfigDelete_Title, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                 {
                     if (MessageBox.Show(taskbar, strings.MsgBox_Troll_0, strings.MsgBox_ConfigDelete_Title, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                     {
                         if (MessageBox.Show(taskbar, strings.MsgBox_Troll_0, strings.MsgBox_ConfigDelete_Title, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                         {
                             if (MessageBox.Show(taskbar, strings.MsgBox_Troll_0, strings.MsgBox_ConfigDelete_Title, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                             {
                                 if (MessageBox.Show(taskbar, strings.MsgBox_Troll_0, strings.MsgBox_ConfigDelete_Title, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                                 {
                                     if (MessageBox.Show(taskbar, strings.MsgBox_Troll_0, strings.MsgBox_ConfigDelete_Title, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                                     {
                                         MessageBox.Show(taskbar, strings.MsgBox_Troll_DontFeelLike, strings.MsgBox_Error_Title, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
示例#32
0
        public static void Clip(Processor processor)
        {
            Control.CheckForIllegalCrossThreadCalls = false;

            var clipForm = new Form
            {
                FormBorderStyle = FormBorderStyle.None,
                BackColor = Color.Black,
                Opacity = 0.25,
                ShowInTaskbar = false,
                TopMost = true
            };

            Label sizeLabel;
            clipForm.Controls.Add(sizeLabel = new Label
            {
                AutoSize = false,
                Size = new Size(90, 13),
                Left = clipForm.Width - 75,
                Top = clipForm.Height - 55,
                Anchor = (AnchorStyles.Bottom | AnchorStyles.Right),
                ForeColor = Color.White
            });

            List<Form> forms = new List<Form>();
            foreach (Screen screen in Screen.AllScreens)
            {
                var screenForm = new Form
                {
                    Bounds = screen.Bounds,
                    StartPosition = FormStartPosition.Manual,
                    WindowState = FormWindowState.Maximized,
                    FormBorderStyle = FormBorderStyle.None,
                    Opacity = 0.01,
                    Cursor = Cursors.Cross,
                    ShowInTaskbar = false,
                    TopMost = true
                };
                PictureBox screenImage;
                screenForm.Controls.Add(screenImage = new PictureBox
                {
                    Dock = DockStyle.Fill,
                    Image = GetScreenshot(screen),
                });
                screenForm.Show();
                screenForm.Focus();
                forms.Add(screenForm);

                new Thread(() =>
                {
                    Thread.Sleep(50);
                    screenForm.Opacity = 1.0;
                }).Start();

                screenImage.MouseDown += (s, e) =>
                {
                    var cursorColor = GetColor(screenImage, e.Location);
                    clipForm.BackColor = cursorColor.ToArgb() > Color.Black.ToArgb() / 2 ? Color.Black : Color.White;
                    sizeLabel.ForeColor = cursorColor.ToArgb() > Color.Black.ToArgb() / 2 ? Color.White : Color.Black;
                };

                screenImage.MouseDown += (s, e) =>
                {
                    if (e.Button == MouseButtons.Left)
                    {
                        _selectingArea = true;
                        _startPoint = screenImage.PointToScreen(e.Location);
                        clipForm.Location = _startPoint;
                        clipForm.Size = new Size(1, 1);
                        clipForm.Show();
                    }
                };

                screenImage.MouseMove += (s, e) =>
                {
                    if (_selectingArea)
                    {
                        var newPoint = screenImage.PointToScreen(e.Location);
                        var point = new Point(Math.Min(newPoint.X, _startPoint.X), Math.Min(newPoint.Y, _startPoint.Y));
                        var size = new Size(Math.Max(newPoint.X, _startPoint.X) - point.X, Math.Max(newPoint.Y, _startPoint.Y) - point.Y);
                        if (clipForm.Location != point) clipForm.Location = point;
                        clipForm.Size = size;
                        sizeLabel.Text = size.Width + " x " + size.Height;
                    }
                };

                screenImage.MouseUp += (s, e) =>
                {
                    _selectingArea = false;
                    clipForm.Close();

                    forms.ForEach(f => f.Visible = false); // uncomment for debug

                    Bitmap bitmap;
                    if (screen.Bounds.Contains(clipForm.Bounds))
                        bitmap = GetClip(screenImage.Image, new Rectangle(screenForm.PointToClient(clipForm.Location), clipForm.Size));
                    else bitmap = Collage(forms, clipForm.Location, clipForm.Size);

                    forms.ForEach(f => f.Close());

                    if (bitmap.Size.Width < 15 || bitmap.Size.Height < 15) Terminate(); //too small to see
                    processor.Process(bitmap);
                };

                clipForm.KeyDown += (s, e) => Escape(e);
                screenForm.KeyDown += (s, e) => Escape(e);
                screenImage.KeyDown += (s, e) => Escape(e);
            }
        }
示例#33
0
        public static DialogResult Show(string text, string caption, Font textFont)
        {
            var form = new Form();

            form.FormBorderStyle = FormBorderStyle.FixedSingle;
            form.MaximizeBox     = false;
            form.MinimumSize     = new Size(154, 140);
            form.Size            = form.MinimumSize;
            form.SizeGripStyle   = SizeGripStyle.Hide;
            form.StartPosition   = FormStartPosition.CenterScreen;
            form.Text            = caption;
            form.TopMost         = true;

            var panel = new Panel();

            panel.Anchor    = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
            panel.BackColor = Color.White;
            panel.Location  = new Point(0, 24);
            panel.Size      = new Size(form.Width, form.Height - 24 - 48);

            var label = new Label();

            label.Anchor       = AnchorStyles.Left | AnchorStyles.Top;
            label.Font         = textFont;
            label.Location     = new Point(0, 24);
            label.Padding      = new Padding(12, 24, 12, 24);
            label.Text         = text;
            label.SizeChanged += (sender, args) =>
            {
                var newSize = new Size(label.Width, label.Height + 24 + 48);
                if (newSize.Width > form.MinimumSize.Width)
                {
                    form.Width = newSize.Width;
                }
                if (newSize.Height > form.MinimumSize.Height)
                {
                    form.Height = newSize.Height;
                }
            };

            form.Controls.Add(panel);
            form.Controls.Add(label);

            var buttonOk = new Button();

            buttonOk.Anchor   = AnchorStyles.Right | AnchorStyles.Bottom;
            buttonOk.TabIndex = 0;
            buttonOk.Text     = "Ok";
            buttonOk.Size     = new Size(86, 24);
            buttonOk.Location = new Point(form.Width - 8 - buttonOk.Width, form.Height - buttonOk.Height - 12);
            buttonOk.Click   += (sender, args) => form.Close();

            form.AcceptButton = buttonOk;
            form.Controls.Add(buttonOk);
            form.ShowDialog();
            form.Focus(); // Disable button focus to prevent invoking Click event from the OnKeyDown event.

            Last = form;

            return(DialogResult.OK);
        }
示例#34
0
        /// <summary>
        /// Returns a SharePoint on-premises / SharePoint Online ClientContext object. Requires claims based authentication with FedAuth cookie.
        /// </summary>
        /// <param name="siteUrl">Site for which the ClientContext object will be instantiated</param>
        /// <param name="icon">Optional icon to use for the popup form</param>
        /// <returns>ClientContext to be used by CSOM code</returns>
        public ClientContext GetWebLoginClientContext(string siteUrl, System.Drawing.Icon icon = null)
        {
            var authCookiesContainer = new CookieContainer();
            var siteUri = new Uri(siteUrl);

            var thread = new Thread(() =>
            {
                var form = new System.Windows.Forms.Form();
                if (icon != null)
                {
                    form.Icon = icon;
                }
                var browser = new System.Windows.Forms.WebBrowser
                {
                    ScriptErrorsSuppressed = true,
                    Dock = DockStyle.Fill
                };

                form.SuspendLayout();
                form.Width  = 900;
                form.Height = 500;
                form.Text   = $"Log in to {siteUrl}";
                form.Controls.Add(browser);
                form.ResumeLayout(false);

                browser.Navigate(siteUri);

                browser.Navigated += (sender, args) =>
                {
                    if (siteUri.Host.Equals(args.Url.Host))
                    {
                        var cookieString = CookieReader.GetCookie(siteUrl).Replace("; ", ",").Replace(";", ",");

                        // Get FedAuth and rtFa cookies issued by ADFS when accessing claims aware applications.
                        // - or get the EdgeAccessCookie issued by the Web Application Proxy (WAP) when accessing non-claims aware applications (Kerberos).
                        IEnumerable <string> authCookies = null;
                        if (Regex.IsMatch(cookieString, "FedAuth", RegexOptions.IgnoreCase))
                        {
                            authCookies = cookieString.Split(',').Where(c => c.StartsWith("FedAuth", StringComparison.InvariantCultureIgnoreCase) || c.StartsWith("rtFa", StringComparison.InvariantCultureIgnoreCase));
                        }
                        else if (Regex.IsMatch(cookieString, "EdgeAccessCookie", RegexOptions.IgnoreCase))
                        {
                            authCookies = cookieString.Split(',').Where(c => c.StartsWith("EdgeAccessCookie", StringComparison.InvariantCultureIgnoreCase));
                        }
                        if (authCookies != null)
                        {
                            authCookiesContainer.SetCookies(siteUri, string.Join(",", authCookies));
                            form.Close();
                        }
                    }
                };

                form.Focus();
                form.ShowDialog();
                browser.Dispose();
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();

            if (authCookiesContainer.Count > 0)
            {
                var ctx = new ClientContext(siteUrl);
                ctx.ExecutingWebRequest += (sender, e) => e.WebRequestExecutor.WebRequest.CookieContainer = authCookiesContainer;
                return(ctx);
            }

            return(null);
        }
示例#35
0
        public void addShellTab()
        {
            //EduardoOliveiraAndColinVerhey.MDITabControl code
            Form foobar = new Form();
            //foobar.Location.X = 5;
            //foobar.Location.Y = 502;
            tabControl1.TabPages.Add(foobar);
            //tabControl2.TabPages.Add(foobar);
            WebBrowser browser1 = new WebBrowser();
            foobar.Controls.Add(browser1);
            browser1.Dock = DockStyle.Fill;
            browser1.Navigated += new
            WebBrowserNavigatedEventHandler(navIE);
            browser1.NewWindow += new CancelEventHandler(browser1_NewWindow);
            browser1.StatusTextChanged += new EventHandler(changingS);
            browser1.DocumentTitleChanged += new EventHandler(browser1_DocumentTitleChanged);
            browser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(browser1_DocumentCompleted);
            browser1.BackColor = System.Drawing.Color.White;
            browser1.GotFocus += new EventHandler(selectS);
            browser1.ScriptErrorsSuppressed = true;
            browser1.ContextMenuStrip = browserCM;
            //browser1.Navigate("about:blank");
            foobar.GotFocus += new
            EventHandler(selectS);
            foobar.Disposed +=
                new EventHandler(dd);

            //browser1.AllowDnsPrefetch = false;
            //browser1.BlockPopups = true;
            textBox1.Text = "about:blank";
            foobar.Tag = "A";
            foobar.Text = "IE Shell/IE壳";
            foobar.Focus();
            rtab();
            swb.Navigate("http://www.pisoft.tk/ieshell.php");
        }
示例#36
0
 private void button2_Click(object sender, EventArgs e)
 {
     try
     {
         lavaMapBrowser.Show();
         lavaMapBrowser.Focus();
     }
     catch (ObjectDisposedException)
     {
         lavaMapBrowser = new LavaMapBrowser();
         lavaMapBrowser.Show();
         lavaMapBrowser.Focus();
     }
     catch (Exception ex) { Server.ErrorLog(ex); }
 }
        /// <summary>
        /// Returns a SharePoint on-premises / SharePoint Online ClientContext object. Requires claims based authentication with FedAuth cookie.
        /// </summary>
        /// <param name="siteUrl">Site for which the ClientContext object will be instantiated</param>
        /// <param name="icon">Optional icon to use for the popup form</param>
        /// <returns>ClientContext to be used by CSOM code</returns>
        public ClientContext GetWebLoginClientContext(string siteUrl, System.Drawing.Icon icon = null)
        {
            var cookies = new CookieContainer();
            var siteUri = new Uri(siteUrl);

            var thread = new Thread(() =>
            {
                var form = new System.Windows.Forms.Form();
                if (icon != null)
                {
                    form.Icon = icon;
                }
                var browser = new System.Windows.Forms.WebBrowser
                {
                    ScriptErrorsSuppressed = true,
                    Dock = DockStyle.Fill
                };


                form.SuspendLayout();
                form.Width = 900;
                form.Height = 500;
                form.Text = string.Format("Log in to {0}", siteUrl);
                form.Controls.Add(browser);
                form.ResumeLayout(false);

                browser.Navigate(siteUri);

                browser.Navigated += (sender, args) =>
                {
                    if (siteUri.Host.Equals(args.Url.Host))
                    {
                        var cookieString = CookieReader.GetCookie(siteUrl).Replace("; ", ",").Replace(";", ",");
                        if (Regex.IsMatch(cookieString, "FedAuth", RegexOptions.IgnoreCase))
                        {
                            var _cookies = cookieString.Split(',').Where(c => c.StartsWith("FedAuth", StringComparison.InvariantCultureIgnoreCase) || c.StartsWith("rtFa", StringComparison.InvariantCultureIgnoreCase));
                            cookies.SetCookies(siteUri, string.Join(",", _cookies));
                            form.Close();
                        }
                    }
                };

                form.Focus();
                form.ShowDialog();
                browser.Dispose();
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();

            if (cookies.Count > 0)
            {
                var ctx = new ClientContext(siteUrl);
                ctx.ExecutingWebRequest += (sender, e) => e.WebRequestExecutor.WebRequest.CookieContainer = cookies;
                return ctx;

            }

            return null;
        }