示例#1
0
        private void propertiesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var settingsForm = new SendCommandToolPropertiesForm()
            {
                HostHwnd     = this.m_HostWindowHwnd,
                ToolWidht    = this.Size.Width,
                ToolHeight   = this.Size.Height,
                AnchorH      = m_AnchorH,
                AnchorV      = m_AnchorV,
                Commands     = m_Commands,
                CommandType  = m_SendCommandType,
                Sleep        = m_Sleep,
                SleepTimeout = m_SleepTimeout,
                RunOnAllWindowsWithSameTitle = m_RunOnAllWindowsWithSameTitle,
                ToolLeft         = this.Location.X,
                ToolTop          = this.Location.Y,
                BorderColor      = this.m_PenNormal.Color,
                BorderHoverColor = this.m_PenHover.Color,
                TitlePattern     = this.m_TitlePattern,
                ActivateOnHover  = this.ActivateOnHover
            };

            var result = settingsForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                this.m_HostWindowHwnd = settingsForm.HostHwnd;
                this.Size             = new Size(settingsForm.ToolWidht, settingsForm.ToolHeight);
                this.m_AnchorH        = settingsForm.AnchorH;
                this.m_AnchorV        = settingsForm.AnchorV;
                this.m_DrawRectangle  = new Rectangle(0, 0, this.Size.Width - 1, this.Size.Height - 1);

                this.m_Commands        = settingsForm.Commands;
                this.m_SendCommandType = settingsForm.CommandType;

                if (this.m_SendCommandType == SendCommandType.ActivateWindow)
                {
                    int handle;
                    if (int.TryParse(m_Commands, out handle))
                    {
                        if (User32Windows.IsWindow((IntPtr)handle))
                        {
                            if (this.BackgroundImagePath != string.Empty)
                            {
                                var q = MessageBox.Show("The tool already has an background icon,\novervrite?", "Background icon",
                                                        MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                                if (q == DialogResult.No)
                                {
                                    return;
                                }
                            }

                            var icon = User32Windows.GetIcon((IntPtr)handle);

                            if (icon != null)
                            {
                                this.BackgroundImage = icon.ToBitmap();
                            }
                        }
                    }
                }

                this.m_Sleep        = settingsForm.Sleep;
                this.m_SleepTimeout = settingsForm.SleepTimeout;
                this.m_RunOnAllWindowsWithSameTitle = settingsForm.RunOnAllWindowsWithSameTitle;
                this.m_TitlePattern = settingsForm.TitlePattern;

                this.Location = new Point(settingsForm.ToolLeft, settingsForm.ToolTop);

                this.m_PenNormal.Color = settingsForm.BorderColor;
                this.m_PenHover.Color  = settingsForm.BorderHoverColor;

                if (m_TitlePattern != String.Empty)
                {
                    m_TitleRegex = new Regex(m_TitlePattern);
                }
                else
                {
                    m_TitleRegex = null;
                }

                this.ActivateOnHover = settingsForm.ActivateOnHover;
            }
        }
示例#2
0
            public static void SetAnchor(RectTransform rectTransform, AnchorHorizontal anchorH, AnchorVertical anchorV, float customMinX = 0, float customMinY = 0, float customMaxX = 0, float customMaxY = 0)
            {
                float minX = 0;
                float minY = 0;
                float maxX = 0;
                float maxY = 0;

                switch (anchorH)
                {
                case AnchorHorizontal.Left:

                    minX = 0;
                    maxX = 0;

                    break;

                case AnchorHorizontal.Center:

                    minX = 0.5f;
                    maxX = 0.5f;

                    break;

                case AnchorHorizontal.Right:

                    minX = 1;
                    maxX = 1;

                    break;


                case AnchorHorizontal.Stretched:

                    minX = 0;
                    maxX = 1;

                    break;

                case AnchorHorizontal.Custom:

                    minX = customMinX;
                    maxX = customMaxX;

                    break;
                }


                switch (anchorV)
                {
                case AnchorVertical.Bottom:

                    minY = 0;
                    maxY = 0;

                    break;

                case AnchorVertical.Center:

                    minY = 0.5f;
                    maxY = 0.5f;

                    break;

                case AnchorVertical.Top:

                    minY = 1;
                    maxY = 1;

                    break;


                case AnchorVertical.Stretched:

                    minY = 0;
                    maxY = 1;

                    break;


                case AnchorVertical.Custom:

                    minY = customMinY;
                    maxY = customMaxY;

                    break;
                }

                rectTransform.anchorMin = new Vector2(minX, minY);
                rectTransform.anchorMax = new Vector2(maxX, maxY);
            }