Ejemplo n.º 1
0
        private void SaveSettings()
        {
            RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey("Software", true);

            if (softwareKey == null)
            {
                return;
            }

            RegistryKey wroxKey = softwareKey.CreateSubKey("WroxPress");

            if (wroxKey == null)
            {
                return;
            }

            RegistryKey selfPlacingWindowKey = wroxKey.CreateSubKey("SelfPlacingWindow");

            if (selfPlacingWindowKey == null)
            {
                return;
            }

            selfPlacingWindowKey.SetValue("BackColor", BackColor.ToKnownColor());
            selfPlacingWindowKey.SetValue("Red", (int)BackColor.R);
            selfPlacingWindowKey.SetValue("Green", (int)BackColor.G);
            selfPlacingWindowKey.SetValue("Blue", (int)BackColor.B);
            selfPlacingWindowKey.SetValue("Width", Width);
            selfPlacingWindowKey.SetValue("Height", Height);
            selfPlacingWindowKey.SetValue("X", DesktopLocation.X);
            selfPlacingWindowKey.SetValue("Y", DesktopLocation.Y);
            selfPlacingWindowKey.SetValue("WindowState", WindowState.ToString());
        }
Ejemplo n.º 2
0
        private void SaveSettings()
        {
            var storageFile   = IsolatedStorageFile.GetUserStoreForDomain();
            var storageStream = new IsolatedStorageFileStream(SelfplacingwindowXml, FileMode.Create, FileAccess.Write);
            var writer        = new XmlTextWriter(storageStream, Encoding.UTF8)
            {
                Formatting = Formatting.Indented
            };

            writer.WriteStartDocument();
            writer.WriteStartElement("Settings");

            {
                writer.WriteStartElement("BackColor");
                writer.WriteValue(BackColor.ToKnownColor().ToString());
                writer.WriteEndElement();

                writer.WriteStartElement("Red");
                writer.WriteValue(BackColor.R);
                writer.WriteEndElement();

                writer.WriteStartElement("Green");
                writer.WriteValue(BackColor.G);
                writer.WriteEndElement();

                writer.WriteStartElement("Blue");
                writer.WriteValue(BackColor.B);
                writer.WriteEndElement();

                writer.WriteStartElement("Width");
                writer.WriteValue(Width);
                writer.WriteEndElement();

                writer.WriteStartElement("Height");
                writer.WriteValue(Height);
                writer.WriteEndElement();

                writer.WriteStartElement("X");
                writer.WriteValue(DesktopLocation.X);
                writer.WriteEndElement();

                writer.WriteStartElement("Y");
                writer.WriteValue(DesktopLocation.Y);
                writer.WriteEndElement();

                writer.WriteStartElement("WindowState");
                writer.WriteValue(WindowState.ToString());
                writer.WriteEndElement();
            }

            writer.WriteEndElement();
            writer.Flush();
            writer.Close();
            storageStream.Close();
            storageFile.Close();
        }
Ejemplo n.º 3
0
 private void setComboBoxSelection()
 {
     if (BackColor.IsKnownColor)
     {
         comboBox.SelectedItem = BackColor.ToKnownColor();
     }
     else
     {
         comboBox.SelectedIndex = -1;
     }
 }
Ejemplo n.º 4
0
        private void OnPaintStandard(PaintEventArgs e)
        {
            SolidBrush ctrlBrush = null;

            if (Enabled)
            {
                if (ReadOnly)
                {
                    if (BackColor.ToKnownColor() == KnownColor.Window)
                    {
                        ctrlBrush = new SolidBrush(Color.FromKnownColor(KnownColor.Control));
                    }
                    else
                    {
                        ctrlBrush = new SolidBrush(BackColor);
                    }
                }
                else
                {
                    ctrlBrush = new SolidBrush(BackColor);
                }
            }
            else
            {
                if (BackColor.ToKnownColor() == KnownColor.Window)
                {
                    ctrlBrush = new SolidBrush(Color.FromKnownColor(KnownColor.Control));
                }
                else
                {
                    ctrlBrush = new SolidBrush(BackColor);
                }
            }

            using ( ctrlBrush )
            {
                e.Graphics.FillRectangle(ctrlBrush, ClientRectangle);
            }

            switch (BorderStyle)
            {
            case BorderStyle.Fixed3D:
                ControlPaint.DrawBorder3D(e.Graphics, ClientRectangle, Border3DStyle.Sunken);
                break;

            case BorderStyle.FixedSingle:
                ControlPaint.DrawBorder(e.Graphics, ClientRectangle,
                                        Color.FromKnownColor(KnownColor.WindowFrame), ButtonBorderStyle.Solid);
                break;
            }
        }
Ejemplo n.º 5
0
        private void OnPaintThemed(PaintEventArgs e)
        {
            NativeMethods.RECT rect = new NativeMethods.RECT();

            rect.left   = ClientRectangle.Left;
            rect.top    = ClientRectangle.Top;
            rect.right  = ClientRectangle.Right;
            rect.bottom = ClientRectangle.Bottom;

            IntPtr hdc = new IntPtr();

            hdc = e.Graphics.GetHdc();

            if (BackColor.ToKnownColor() != KnownColor.Window)
            {
                e.Graphics.ReleaseHdc(hdc);

                using (SolidBrush backgroundBrush = new SolidBrush(BackColor))
                {
                    e.Graphics.FillRectangle(backgroundBrush, ClientRectangle);
                }

                hdc = e.Graphics.GetHdc();

                IntPtr hTheme = NativeMethods.OpenThemeData(Handle, "Edit");

                NativeMethods.DTBGOPTS options = new NativeMethods.DTBGOPTS();
                options.dwSize  = (uint)System.Runtime.InteropServices.Marshal.SizeOf(options);
                options.dwFlags = NativeMethods.DTBG_OMITCONTENT;

                int state = NativeMethods.ETS_NORMAL;

                if (!Enabled)
                {
                    state = NativeMethods.ETS_DISABLED;
                }
                else
                if (ReadOnly)
                {
                    state = NativeMethods.ETS_READONLY;
                }

                NativeMethods.DrawThemeBackgroundEx(hTheme, hdc,
                                                    NativeMethods.EP_EDITTEXT, state, ref rect, ref options);

                if (IntPtr.Zero != hTheme)
                {
                    NativeMethods.CloseThemeData(hTheme);
                }
            }
            else if (Enabled & !ReadOnly)
            {
                IntPtr hTheme = NativeMethods.OpenThemeData(Handle, "Edit");

                NativeMethods.DrawThemeBackground(hTheme, hdc, NativeMethods.EP_EDITTEXT,
                                                  NativeMethods.ETS_NORMAL, ref rect, IntPtr.Zero);

                if (IntPtr.Zero != hTheme)
                {
                    NativeMethods.CloseThemeData(hTheme);
                }
            }
            else
            {
                IntPtr hTheme = NativeMethods.OpenThemeData(Handle, "Globals");

                IntPtr hBrush = NativeMethods.GetThemeSysColorBrush(hTheme, 15);

                NativeMethods.FillRect(hdc, ref rect, hBrush);

                if (IntPtr.Zero != hBrush)
                {
                    NativeMethods.DeleteObject(hBrush);
                    hBrush = IntPtr.Zero;
                }

                if (IntPtr.Zero != hTheme)
                {
                    NativeMethods.CloseThemeData(hTheme);
                    hTheme = IntPtr.Zero;
                }

                hTheme = NativeMethods.OpenThemeData(Handle, "Edit");

                NativeMethods.DTBGOPTS options = new NativeMethods.DTBGOPTS();
                options.dwSize  = (uint)System.Runtime.InteropServices.Marshal.SizeOf(options);
                options.dwFlags = NativeMethods.DTBG_OMITCONTENT;

                NativeMethods.DrawThemeBackgroundEx(hTheme, hdc,
                                                    NativeMethods.EP_EDITTEXT, NativeMethods.ETS_DISABLED, ref rect, ref options);

                if (IntPtr.Zero != hTheme)
                {
                    NativeMethods.CloseThemeData(hTheme);
                }
            }

            e.Graphics.ReleaseHdc(hdc);
        }
Ejemplo n.º 6
0
        protected void OnPaintThemed(PaintEventArgs e)
        {
            NativeMethods.RECT rect = new NativeMethods.RECT();

            rect.left   = ClientRectangle.Left;
            rect.top    = ClientRectangle.Top;
            rect.right  = ClientRectangle.Right;
            rect.bottom = ClientRectangle.Bottom;

            IntPtr hdc = new IntPtr();

            hdc = e.Graphics.GetHdc();

            if (BackColor.ToKnownColor() != KnownColor.Window)
            {
                e.Graphics.ReleaseHdc(hdc);

                using (SolidBrush backgroundBrush = new SolidBrush(BackColor))
                {
                    e.Graphics.FillRectangle(backgroundBrush, ClientRectangle);
                }

                hdc = e.Graphics.GetHdc();
            }
            else
            if (Enabled & !ReadOnly)
            {
                IntPtr hTheme = NativeMethods.OpenThemeData(Handle, "Edit");

                NativeMethods.DTBGOPTS options = new NativeMethods.DTBGOPTS();
                options.dwSize  = (uint)System.Runtime.InteropServices.Marshal.SizeOf(options);
                options.dwFlags = NativeMethods.DTBG_OMITBORDER;

                NativeMethods.DrawThemeBackgroundEx(hTheme, hdc,
                                                    NativeMethods.EP_EDITTEXT, NativeMethods.ETS_NORMAL, ref rect, ref options);

                if (IntPtr.Zero != hTheme)
                {
                    NativeMethods.CloseThemeData(hTheme);
                }
            }
            else
            {
                IntPtr hTheme = NativeMethods.OpenThemeData(Handle, "Globals");

                IntPtr hBrush = NativeMethods.GetThemeSysColorBrush(hTheme, 15);

                NativeMethods.FillRect(hdc, ref rect, hBrush);

                if (IntPtr.Zero != hBrush)
                {
                    NativeMethods.DeleteObject(hBrush);
                    hBrush = IntPtr.Zero;
                }

                if (IntPtr.Zero != hTheme)
                {
                    NativeMethods.CloseThemeData(hTheme);
                    hTheme = IntPtr.Zero;
                }
            }

            e.Graphics.ReleaseHdc(hdc);

            uint colorref = 0;

            if (Enabled)
            {
                if (ForeColor.ToKnownColor() != KnownColor.WindowText)
                {
                    colorref = NativeMethods.RGB(ForeColor.R, ForeColor.G, ForeColor.B);
                }
                else
                {
                    IntPtr hTheme = NativeMethods.OpenThemeData(Handle, "Globals");
                    colorref = NativeMethods.GetThemeSysColor(hTheme, 6);
                    if (IntPtr.Zero != hTheme)
                    {
                        NativeMethods.CloseThemeData(hTheme);
                        hTheme = IntPtr.Zero;
                    }
                }
            }
            else
            {
                IntPtr hTheme = NativeMethods.OpenThemeData(Handle, "Globals");
                colorref = NativeMethods.GetThemeSysColor(hTheme, 16);
                if (IntPtr.Zero != hTheme)
                {
                    NativeMethods.CloseThemeData(hTheme);
                    hTheme = IntPtr.Zero;
                }
            }

            int r = NativeMethods.GetRValue(colorref);
            int g = NativeMethods.GetGValue(colorref);
            int b = NativeMethods.GetBValue(colorref);

            StringFormat stringFormat = new StringFormat();

            stringFormat.Alignment = StringAlignment.Center;

            using (SolidBrush textBrush = new SolidBrush(Color.FromArgb(r, g, b)))
            {
                e.Graphics.DrawString(Text, Font, textBrush, ClientRectangle, stringFormat);
            }
        }
Ejemplo n.º 7
0
        protected void OnPaintStandard(PaintEventArgs e)
        {
            SolidBrush ctrlBrush = null;
            SolidBrush textBrush = null;

            if (Enabled)
            {
                if (ReadOnly)
                {
                    if (BackColor.ToKnownColor() == KnownColor.Window)
                    {
                        ctrlBrush = new SolidBrush(Color.FromKnownColor(KnownColor.Control));
                        textBrush = new SolidBrush(Color.FromKnownColor(KnownColor.WindowText));
                    }
                    else
                    {
                        ctrlBrush = new SolidBrush(BackColor);
                        textBrush = new SolidBrush(ForeColor);
                    }
                }
                else
                {
                    ctrlBrush = new SolidBrush(BackColor);
                    textBrush = new SolidBrush(ForeColor);
                }
            }
            else
            {
                if (BackColor.ToKnownColor() == KnownColor.Window)
                {
                    ctrlBrush = new SolidBrush(Color.FromKnownColor(KnownColor.Control));
                }
                else
                {
                    ctrlBrush = new SolidBrush(BackColor);
                }

                if (ForeColor.ToKnownColor() == KnownColor.Control)
                {
                    textBrush = new SolidBrush(ForeColor);
                }
                else
                {
                    textBrush = new SolidBrush(Color.FromKnownColor(KnownColor.GrayText));
                }
            }

            using ( ctrlBrush )
            {
                e.Graphics.FillRectangle(ctrlBrush, ClientRectangle);
            }

            StringFormat stringFormat = new StringFormat();

            stringFormat.Alignment = StringAlignment.Center;

            using ( textBrush )
            {
                e.Graphics.DrawString(Text, Font, textBrush, ClientRectangle, stringFormat);
            }
        }