How to get tooltip to not draw black rectangle on setting it's size on popup?

08/18/2014 02:45 OverKillasdwqe#1
all i want is a transparent (less opacity tool tip)

here is what I've so far

Code:
public partial class CustomToolTip : ToolTip    
{
    public CustomToolTip()
    {
        InitializeComponent();
        this.BackColor = Color.FromArgb(127, 0, 0, 0);
        this.OwnerDraw = true;
        this.Popup += new PopupEventHandler(this.OnPopup);
        this.Draw += new DrawToolTipEventHandler(this.OnDraw);
    }
 
    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams CP = base.CreateParams;
            CP.ExStyle = CP.ExStyle | 0x20;
            return CP;
        }
    }
 
    private void OnPopup(object sender, PopupEventArgs e)
    {
        e.ToolTipSize = new Size(200, 100);
    }
 
    private void OnDraw(object sender, DrawToolTipEventArgs e)
    {
        e.Graphics.FillRectangle(new SolidBrush(this.BackColor), e.Bounds);
    }
}
but i end up having a black rectangle at setting the tooltip size which i can't get ride of

[Only registered and activated users can see links. Click Here To Register...]

any idea how could i draw without setting size or even remove that black rectangle ?

^ that what i've posted on programming forums but as people here can relate to conquer then i should say im going after conquer's item tool tip kind thing (if that isn't obvious by now)

i also want to add that this is the reason for not doing it with this ways

1- as for transparent form : it lose focus of the previous form plus it's gay
2- custom controls : C# graphics is way way way too good for documentation and not strict at all, everything is pretty straight forward >.< IKR lmao, but seriously i reached a certain point where i don't have suitable parent to draw on a custom transparent control ( some controls redraw over it for certain reasons ) and no control support real transparency (only taking it's parent backcolor) but won't let me set createprams 0x20 flag

answer by Loathing, maybe you folks wanna have a look how it was done
Updated the solution with the final class (didn't want to release it but duh)
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace IConquerClient.Objects
{
    public partial class CustomToolTip : ToolTip
    {
        private Item _Item;
        public Item Item 
        {
            get { return _Item; }
            set { _Item = value; }
        }

        public CustomToolTip()
        {
            this.OwnerDraw = true;
            this.Popup += new PopupEventHandler(this.OnPopup);
            this.Draw += new DrawToolTipEventHandler(this.OnDraw);
        }

        private void OnPopup(Object sender, PopupEventArgs e)
        {
            e.ToolTipSize = new Size(500, 660);
            var window = typeof(ToolTip).GetField("window", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this) as NativeWindow;
            var Handle = window.Handle;
            //MessageBox.Show("Handle " + Handle.ToString() + " , GetWinLong " + GetWindowLong(Handle, GWL_EXSTYLE).ToString()); 524424

            //SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) ^ WS_EX_LAYERED);
            SetWindowLong(Handle, GWL_EXSTYLE, 524424 ^ WS_EX_LAYERED);
            SetLayeredWindowAttributes(Handle, 0, 250, LWA_ALPHA);
           
        }

        public const int GWL_EXSTYLE = -20;
        public const int WS_EX_LAYERED = 0x80000;
        public const int LWA_ALPHA = 0x20;
        public const int LWA_COLORKEY = 0x5;

        [DllImport("user32.dll")]
        static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
        [DllImport("user32.dll", SetLastError = true)]
        static extern int GetWindowLong(IntPtr hWnd, int nIndex);
        [DllImport("user32.dll")]
        static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern bool IsWindowVisible(IntPtr hWnd);

        private void OnDraw(object sender, DrawToolTipEventArgs e)
        {

            // hold my dignity, i'm going to draw ! XD

            if(_Item == null)
                return;
            using (Font font = new Font("Courier New", 12))
            using (Font font10 = new Font("Courier New", 10))
            using (Font font9 = new Font("Courier New", 10))
            using (Brush wbrush = new SolidBrush(Color.White))
            using (Brush rbrush = new SolidBrush(Color.Red))
            {
                e.Graphics.FillRectangle(new SolidBrush(this.BackColor), e.Bounds);
                ControlPaint.DrawBorder(e.Graphics, e.Bounds, Color.White, ButtonBorderStyle.Solid);
                e.Graphics.DrawString(_Item.Name, font, _Item.UID.ToString().EndsWith("9") ?
                    new SolidBrush(Color.Orange) : _Item.UID.ToString().EndsWith("8") ?
                    new SolidBrush(Color.DarkOrchid) : _Item.UID.ToString().EndsWith("7") ?
                    new SolidBrush(Color.Chartreuse) : _Item.UID.ToString().EndsWith("6") ?
                    new SolidBrush(Color.Aqua) : wbrush, 5, 5);
                e.Graphics.DrawString("UID : " + Item.UID.ToString(),font,wbrush,5,25);
                e.Graphics.DrawString("Class : " + (Item.ReqProfession == 0 ? "all" : ((Kernel.Professions)Item.ReqProfession).ToString()), font, wbrush, 5, 45);
                e.Graphics.DrawString("Wep Level : " + (Item.ReqWeaponSkill == 0 ? "None" : "L" + Item.ReqWeaponSkill), font, wbrush, 5, 65);
                e.Graphics.DrawString("Level : " + Item.ReqLevel, font, wbrush, 5, 85);
                e.Graphics.DrawString("Sex : " + (Item.ReqSex == 0 ? "Any" : Item.ReqSex == 1 ? "Male" : "Female"), font,wbrush,5,105);
                e.Graphics.DrawString("Strength : " + Item.ReqStrength, font, wbrush, 5, 125);
                e.Graphics.DrawString("Agility : " + Item.ReqAgility, font, wbrush, 5, 145);
                e.Graphics.DrawString("Vitality : " + Item.ReqVitality, font, wbrush, 5, 165);
                e.Graphics.DrawString("Spirit : " + Item.ReqSpirit, font, wbrush, 5, 185);
                e.Graphics.DrawString("Monopoly : " + Item.Monopoly,font,wbrush,5,205);
                e.Graphics.DrawString("Weight : " + Item.Weight, font, wbrush, 5, 225);
                e.Graphics.DrawString("Price : " + Item.Price, font, wbrush, 5, 245);
                e.Graphics.DrawString("ActionId : " + Item.ActionId, font, wbrush, 5, 265);
                e.Graphics.DrawString("AttackMax : " + Item.AttackMax, font, wbrush, 5, 285);
                e.Graphics.DrawString("AttackMin : " + Item.AttackMin, font, wbrush, 5, 305);
                e.Graphics.DrawString("Defense : " + Item.Defense, font, wbrush, 5, 325);
                e.Graphics.DrawString("Agility : " + Item.Agility, font, wbrush, 5, 345);
                e.Graphics.DrawString("Dodge : " + Item.Dodge, font, wbrush, 5, 365);
                e.Graphics.DrawString("Life : " + Item.Life, font, wbrush, 5, 385);
                e.Graphics.DrawString("Mana : " + Item.Mana, font, wbrush, 5, 405);
                e.Graphics.DrawString("Amount : " + Item.Amount, font, wbrush, 5, 425);
                e.Graphics.DrawString("AmountLimit : " + Item.AmountLimit, font, wbrush, 5, 445);
                e.Graphics.DrawString("Ident : " + Item.Ident, font, wbrush, 5, 465);
                e.Graphics.DrawString("Gem1 : " + Item.Gem1, font, wbrush, 5, 485);
                e.Graphics.DrawString("Gem2 : " + Item.Gem2, font, wbrush, 5, 505);
                e.Graphics.DrawString("Magic1 : " + Item.Magic1, font, wbrush, 5, 525);
                e.Graphics.DrawString("Magic2 : " + Item.Magic2, font, wbrush, 5, 545);
                e.Graphics.DrawString("Magic3 : " + Item.Magic3, font, wbrush, 5, 565);


                e.Graphics.DrawImage(DevIL.DevIL.LoadBitmap(Item.MapItemIconPath), new Rectangle(new Point(200, 10), new Size(42, 42)));
                e.Graphics.DrawImage(DevIL.DevIL.LoadBitmap(Item.ItemMinIconPath), new Rectangle(new Point(270, 10), new Size(42, 42)));
                e.Graphics.DrawString("Data : " + Item.Data, font, wbrush, 200, 65);
                e.Graphics.DrawString("MagicAttack : " + Item.MagicAttack, font, wbrush, 200, 85);
                e.Graphics.DrawString("MagicDefense : " + Item.MagicDefense, font, wbrush, 200, 105);
                e.Graphics.DrawString("AttackRange : " + Item.AttackRange, font, wbrush, 200, 125);
                e.Graphics.DrawString("AttackSpeed : " + Item.AttackSpeed, font, wbrush, 200, 145);
                e.Graphics.DrawString("FrayMode : " + Item.FrayMode, font, wbrush, 200, 165);
                e.Graphics.DrawString("RepairMode : " + Item.RepairMode, font, wbrush, 200, 185);
                e.Graphics.DrawString("TypeMask : " + Item.TypeMask, font, wbrush, 200, 205);
                e.Graphics.DrawString("PointPrice : " + Item.PointPrice, font, wbrush, 200, 225);
                e.Graphics.DrawString("CriticalStrike : " + Item.CriticalStrike, font, wbrush, 200, 245);
                e.Graphics.DrawString("SkillCriticalStrike : " + Item.SkillCriticalStrike, font, wbrush, 200, 265);
                e.Graphics.DrawString("Immunity : " + Item.Immunity, font, wbrush, 200, 285);
                e.Graphics.DrawString("Penetration : " + Item.Penetration, font, wbrush, 200, 305);
                e.Graphics.DrawString("Block : " + Item.Block, font, wbrush, 200, 325);
                e.Graphics.DrawString("Breakthrough : " + Item.Breakthrough, font, wbrush, 200, 345);
                e.Graphics.DrawString("Counteraction : " + Item.Counteraction, font, wbrush, 200, 365);
                e.Graphics.DrawString("StackLimit : " + Item.StackLimit, font, wbrush, 200, 385);
                e.Graphics.DrawString("ResistMetal : " + Item.ResistMetal, font, wbrush, 200, 405);
                e.Graphics.DrawString("ResistWood : " + Item.ResistWood, font, wbrush, 200, 425);
                e.Graphics.DrawString("ResistWater : " + Item.ResistWater, font, wbrush, 200, 445);
                e.Graphics.DrawString("ResistFire : " + Item.ResistFire, font, wbrush, 200, 465);
                e.Graphics.DrawString("ResistEarth : " + Item.ResistEarth, font, wbrush, 200, 485);
                e.Graphics.DrawString("TypeName : " + Item.TypeName, font, wbrush, 200, 505);
                e.Graphics.DrawString("NameColor : " + Item.NameColor, font, wbrush, 200, 525);
                e.Graphics.DrawString("DragonSoulPhase : " + Item.Magic1, font, wbrush, 200, 545);
                e.Graphics.DrawString("DragonSoulReq : " + Item.Magic2, font, wbrush, 200, 565);



                e.Graphics.DrawString("Description : " + Item.Magic3, font, wbrush, 0, 585);
                e.Graphics.DrawString(Item.ItemMinIconPath, font9, rbrush, 0, 605);
                e.Graphics.DrawString(Item.MapItemIconPath, font9, rbrush, 0, 625);


            }
        }

        public bool IsHintVisible()
        {
            try
            {
                var window = typeof(ToolTip).GetField("window", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this) as NativeWindow;
                var Handle = window.Handle;
                return IsWindowVisible(Handle);
            }
            catch
            {
                return false;
            }
            
        }
    }


}
08/19/2014 06:12 { Angelius }#2
[Only registered and activated users can see links. Click Here To Register...]

Change dwStyle in CreateWindowEx to WS_POPUP if you don't like the balloon..

I hope that helps, Good luck.
08/19/2014 07:08 OverKillasdwqe#3
Quote:
Originally Posted by { Angelius } View Post
[Only registered and activated users can see links. Click Here To Register...]

Change dwStyle in CreateWindowEx to WS_POPUP if you don't like the balloon..

I hope that helps, Good luck.
got it solved but still thanks for the thought i've added the solution but i've tweaked it alot to get it to work but there is still a bug or two, will try out your solution and see if it works better

[Only registered and activated users can see links. Click Here To Register...]
08/20/2014 02:23 { Angelius }#4
Quote:
Originally Posted by OverKillasdwqe View Post
got it solved but still thanks for the thought i've added the solution but i've tweaked it alot to get it to work but there is still a bug or two, will try out your solution and see if it works better

[Only registered and activated users can see links. Click Here To Register...]
Looking good.. Keep it up and let me know if you need any help.

I think this might prove useful to you.. [Only registered and activated users can see links. Click Here To Register...]
08/21/2014 06:43 OverKillasdwqe#5
Quote:
Originally Posted by { Angelius } View Post
I think this might prove useful to you.. [Only registered and activated users can see links. Click Here To Register...]
it's same or less what i do but mine is a bit more dynamic and a bit more complicated (not just shops, it's like full client manager)
i read all items, all icons, all shops, most of the ani and ini files
i then cast them to lists of objects and i write them to a binary file (to read them back with like 100 times faster than normal txt files)
also i read and convert images at run time, doesn't take any time or effort so i think it's best that way to fit my app

but with that being said, i love some techniques you used XD im stealing what i can :P :P
08/21/2014 07:05 { Angelius }#6
Quote:
Originally Posted by OverKillasdwqe View Post
it's same or less what i do but mine is a bit more dynamic and a bit more complicated (not just shops, it's like full client manager)
i read all items, all icons, all shops, most of the ani and ini files
i then cast them to lists of objects and i write them to a binary file (to read them back with like 100 times faster than normal txt files)
also i read and convert images at run time, doesn't take any time or effort so i think it's best that way to fit my app

but with that being said, i love some techniques you used XD im stealing what i can :P :P
Sure help your self :)

That was a little test project that i put together to implement some type of a drag/drop functionality for the shop icons..

The idea was to be able to drag any item in the inventory/shop etc and drop it in the search box and it will display all sorts of information about the item without any effort.. yes that's how lazy i am =))