コード例 #1
0
ファイル: DatePicker.cs プロジェクト: wyh0395/iFactr-NETCF
        public override void ShowPicker()
        {
            base.ShowPicker();
            int x      = Width - (int)(10 * CompactFactory.Instance.DpiScale);
            int y      = Height / 2;
            int lParam = x + y * 0x00010000;

            CoreDll.SendMessage(Handle, 0x00000201, (IntPtr)1, (IntPtr)lParam);
        }
コード例 #2
0
        public void Paint(Graphics g)
        {
            if (Visibility != Visibility.Visible || string.IsNullOrEmpty(Text))
            {
                return;
            }

            IntPtr hdcTemp     = IntPtr.Zero;
            IntPtr oldFont     = IntPtr.Zero;
            IntPtr currentFont = IntPtr.Zero;

            try
            {
                hdcTemp = g.GetHdc();
                if (hdcTemp != IntPtr.Zero)
                {
                    currentFont = Font.ToFont().ToHfont();
                    oldFont     = CoreDll.SelectObject(hdcTemp, currentFont);

                    var rect = new Rect
                    {
                        Left   = (int)Location.X,
                        Top    = (int)Location.Y,
                        Right  = (int)(Location.X + Size.Width),
                        Bottom = (int)(Location.Y + Size.Height),
                    };
                    var color = (Highlight ? HighlightColor : ForegroundColor).ToColor();
                    CoreDll.SetTextColor(hdcTemp, color.R | (color.G << 8) | (color.B << 16));
                    CoreDll.SetBkMode(hdcTemp, 1);
                    var flags = CoreDll.DT_END_ELLIPSIS | CoreDll.DT_NOPREFIX;
                    if (Lines != 1)
                    {
                        flags += CoreDll.DT_WORDBREAK;
                    }
                    CoreDll.DrawText(hdcTemp, Text, Text.Length, ref rect, flags);
                }
            }
            finally
            {
                if (oldFont != IntPtr.Zero)
                {
                    CoreDll.SelectObject(hdcTemp, oldFont);
                }

                if (hdcTemp != IntPtr.Zero)
                {
                    g.ReleaseHdc(hdcTemp);
                }

                if (currentFont != IntPtr.Zero)
                {
                    CoreDll.DeleteObject(currentFont);
                }
            }
        }
コード例 #3
0
ファイル: ButtonControl.cs プロジェクト: wyh0395/iFactr-NETCF
        public void FitText()
        {
            if (!_hasMeasured)
            {
                return;
            }
            const string ellipsisChars = "... ";
            var          constraints   = Size.ToSize();
            Size         s             = CoreDll.MeasureString(" " + _title + " ", Font.ToFont(), constraints, false, true) + _margins;

            // control is large enough to display the whole text
            if (s.Width <= Width)
            {
                return;
            }

            int    len = 0;
            int    seg = _title.Length;
            string fit = string.Empty;

            // find the longest string that fits into the control boundaries using bisection method
            while (seg > 1)
            {
                seg -= seg / 2;

                int left  = len + seg;
                int right = _title.Length;

                if (left > right)
                {
                    continue;
                }

                // build and measure a candidate string with ellipsis
                string tst = " " + _title.Substring(0, left).TrimEnd() + ellipsisChars;

                s = CoreDll.MeasureString(tst, Font.ToFont(), constraints, false, true) + _margins;

                // candidate string fits into control boundaries,
                // try a longer string
                // stop when seg <= 1
                if (s.Width <= Width)
                {
                    len += seg;
                    fit  = tst;
                }
            }

            base.Text = len == 0 ? ellipsisChars : fit;
        }
コード例 #4
0
        public static void Initialize()
        {
            Device.Initialize(new CompactDevice());
            Initialize(new RootForm());

            IntPtr    HWND_BROADCAST = (IntPtr)0xFFFF;
            const int WM_Fontchange  = 0x001D;
            IntPtr    thir           = (IntPtr)0;
            IntPtr    fourth         = (IntPtr)0;
            var       fontName       = Font.PreferredLabelFont.Name + ".ttf";
            var       fontPath       = "\\Windows\\Fonts\\".AppendPath(fontName);

            if (!Device.File.Exists(fontPath))
            {
                var fontStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("iFactr.Compact.Resources." + fontName);
                if (fontStream != null)
                {
                    Device.File.Save(fontPath, fontStream);
                }
            }

            if (Device.File.Exists(fontPath))
            {
                CoreDll.AddFontResource(fontPath);
                CoreDll.SendMessage(HWND_BROADCAST, WM_Fontchange, thir, fourth);
            }
            CoreDll.SystemParametersInfo(CoreDll.SPI_SETFONTSMOOTHING, -1, IntPtr.Zero, 0);

            var context = new iApp.AppNavigationContext {
                ActivePane = Pane.Master
            };

            PaneManager.Instance.AddStack(new HistoryStack {
                Context = context
            }, context);
            context = new iApp.AppNavigationContext {
                ActivePane = Pane.Popover
            };
            PaneManager.Instance.AddStack(new HistoryStack {
                Context = context
            }, context);
        }
コード例 #5
0
ファイル: PickerBase.cs プロジェクト: wyh0395/iFactr-NETCF
        public Size Measure(Size constraints)
        {
            var s = CoreDll.MeasureString(Text, Font.ToFont(), constraints, false, true);

            return(new Size(constraints.Width, s.Height));
        }
コード例 #6
0
ファイル: ButtonControl.cs プロジェクト: wyh0395/iFactr-NETCF
        public Size Measure(Size constraints)
        {
            var measure = CoreDll.MeasureString(" " + _title + " ", Font.ToFont(), constraints, false, true) + _margins;

            return(new Size(measure.Width, Math.Max(measure.Height, 33 * CompactFactory.Instance.DpiScale)));
        }
コード例 #7
0
 protected override double GetLineHeight(Font font)
 {
     return(CoreDll.MeasureString("Wq", font.ToFont(), new Size(1000, 1000), false, true).Height);
 }
コード例 #8
0
 public Size Measure(Size constraints)
 {
     return(CoreDll.MeasureString(Text, Font.ToFont(), constraints, Lines != 1, false));
 }