示例#1
0
        private string AssignData(Control ctl, string title, Dictionary<string, string> values, Image titleImage, Image customImage)
        {
            titleImage = GetScaledImage(titleImage);
            customImage = GetScaledImage(customImage);

            if (ctl == null)
            {
                ctl = __generic;
            }

            if (_data.ContainsKey(ctl))
            {
                if (string.IsNullOrEmpty(title))
                {
                    _data.Remove(ctl);
                }
                else
                {
                    _data[ctl] = new OPMToolTipData { Values = values, Title = title, TitleImage = titleImage, CustomImage = customImage};
                }
            }
            else if (!string.IsNullOrEmpty(title))
            {
                _data.Add(ctl, new OPMToolTipData { Values = values, Title = title, TitleImage = titleImage, CustomImage = customImage });
            }

            if (_data.ContainsKey(ctl) && _def != null)
            {
                _data[ctl].Size = CalculateSize(ctl, _data[ctl]);

                string fake = string.Empty;
                string row = string.Empty;
                SizeF size = SizeF.Empty;

                // Calculate a string that would generate an equivalent tooltip size
                using (Graphics g = ctl.CreateGraphics())
                {
                    do
                    {
                        row += "Ig";
                        size = g.MeasureString(row, _def);
                    }
                    while (size.Width < _data[ctl].Size.Width);

                    fake = row;

                    size = SizeF.Empty;
                    do
                    {
                        fake += "Ig\n";
                        size = g.MeasureString(fake, _def);
                    }
                    while (size.Height < _data[ctl].Size.Height);
                }

                return fake;
            }
            
            return title;
        }
        private Size CalculateSize(Control c, OPMToolTipData data)
        {
            int x = 0, y = 0;

            if (data != null)
            {
                int titleOffsetX = 5;
                int titleOffsetY = 5;

                using (Graphics g = c.CreateGraphics())
                {
                    SizeF sizeTitle = g.MeasureString(data.Title, _fTitle);

                    if (data.TitleImage != null)
                    {
                        x += 5 + data.TitleImage.Width;
                        y += 5 + data.TitleImage.Height;

                        titleOffsetX += 5 + data.TitleImage.Width;
                        titleOffsetY  = (int)(data.TitleImage.Height / 2 - sizeTitle.Height / 2);

                        y += 5;
                    }
                    else
                    {
                        y += (int)sizeTitle.Height + 10;
                    }

                    if (data.Values != null)
                    {
                        foreach (KeyValuePair <string, string> val in data.Values)
                        {
                            string key        = Translator.Translate(val.Key.Trim());
                            string keyMeasure = string.IsNullOrEmpty(key) ? " " : key;
                            string valMeasure = string.IsNullOrEmpty(val.Value) ? " " : val.Value;

                            SizeF szKey = g.MeasureString(keyMeasure, _fKey);
                            SizeF szVal = g.MeasureString(valMeasure, _fVal);

                            y += (int)szKey.Height + 2;
                            x  = (int)Math.Max(x, szKey.Width + szVal.Width + 10);
                        }
                    }

                    x = (int)Math.Max(x, titleOffsetX + sizeTitle.Width);

                    if (data.CustomImage != null)
                    {
                        y += 5;
                        y += data.CustomImage.Height;
                    }
                }
            }

            x += 10;
            y += 10;

            return(new Size(x, y));
        }
 private void AssignData(string title, Dictionary <string, string> values, Image img)
 {
     data = new OPMToolTipData {
         Values = values, TitleImage = img, Title = title
     };
     base.Size     = CalculateSize(data);
     base.Location = CalculateLocation();
 }
        private Size CalculateSize(OPMToolTipData data)
        {
            int x = 0, y = 0;

            if (data != null)
            {
                int titleOffsetX = 5;
                int titleOffsetY = 5;

                using (Graphics g = CreateGraphics())
                {
                    SizeF sizeTitle = g.MeasureString(data.Title, _fTitle);

                    if (data.TitleImage != null)
                    {
                        x += 5 + data.TitleImage.Width;
                        y += 5 + data.TitleImage.Height;

                        titleOffsetX += 5 + data.TitleImage.Width;
                        titleOffsetY = (int)(data.TitleImage.Height / 2 - sizeTitle.Height / 2);

                        y += 5;
                    }
                    else
                    {
                        y += (int)sizeTitle.Height + 10;
                    }

                    if (data.Values != null)
                    {
                        foreach (KeyValuePair<string, string> val in data.Values)
                        {
                            string key = Translator.Translate(val.Key.Trim());
                            string keyMeasure = string.IsNullOrEmpty(key) ? " " : key;
                            string valMeasure = string.IsNullOrEmpty(val.Value) ? " " : val.Value;

                            SizeF szKey = g.MeasureString(keyMeasure, _fKey);
                            SizeF szVal = g.MeasureString(valMeasure, _fVal);

                            y += (int)szKey.Height + 2;
                            x = (int)Math.Max(x, szKey.Width + szVal.Width + 10);
                        }
                    }

                    x = (int)Math.Max(x, titleOffsetX + sizeTitle.Width);
                }
            }

            x += 10;
            y += 10;

            return new Size(x, y);
        }
 private void AssignData(string title, Dictionary<string, string> values, Image img)
 {
     data = new OPMToolTipData { Values = values, TitleImage = img, Title = title };
     base.Size = CalculateSize(data);
     base.Location = CalculateLocation();
 }
示例#6
0
        private void DrawContents(Graphics g, OPMToolTipData data)
        {
            if (data != null)
            {
                int titleOffsetX = 5;
                int titleOffsetY = 5;
                int textOffsetY = 5;

                SizeF sizeTitle = g.MeasureString(data.Title, _fTitle);

                if (data.TitleImage != null)
                {
                    g.DrawImage(data.TitleImage, 5, 5);

                    titleOffsetX += 5 + data.TitleImage.Width;
                    titleOffsetY = (int)(data.TitleImage.Height / 2 - sizeTitle.Height / 4);

                    textOffsetY += data.TitleImage.Height + 5;
                }
                else
                {
                    textOffsetY += (int)sizeTitle.Height + 5;
                }

                int y = textOffsetY;

                using (Brush b = new SolidBrush(ThemeManager.ForeColor))
                {
                    g.DrawString(data.Title, _fTitle, b, titleOffsetX, titleOffsetY);

                    int x = 5;

                    if (data.Values != null)
                    {
                        foreach (KeyValuePair<string, string> val in data.Values)
                        {
                            string key = Translator.Translate(val.Key.Trim());
                            string keyMeasure = string.IsNullOrEmpty(key) ? " " : key;
                            string valMeasure = string.IsNullOrEmpty(val.Value) ? " " : val.Value;

                            SizeF szKey = g.MeasureString(keyMeasure, _fKey);
                            SizeF szVal = g.MeasureString(valMeasure, _fVal);

                            if (!string.IsNullOrEmpty(val.Key))
                            {
                                g.DrawString(key, _fKey, b, x, y);
                            }

                            if (!string.IsNullOrEmpty(val.Value))
                            {
                                g.DrawString(val.Value, _fVal, b, x + szKey.Width, y);
                            }

                            y += (int)Math.Max(szKey.Height, szVal.Height) + 2;
                        }
                    }
                }
                
                if (data.CustomImage != null)
                {
                    y += 5;
                    int x = (data.Size.Width - data.CustomImage.Width) / 2;

                    g.DrawImage(data.CustomImage, x, y);
                }
            }
        }
        private string AssignData(Control ctl, string title, Dictionary <string, string> values, Image titleImage, Image customImage)
        {
            titleImage  = GetScaledImage(titleImage);
            customImage = GetScaledImage(customImage);

            if (ctl == null)
            {
                ctl = __generic;
            }

            if (_data.ContainsKey(ctl))
            {
                if (string.IsNullOrEmpty(title))
                {
                    _data.Remove(ctl);
                }
                else
                {
                    _data[ctl] = new OPMToolTipData {
                        Values = values, Title = title, TitleImage = titleImage, CustomImage = customImage
                    };
                }
            }
            else if (!string.IsNullOrEmpty(title))
            {
                _data.Add(ctl, new OPMToolTipData {
                    Values = values, Title = title, TitleImage = titleImage, CustomImage = customImage
                });
            }

            if (_data.ContainsKey(ctl) && _def != null)
            {
                _data[ctl].Size = CalculateSize(ctl, _data[ctl]);

                string fake = string.Empty;
                string row  = string.Empty;
                SizeF  size = SizeF.Empty;

                // Calculate a string that would generate an equivalent tooltip size
                using (Graphics g = ctl.CreateGraphics())
                {
                    do
                    {
                        row += "Ig";
                        size = g.MeasureString(row, _def);
                    }while (size.Width < _data[ctl].Size.Width);

                    fake = row;

                    size = SizeF.Empty;
                    do
                    {
                        fake += "Ig\n";
                        size  = g.MeasureString(fake, _def);
                    }while (size.Height < _data[ctl].Size.Height);
                }

                return(fake);
            }

            return(title);
        }
        private void DrawContents(Graphics g, OPMToolTipData data)
        {
            if (data != null)
            {
                int titleOffsetX = 5;
                int titleOffsetY = 5;
                int textOffsetY  = 5;

                SizeF sizeTitle = g.MeasureString(data.Title, _fTitle);

                if (data.TitleImage != null)
                {
                    g.DrawImage(data.TitleImage, 5, 5);

                    titleOffsetX += 5 + data.TitleImage.Width;
                    titleOffsetY  = (int)(data.TitleImage.Height / 2 - sizeTitle.Height / 4);

                    textOffsetY += data.TitleImage.Height + 5;
                }
                else
                {
                    textOffsetY += (int)sizeTitle.Height + 5;
                }

                int y = textOffsetY;

                using (Brush b = new SolidBrush(ThemeManager.ForeColor))
                {
                    g.DrawString(data.Title, _fTitle, b, titleOffsetX, titleOffsetY);

                    int x = 5;

                    if (data.Values != null)
                    {
                        foreach (KeyValuePair <string, string> val in data.Values)
                        {
                            string key        = Translator.Translate(val.Key.Trim());
                            string keyMeasure = string.IsNullOrEmpty(key) ? " " : key;
                            string valMeasure = string.IsNullOrEmpty(val.Value) ? " " : val.Value;

                            SizeF szKey = g.MeasureString(keyMeasure, _fKey);
                            SizeF szVal = g.MeasureString(valMeasure, _fVal);

                            if (!string.IsNullOrEmpty(val.Key))
                            {
                                g.DrawString(key, _fKey, b, x, y);
                            }

                            if (!string.IsNullOrEmpty(val.Value))
                            {
                                g.DrawString(val.Value, _fVal, b, x + szKey.Width, y);
                            }

                            y += (int)Math.Max(szKey.Height, szVal.Height) + 2;
                        }
                    }
                }

                if (data.CustomImage != null)
                {
                    y += 5;
                    int x = (data.Size.Width - data.CustomImage.Width) / 2;

                    g.DrawImage(data.CustomImage, x, y);
                }
            }
        }