Esempio n. 1
0
        private void btnSetting_Click(object sender, EventArgs e)
        {
            switch (cmbFormStartState.SelectedIndex)
            {
            case 1:
            {
                PointX     = Convert.ToInt32(Screen.PrimaryScreen.Bounds.Width * 0.1);
                PointY     = Convert.ToInt32(Screen.PrimaryScreen.Bounds.Height * 0.1);
                SizeWidth  = Convert.ToInt32(Screen.PrimaryScreen.Bounds.Width * 0.8);
                SizeHeight = Convert.ToInt32(Screen.PrimaryScreen.Bounds.Height * 0.8);
            }
            break;

            case 2:
            {
                SizeWidth  = (int)numWidth.Value;
                SizeHeight = (int)numHeight.Value;
                PointX     = 0;
                PointY     = 0;
            }
            break;
            }

            WritePrivateProfileString("Location", "X", PointX.ToString(), Application.StartupPath + @"\configure.ini");
            WritePrivateProfileString("Location", "Y", PointY.ToString(), Application.StartupPath + @"\configure.ini");
            WritePrivateProfileString("Size", "Width", SizeWidth.ToString(), Application.StartupPath + @"\configure.ini");
            WritePrivateProfileString("Size", "Height", SizeHeight.ToString(), Application.StartupPath + @"\configure.ini");
            WritePrivateProfileString("Form", "Screen", "None", Application.StartupPath + @"\configure.ini");
            WritePrivateProfileString("Form", "BackColor", ColorTranslator.ToHtml(pnlColor.BackColor), Application.StartupPath + @"\configure.ini");
            WritePrivateProfileString("Form", "StartState", cmbFormStartState.SelectedIndex.ToString(), Application.StartupPath + @"\configure.ini");
            WritePrivateProfileString("Form", "ShowInTaskbar", chkShowInTaskbar.Checked.ToString(), Application.StartupPath + @"\configure.ini");

            RegisterFileType(".jpg", "Feep JPG File", Application.StartupPath + @"\Icon\JPG.ico", Application.StartupPath + @"\Feep.exe", cbJPG.Checked);
            RegisterFileType(".bmp", "Feep BMP File", Application.StartupPath + @"\Icon\BMP.ico", Application.StartupPath + @"\Feep.exe", cbBMP.Checked);
            RegisterFileType(".png", "Feep PNG File", Application.StartupPath + @"\Icon\PNG.ico", Application.StartupPath + @"\Feep.exe", cbPNG.Checked);
            RegisterFileType(".gif", "Feep GIF File", Application.StartupPath + @"\Icon\GIF.ico", Application.StartupPath + @"\Feep.exe", cbGIF.Checked);
            RegisterFileType(".tif", "Feep TIF File", Application.StartupPath + @"\Icon\TIF.ico", Application.StartupPath + @"\Feep.exe", cbTIF.Checked);

            MessageBox.Show("设置成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Esempio n. 2
0
        // Calculate menu's position based on Anchor and parent's positions.
        // If there is not enought space, then menu's size can be also resized.
        private void CalculateMenuPosition()
        {
            if ((Anchor == null) || (Content == null))
            {
                return;
            }

            if (Items == null)
            {
                return;
            }

            if (SizeWidth.Equals(0) && SizeHeight.Equals(0))
            {
                return;
            }

            float menuScreenPosX = 0;
            float menuScreenPosY = 0;

            if (HorizontalPositionToAnchor == RelativePosition.Start)
            {
                if (GetRootView().LayoutDirection == ViewLayoutDirectionType.LTR)
                {
                    menuScreenPosX = Anchor.ScreenPosition.X - SizeWidth;
                }
                else
                {
                    menuScreenPosX = Anchor.ScreenPosition.X + Anchor.Margin.Start + Anchor.SizeWidth + Anchor.Margin.End;
                }
            }
            else if (HorizontalPositionToAnchor == RelativePosition.Center)
            {
                menuScreenPosX = Anchor.ScreenPosition.X + Anchor.Margin.Start + (Anchor.SizeWidth / 2) - (SizeWidth / 2);
            }
            else
            {
                if (GetRootView().LayoutDirection == ViewLayoutDirectionType.LTR)
                {
                    menuScreenPosX = Anchor.ScreenPosition.X + Anchor.Margin.Start + Anchor.SizeWidth + Anchor.Margin.End;
                }
                else
                {
                    menuScreenPosX = Anchor.ScreenPosition.X - SizeWidth;
                }
            }

            if (VerticalPositionToAnchor == RelativePosition.Start)
            {
                menuScreenPosY = Anchor.ScreenPosition.Y - SizeHeight;
            }
            else if (VerticalPositionToAnchor == RelativePosition.Center)
            {
                menuScreenPosY = Anchor.ScreenPosition.Y + Anchor.Margin.Top + (Anchor.SizeHeight / 2) - (SizeHeight / 2);
            }
            else
            {
                menuScreenPosY = Anchor.ScreenPosition.Y + Anchor.Margin.Top + Anchor.SizeHeight + Anchor.Margin.Bottom;
            }

            float menuSizeW = SizeWidth;
            float menuSizeH = SizeHeight;

            // Check if menu is not inside parent's boundary in x coordinate system.
            if (menuScreenPosX + SizeWidth > Window.Size.Width)
            {
                if (HorizontalPositionToAnchor == RelativePosition.Center)
                {
                    menuScreenPosX = Window.Size.Width - SizeWidth;
                }
                else
                {
                    menuSizeW = Window.Size.Width - menuScreenPosX;
                }
            }
            if (menuScreenPosX < 0)
            {
                menuScreenPosX = 0;
                menuSizeW      = Window.Size.Width;
            }

            // Check if menu is not inside parent's boundary in y coordinate system.
            if (menuScreenPosY + SizeHeight > Window.Size.Height)
            {
                if (VerticalPositionToAnchor == RelativePosition.Center)
                {
                    menuScreenPosY = Window.Size.Height - SizeHeight;
                }
                else
                {
                    menuSizeH = Window.Size.Height - menuScreenPosY;
                }
            }
            if (menuScreenPosY < 0)
            {
                menuScreenPosY = 0;
                menuSizeH      = Window.Size.Height;
            }

            // Position is relative to parent's coordinate system.
            var menuPosX = menuScreenPosX;
            var menuPosY = menuScreenPosY;

            if (!PositionX.Equals(menuPosX) || !PositionY.Equals(menuPosY) || !SizeWidth.Equals(menuSizeW) || !SizeHeight.Equals(menuSizeH))
            {
                Position = new Position(menuPosX, menuPosY);
                Size     = new Size(menuSizeW, menuSizeH);
            }
        }